diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index 4bc35d03b..a52f2c1d6 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -6,7 +6,7 @@ - + @@ -222,6 +222,7 @@ export default { ...mapActions({ quickSearchClear: 'search/quickClear', quickSearch: 'search/quickSearch', + fetchPosts: 'posts/fetchPosts', }), goToPost(item) { this.$nextTick(() => { @@ -247,6 +248,10 @@ export default { toggleMobileMenuView() { this.toggleMobileMenu = !this.toggleMobileMenu }, + redirectToRoot() { + this.$router.replace('/') + this.fetchPosts({ i18n: this.$i18n, filter: {} }) + }, }, apollo: { Category: { diff --git a/webapp/store/posts.js b/webapp/store/posts.js index cecc2a58e..7112a8add 100644 --- a/webapp/store/posts.js +++ b/webapp/store/posts.js @@ -1,3 +1,5 @@ +import gql from 'graphql-tag' + export const state = () => { return { posts: [], @@ -15,3 +17,61 @@ export const getters = { return state.posts || [] }, } + +export const actions = { + async fetchPosts({ commit, dispatch }, { i18n, filter }) { + const client = this.app.apolloProvider.defaultClient + const { + data: { Post }, + } = await client.query({ + query: gql(` + query Post($filter: _PostFilter, $first: Int, $offset: Int) { + Post(filter: $filter, first: $first, offset: $offset) { + id + title + contentExcerpt + createdAt + disabled + deleted + slug + image + author { + id + avatar + slug + name + disabled + deleted + contributionsCount + shoutedCount + commentsCount + followedByCount + followedByCurrentUser + location { + name: name${i18n.locale().toUpperCase()} + } + badges { + id + key + icon + } + } + commentsCount + categories { + id + name + icon + } + shoutedCount + } + }`), + variables: { + filter, + first: 12, + offset: 0, + }, + }) + commit('SET_POSTS', Post) + return Post + }, +}