ThreadSection.vue 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. :key="thread.id"
  12. :thread="thread"
  13. :active="thread.id === currentThread.id"
  14. @switch-thread="switchThread">
  15. </thread>
  16. </ul>
  17. </div>
  18. </template>
  19. <script>
  20. import Thread from './Thread.vue'
  21. import { mapGetters } from 'vuex'
  22. export default {
  23. name: 'ThreadSection',
  24. components: { Thread },
  25. computed: {
  26. ...mapGetters([
  27. 'threads',
  28. 'currentThread'
  29. ]),
  30. unreadCount () {
  31. const threads = this.threads
  32. return Object.keys(threads).reduce((count, id) => {
  33. return threads[id].lastMessage.isRead
  34. ? count
  35. : count + 1
  36. }, 0)
  37. }
  38. },
  39. methods: {
  40. switchThread (id) {
  41. this.$store.dispatch('switchThread', { id })
  42. }
  43. }
  44. }
  45. </script>