Skip to content

Commit fce27b3

Browse files
committed
feat: implement page change to last page of thread after creating new post
1 parent 3f6161d commit fce27b3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/views/Posts.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ import humanDate from '@/composables/filters/humanDate'
425425
import dayjs from 'dayjs'
426426
import { userRoleHighlight } from '@/composables/utils/userUtils'
427427
import truncate from '@/composables/filters/truncate'
428-
import { inject, reactive, watch, toRefs } from 'vue'
428+
import { inject, reactive, watch, toRefs, nextTick } from 'vue'
429429
import { postsApi, pollsApi, threadsApi, usersApi, watchlistApi } from '@/api'
430430
import { AuthStore } from '@/composables/stores/auth'
431431
import { PreferencesStore, localStoragePrefs } from '@/composables/stores/prefs'
@@ -905,7 +905,17 @@ export default {
905905
}
906906
907907
const createPost = post => postsApi.create(post)
908-
.then(p => $router.push({ path: $route.path, query: $route.query, hash: `#${p.id}` }))
908+
.then(p => {
909+
const limit = localStoragePrefs().data.posts_per_page
910+
if (v.postData.data.posts.length === limit) {
911+
const postCount = v.postData.data.thread.post_count + 1
912+
const lastPage = Math.ceil(postCount / limit)
913+
Object.assign(v.postData.data.thread.post_count, postCount)
914+
Object.assign(v.postData.data.page, lastPage)
915+
nextTick(() => $router.push({ path: $route.path, query: { ...$route.query, page: lastPage }, hash: `#${p.id}` }))
916+
}
917+
else $router.push({ path: $route.path, query: $route.query, hash: `#${p.id}` })
918+
})
909919
910920
const updatePost = post => postsApi.update(post)
911921
.then(processPosts)

0 commit comments

Comments
 (0)