Skip to content

Commit

Permalink
feat: create mixin for applying initial data on posts page load
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Replaces URLQueryManagerMixin for now as it didnt work correctly
  • Loading branch information
AlejandroAkbal committed Jul 13, 2020
1 parent 5f78b2e commit 1eb0fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions components/pages/posts/util/PostsStartupMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { mapState, mapActions } from 'vuex'

export default {
mounted() {
this.setInitialPageIDAndFetch()
},

computed: {
...mapState('booru', ['posts', 'queries']),
},

methods: {
...mapActions('booru', ['fetchPosts', 'pidManager']),

async setInitialPageIDAndFetch() {
if (this.queries.pid === undefined)
await this.pidManager({ operation: 'reset' })

if (!this.posts.data.length) this.fetchPosts()
},
},
}
4 changes: 2 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import Post from '~/components/pages/posts/content/Post.vue'
import Errors from '~/components/utils/Errors.vue'
// Mixins
// import URLQueryManagerMixin from '~/components/pages/dashboard/navigation/url/URLQueryManagerMixin.js'
import PostsStartupMixin from '~/components/pages/posts/util/PostsStartupMixin.js'
// Lazy loaded components
export default {
components: {
Errors,
Expand All @@ -39,6 +38,7 @@ export default {
},
// mixins: [URLQueryManagerMixin], // TODO: Remake this
mixins: [PostsStartupMixin],
computed: {
...mapState('booru', ['posts']),
Expand Down

0 comments on commit 1eb0fe6

Please sign in to comment.