ThreadSection.vue 783 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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
  10. v-for="thread in threads"
  11. track-by="id"
  12. :thread="thread">
  13. </thread>
  14. </ul>
  15. </div>
  16. </template>
  17. <script>
  18. import store from '../store'
  19. import Thread from './Thread.vue'
  20. export default {
  21. components: { Thread },
  22. vuex: {
  23. state: {
  24. threads: state => state.threads
  25. }
  26. },
  27. computed: {
  28. unreadCount () {
  29. const threads = this.threads
  30. return Object.keys(threads).reduce((count, id) => {
  31. return threads[id].lastMessage.isRead
  32. ? count
  33. : count + 1
  34. }, 0)
  35. }
  36. }
  37. }
  38. </script>