Переглянути джерело

:bug: tracking seen title inbetween state in vuex | clearing from list

tags/0.9.0
J 4 роки тому
джерело
коміт
5b38683502

+ 10
- 4
vue-theme/src/pages/list.vue Переглянути файл

@@ -87,11 +87,12 @@ export default {
87 87
     },
88 88
     methods: {
89 89
         async loadMorePosts(shouldClear) {
90
+            
90 91
             if(!this.keepFetching) return console.warn('Nothing left to fetch...')
91 92
 
92 93
             const getPosts = async  (params, dispatchType) => {
93 94
                 if(!this.type) throw `post type: ${this.type} not found...`
94
-                console.log('$route :', this.$route)
95
+                
95 96
                 // We always grab all pages on hero init so no need to do it here
96 97
                 return this.pType && this.type != 'page' ? await this.$store.dispatch(
97 98
                     `get${dispatchType}${this.pType}`,
@@ -99,8 +100,13 @@ export default {
99 100
                 ) : []
100 101
             }
101 102
 
102
-            if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
103
-            console.log('loadMore $route :', this.$route)
103
+            if(shouldClear) {
104
+                this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
105
+                
106
+                // Clear any state needed to track title inbetweens
107
+                this.$store.commit(`CLEAR_${this.pType.toUpperCase()}_SEEN`)
108
+            }
109
+
104 110
             try {
105 111
                 this.loadingFetched = true
106 112
                 this.page++
@@ -197,7 +203,7 @@ export default {
197 203
         // This only fires navigating from a non-list page > list page
198 204
         this.initPostList()
199 205
     },
200
-    beforeDestroy() {
206
+    beforeUnmount() {
201 207
         this.unsetIntersectionLoader()
202 208
     }
203 209
 }

+ 8
- 4
vue-theme/src/store/modules/artist.js Переглянути файл

@@ -5,6 +5,7 @@ const state = {
5 5
     all: [],
6 6
     loaded: false,
7 7
     singleArtist: null,
8
+    seenTitles: []
8 9
 }
9 10
 
10 11
 const getters = {
@@ -36,15 +37,14 @@ const _arrangeByMaterial = artistsList => {
36 37
     return flatPacked
37 38
 }
38 39
 
39
-let seenTitles = []
40 40
 const _arrangeByAlpha = artistsList => {
41 41
     const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
42 42
     const flatPacked = []
43
-
43
+    
44 44
     const storeTitle = letter => {
45
-        if(seenTitles.includes(letter)) return
45
+        if(state.seenTitles.includes(letter)) return
46 46
         flatPacked.push({ slug: letter, title: letter, inbetween: true })
47
-        seenTitles.push(letter)
47
+        state.seenTitles.push(letter)
48 48
     }
49 49
 
50 50
     artistsList.forEach(artist => {
@@ -74,6 +74,7 @@ const actions = {
74 74
         return api.getByType({ type: 'artist', sort: sortType, params, cb: storeFetch })
75 75
     },
76 76
     getMoreArtists({ commit }, { sortType, params }) {
77
+        commit('ARTISTS_LOADED', false)
77 78
         const storeFetch = (artists => {
78 79
             let repacked = artists
79 80
             if(sortType == sortTypes.alpha) {
@@ -108,6 +109,9 @@ const mutations = {
108 109
     CLEAR_ARTISTS(state) {
109 110
         state.all = []
110 111
     },
112
+    CLEAR_ARTISTS_SEEN(state) {
113
+        state.seenTitles = []
114
+    },
111 115
     CLEAR_SINGLE_ARTISTS(state) {
112 116
         state.singleArtist = null
113 117
     },

+ 1
- 1
vue-theme/src/utils/api.js Переглянути файл

@@ -23,8 +23,8 @@ const constructQuery = (params) => {
23 23
 export default {
24 24
     getByType({ type, sort, params, cb }) {
25 25
         const query = constructQuery(params)
26
-
27 26
         if (sort && Object.values(sortTypes).includes(sort)) {
27
+            console.log('---')
28 28
             return axios
29 29
                 .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sort}${query}`)
30 30
                 .then(response => {

Завантаження…
Відмінити
Зберегти