ThreadSection.vue 729 B

12345678910111213141516171819202122232425262728293031323334
  1. <template>
  2. <div class="thread-section">
  3. <div class="thread-count">
  4. <span v-show="unreadCount">
  5. Unread threads: {{ unreadCount }}
  6. </span>
  7. </div>
  8. <ul class="thread-list">
  9. <thread v-for="thread in threads" :thread="thread"></thread>
  10. </ul>
  11. </div>
  12. </template>
  13. <script>
  14. import vuex from '../vuex'
  15. import Thread from './Thread.vue'
  16. export default {
  17. components: { Thread },
  18. computed: {
  19. threads () {
  20. return vuex.state.threads
  21. },
  22. unreadCount () {
  23. return vuex.state.threads.reduce((count, thread) => {
  24. const hasUnread = thread.messages.some(m => !m.isRead)
  25. return hasUnread
  26. ? count + 1
  27. : count
  28. }, 0)
  29. }
  30. }
  31. }
  32. </script>