Explorar el Código

Fix bugs which prevented scrolling to and highlighting posts working correctly

sbkwgh hace 8 años
padre
commit
ab13d57f82
Se han modificado 2 ficheros con 19 adiciones y 6 borrados
  1. 17 4
      src/components/routes/Thread.vue
  2. 2 2
      src/store/modules/thread.js

+ 17 - 4
src/components/routes/Thread.vue

@@ -36,7 +36,7 @@
 				<thread-post
 					v-for='(post, index) in posts'
 					@reply='replyUser'
-					@goToPost='$router.push({ params: { post_number: post.postNumber } })'
+					@goToPost='goToPost'
 					:post='post'
 					:show-reply='true'
 					:highlight='highlightedPostIndex === index'
@@ -135,9 +135,22 @@
 			loadInitialPosts () {
 				this.$store.dispatch('loadInitialPostsAsync', this)
 			},	
-			goToPost (number) {
-				this.$router.push({ params: { post_number: number } })
-				this.loadInitialPosts()
+			goToPost (number, getPostNumber) {
+				let pushRoute = postNumber => {
+					if(this.$route.params.post_number === postNumber) {
+						this.highlightPost(postNumber)
+					} else {
+						this.$router.push({ name: 'thread-post', params: { post_number: postNumber } })
+					}
+				}
+
+				if(getPostNumber) {
+					this.axios
+						.get('/api/v1/post/' + number)
+						.then(res => pushRoute(res.data.postNumber) )
+				} else {
+					pushRoute(number)
+				}
 			},
 			scrollTo (postNumber, cb) {
 				for(var i = 0; i < this.posts.length; i++) {

+ 2 - 2
src/store/modules/thread.js

@@ -57,7 +57,7 @@ const actions = {
 		let postNumber = vue.$route.params.post_number
 		let apiURL = '/api/v1/thread/' + vue.$route.params.id
 
-		if(postNumber) {
+		if(postNumber !== undefined) {
 			apiURL += '?postNumber=' + postNumber
 		}
 
@@ -72,7 +72,7 @@ const actions = {
 				commit('setPostCounts', res.data.meta)
 				commit('setPosts', res.data.Posts)
 
-				if(postNumber) {
+				if(postNumber !== undefined) {
 					vue.highlightPost(+postNumber)
 				}
 			}).catch(AjaxErrorHandler(vue.$store))