Skip to content

Commit

Permalink
feat: sort posts by date
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jun 8, 2021
1 parent d95cfe7 commit 6869525
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions pages/premium/saved-posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,24 @@ export default {
...mapGetters('user', ['getSavedPosts']),
savedPostsFromSelectedBooru() {
let SAVED_POSTS = null
if (this.selectedBooru === 'all') {
return this.getSavedPosts
SAVED_POSTS = JSON.parse(JSON.stringify(this.getSavedPosts))
}
return this.getSavedPosts.filter(
(POST) => POST.meta_data.booru_domain === this.selectedBooru
)
//
else {
const FILTERED_SAVED_POSTS = this.getSavedPosts.filter(
(POST) => POST.meta_data.booru_domain === this.selectedBooru
)
SAVED_POSTS = FILTERED_SAVED_POSTS
}
const SORTED_SAVED_POSTS = this.sortPostsByDate(SAVED_POSTS)
return SORTED_SAVED_POSTS
},
availableBoorusWithSavedPosts() {
Expand All @@ -95,6 +106,17 @@ export default {
this.selectedBooru = BOORU
},
sortPostsByDate(POSTS) {
const SORTED_POSTS = POSTS.sort((POST_A, POST_B) => {
const POST_A_DATE_STRING = POST_A.meta_data.created_at
const POST_B_DATE_STRING = POST_B.meta_data.created_at
return new Date(POST_B_DATE_STRING) - new Date(POST_A_DATE_STRING)
})
return SORTED_POSTS
},
},
}
</script>

0 comments on commit 6869525

Please sign in to comment.