FlagCollection.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <section class="flag-collection">
  3. <header>
  4. <h3 class="mdi mdi-folder-outline">{{collection.name}}</h3>
  5. <span
  6. class="mdi mdi-close"
  7. title="close"
  8. @click.prevent="onCloseFlagColl"
  9. />
  10. </header>
  11. <ul v-if="loadedItems">
  12. <li
  13. v-for="item in loadedItems"
  14. :key="item.id"
  15. >
  16. <MiniCard :item="item"/>
  17. </li>
  18. </ul>
  19. <span v-else class="loading">Loading</span>
  20. </section>
  21. </template>
  22. <script>
  23. import { mapState, mapActions } from 'vuex'
  24. import MiniCard from 'vuejs/components/Content/MiniCard'
  25. export default {
  26. name: "FlagCollection",
  27. props: ['collection'],
  28. data: () => ({
  29. loadedItems: false
  30. }),
  31. computed: {
  32. ...mapState({
  33. flagcolls: state => state.User.flagcolls,
  34. openedCollid: state => state.User.openedCollid
  35. })
  36. },
  37. // watch: {
  38. // flagcolls (newv, oldv) {
  39. // console.log('watching flagcolls');
  40. // if( typeof this.flagcolls[this.collection.id].loadedItems !== 'undefined' ) {
  41. // this.loadedItems = this.flagcolls[this.collection.id].loadedItems
  42. // }
  43. // }
  44. // },
  45. created() {
  46. if (typeof this.collection.loadedItems !== 'undefined') {
  47. // if loadedItems are alredy loaded,
  48. // the mutation occurs before this subscription
  49. // so we first check if they are already available
  50. this.loadedItems = this.collection.loadedItems
  51. }
  52. this.unsubscribe = this.$store.subscribe((mutation, state) => {
  53. if (mutation.type === 'User/setLoadedCollItems') {
  54. console.log("mutation setLoadedCollItems collid", this.openedCollid)
  55. // mutation is triggered before the component update
  56. // so this.collection.id is not good
  57. this.loadedItems = state.User.flagcolls[this.openedCollid].loadedItems
  58. }
  59. })
  60. },
  61. beforeDestroy() {
  62. this.unsubscribe()
  63. },
  64. // beforeMount () {
  65. // if (typeof this.flagcolls[collection.id].loadedItems === 'undefined') {
  66. // this.
  67. // }
  68. // },
  69. methods: {
  70. ...mapActions({
  71. closeFlagColl: 'User/closeFlagColl'
  72. }),
  73. onCloseFlagColl(e) {
  74. this.closeFlagColl()
  75. }
  76. },
  77. components: {
  78. MiniCard
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. </style>