Quellcode durchsuchen

:sparkles: appending new posts on list

tags/0.9.0
J vor 4 Jahren
Ursprung
Commit
f1e64fc640

+ 21
- 8
vue-theme/src/pages/list.vue Datei anzeigen

@@ -16,7 +16,7 @@
16 16
                 card(:content="post" :type="type" :wide="type == 'exhibition' && i > 1 || type == 'event' && i > 1 ")
17 17
 
18 18
         footer
19
-            button(@click="loadMore") load more {{ type }}s...
19
+            button(@click="loadMorePosts") load more {{ type }}s...
20 20
             p {{ `${type} count: ${Object.values(posts).length}` }}
21 21
             p {{ `show sidebar: ${sidebar}` }}
22 22
         
@@ -57,6 +57,10 @@ export default {
57 57
             let type = convertTitleCase(this.type) + 's'
58 58
             return this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
59 59
         },
60
+        getMoreName() {
61
+            let type = convertTitleCase(this.type) + 's'
62
+            return this.sortBy ? `getMore${type.split('/')[0]}` : `getMore${type}`
63
+        },
60 64
         loaded() {
61 65
             let type = convertTitleCase(this.type) + 's'
62 66
             if (!type) return
@@ -69,11 +73,11 @@ export default {
69 73
         },
70 74
     },
