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

Load pagination from starting post, add previousURL to store

sbkwgh 8 роки тому
батько
коміт
e1dc995d94
2 змінених файлів з 13 додано та 2 видалено
  1. 8 1
      src/components/routes/Thread.vue
  2. 5 1
      src/store/modules/thread.js

+ 8 - 1
src/components/routes/Thread.vue

@@ -153,11 +153,18 @@
 			setHeader();
 			document.addEventListener('scroll', throttle(setHeader, 200));
 
+			let apiURL = '/api/v1/thread/' + this.$route.params.id
+
+			if(this.$route.params.post_id) {
+				apiURL += '?postId=' + this.$route.params.post_id 
+			}
+
 			this.axios
-				.get('/api/v1/thread/' + this.$route.params.id)
+				.get(apiURL)
 				.then(res => {
 					this.$store.commit('setThread', res.data)
 					this.$store.commit('setNextURL', res.data.meta.nextURL)
+					this.$store.commit('setPreviousURL', res.data.meta.previousURL)
 					this.$store.commit('setPosts', res.data.Posts)
 				}).catch(AjaxErrorHandler(this.$store))
 		}

+ 5 - 1
src/store/modules/thread.js

@@ -13,7 +13,8 @@ const state = {
 		value: ''
 	},
 	loadingPosts: false,
-	nextURL: ''
+	nextURL: '',
+	previousURL: ''
 }
 
 const getters = {
@@ -120,6 +121,9 @@ const mutations = {
 	},
 	setNextURL (state, URL) {
 		state.nextURL = URL
+	},
+	setPreviousURL (state, URL) {
+		state.previousURL = URL
 	}
 }