Skip to content

Commit

Permalink
fix(Posts): invert order when displaying comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jkklapp committed Jun 9, 2022
1 parent 2be4ee0 commit f359b62
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
9 changes: 5 additions & 4 deletions backend/src/posts/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export class PostsService {
): Promise<PaginatedResults> {
const _startAfter = startAfter ? parseInt(startAfter, 10) : '';
const noMoreResults = startAfter ? -1 : null;
return this.postsCollection
.orderBy('date', 'desc')
.startAfter(_startAfter)
const query = parentId
? this.postsCollection.orderBy('date').endBefore(_startAfter)
: this.postsCollection.orderBy('date', 'desc').startAfter(_startAfter);
return query
.limit(limit)
.get()
.then(async (snapshot) => {
Expand All @@ -68,7 +69,7 @@ export class PostsService {
...doc.data(),
}))
.filter((post) => {
return post.parentId === parentId;
return post.parentId === parentId || post.id === parentId;
});
const q = await snapshot.query.offset(limit).get();

Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/Dashboard/Posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ export default {
components: {
Post,
},
async beforeRouteEnter(to, from) {
// react to route changes...
this.fetchPosts(to.params.parentId);
},
computed: {
...mapGetters({
posts: 'getPosts',
Expand All @@ -68,7 +63,7 @@ export default {
created() {
this.$watch(
() => this.$route.params,
({ parentId }, previousParams) => {
({ parentId }) => {
if (
this.$route.name === 'Dashboard' ||
this.$route.name === 'Comments'
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export default {
state.parentId = data;
},
SET_POSTS(state, results) {
if (state.parentId) {
const parent = state.posts.filter((post) => post.id === state.parentId);
state.posts = [...parent, ...results];
} else {
state.posts = results;
}
state.posts = results;
},
SET_POST_BY_ID(state, data) {
const index = state.posts.findIndex((post) => post.id === data.id);
Expand Down

0 comments on commit f359b62

Please sign in to comment.