71 75
     methods: {
72
-        loadMore() {
76
+        loadMorePosts() {
73 77
             this.page++
74
-            this.getPosts()
78
+            this.getPosts(false)
75 79
         },
76
-        getPosts(offset) {
80
+        getPosts(clear) {
77 81
             // Limit
78 82
             let params = {
79 83
                 limit: this.perPage,
@@ -94,8 +98,11 @@ export default {
94 98
             // }
95 99
 
96 100
             // Don't dispatch if there's no type
97
-            if (this.type && this.dispatchName) {
98
-                this.$store.dispatch(this.dispatchName, { sortType: sort, params })
101
+            if (this.type && this.dispatchName && clear) {
102
+                this.$store.dispatch(
103
+                    this.dispatchName,
104
+                    { sortType: sort, params }
105
+                )
99 106
 
100 107
                 if (this.type == 'event') {
101 108
                     this.$store.dispatch(
@@ -115,6 +122,12 @@ export default {
115 122
                         }
116 123
                     )
117 124
                 }
125
+            // Add to existing
126
+            } else if (!clear) {
127
+                this.$store.dispatch(
128
+                    this.getMoreName,
129
+                    { sortType: sort, params }
130
+                )
118 131
             }
119 132
         },
120 133
         async checkAndSetHero(type) {
@@ -173,7 +186,7 @@ export default {
173 186
                 sort = null
174 187
             }
175 188
 
176
-            if (!this[`all${type}Loaded`] || sort) this.getPosts()
189
+            if (!this[`all${type}Loaded`] || sort) this.getPosts(true)
177 190
         },
178 191
     },
179 192
     mounted() {
@@ -187,7 +200,7 @@ export default {
187 200
 
188 201
         // We also need to check if only ONE has been loaded because
189 202
         // coming from the homepage there will only be 1 item
190
-        if (!this[`all${type}Loaded`] || this[`all${type}`].length < 2) this.getPosts()
203
+        if (!this[`all${type}Loaded`] || this[`all${type}`].length < 2) this.getPosts(true)
191 204
     },
192 205
 }
193 206
 </script>

+ 11
- 0
vue-theme/src/store/modules/artist.js Datei anzeigen

@@ -26,6 +26,14 @@ const actions = {
26 26
         })
27 27
         return api.getByType({ type: 'artist', sort: sortType, params, cb: storeFetch })
28 28
     },
29
+    getMoreArtists({ commit }, { sortType, params }) {
30
+        commit('ARTISTS_LOADED', false)
31
+        const storeFetch = (artists => {
32
+            commit('ADD_TO_FETCHED_ARTISTS', { artists })
33
+            commit('ARTISTS_LOADED', true)
34
+        })
35
+        return api.getByType({ type: 'artist', sort: sortType, params, cb: storeFetch })
36
+    },
29 37
     getSingleArtist({ commit }, id) {
30 38
         commit('CLEAR_SINGLE_ARTISTS')
31 39
         commit('ARTISTS_LOADED', false)
@@ -38,6 +46,9 @@ const actions = {
38 46
 }
39 47
 
40 48
 const mutations = {
49
+    ADD_TO_FETCHED_ARTISTS(state, { artists }) {
50
+        state.all = [...state.all, ...artists]
51
+    },
41 52
     STORE_FETCHED_ARTISTS(state, { artists }) {
42 53
         state.all = artists
43 54
     },

+ 10
- 0
vue-theme/src/store/modules/event.js Datei anzeigen

@@ -32,6 +32,13 @@ const actions = {
32 32
             commit('EVENTS_LOADED', true)
33 33
         }, params })
34 34
     },
35
+    getMoreEvents({ commit }, { sortType, params }) {
36
+        commit('EVENTS_LOADED', false)
37
+        return api.getByType({ type: 'event', sort: sortType, cb: events => {
38
+            commit('ADD_TO_FETCHED_EVENTS', { events })
39
+            commit('EVENTS_LOADED', true)
40
+        }, params })
41
+    },
35 42
     getSingleEvent({ commit }, id) {
36 43
         commit('CLEAR_SINGLE_EVENTS')
37 44
         commit('EVENTS_LOADED', false)
@@ -43,6 +50,9 @@ const actions = {
43 50
 }
44 51
 
45 52
 const mutations = {
53
+    ADD_TO_FETCHED_EVENTS(state, { events }) {
54
+        state.all = [...state.all, ...events]
55
+    },
46 56
     STORE_FETCHED_EVENTS(state, { events }) {
47 57
         state.all = events
48 58
     },

+ 10
- 0
vue-theme/src/store/modules/exhibition.js Datei anzeigen

@@ -34,6 +34,13 @@ const actions = {
34 34
             commit('EXHIBITIONS_LOADED', true)
35 35
         }, params })
36 36
     },
37
+    getMoreExhibitions({ commit },{ sortType, params }) {
38
+        commit('EXHIBITIONS_LOADED', false)
39
+        return api.getByType({ type: 'exhibition', sort: sortType, cb: exhibitions => {
40
+            commit('ADD_TO_FETCHED_EXHIBITIONS', { exhibitions })
41
+            commit('EXHIBITIONS_LOADED', true)
42
+        }, params })
43
+    },
37 44
     getSingleExhibition({ commit }, id) {
38 45
         commit('CLEAR_SINGLE_EXHIBITIONS')
39 46
         commit('EXHIBITIONS_LOADED', false)
@@ -45,6 +52,9 @@ const actions = {
45 52
 }
46 53
 
47 54
 const mutations = {
55
+    ADD_TO_FETCHED_EXHIBITIONS(state, { exhibitions }) {
56
+        state.all = [...state.all, ...exhibitions]
57
+    },
48 58
     STORE_FETCHED_EXHIBITIONS(state, { exhibitions }) {
49 59
         state.all = exhibitions
50 60
     },

+ 10
- 0
vue-theme/src/store/modules/post.js Datei anzeigen

@@ -20,6 +20,13 @@ const actions = {
20 20
             commit('POSTS_LOADED', true)
21 21
         }, params })
22 22
     },
23
+    getMorePosts({ commit }, { sortType, params }) {
24
+        commit('POSTS_LOADED', false)
25
+        return api.getByType({ type: 'post', sort: sortType, cb: posts => {
26
+            commit('ADD_TO_FETCHED_POSTS', { posts })
27
+            commit('POSTS_LOADED', true)
28
+        }, params })
29
+    },
23 30
     getSinglePost({ commit }, id) {
24 31
         commit('CLEAR_SINGLE_POSTS')
25 32
         commit('POSTS_LOADED', false)
@@ -31,6 +38,9 @@ const actions = {
31 38
 }
32 39
 
33 40
 const mutations = {
41
+    ADD_TO_FETCHED_POSTS(state, { posts }) {
42
+        state.all = [...state.all, ...posts]
43
+    },
34 44
     STORE_FETCHED_POSTS(state, { posts }) {
35 45
         state.all = posts
36 46
     },

Laden…
Abbrechen
Speichern