Refetch posts when a user clicks on the HC logo

This commit is contained in:
Matt Rider 2019-07-10 18:44:07 -03:00
parent 6536574a3b
commit 79930dcdc4
2 changed files with 66 additions and 1 deletions

View File

@ -6,7 +6,7 @@
<ds-flex class="main-navigation-flex">
<ds-flex-item :width="{ lg: '5%' }" />
<ds-flex-item :width="{ base: '80%', sm: '80%', md: '80%', lg: '15%' }">
<a @click="$router.push('/').then(() => $router.go())">
<a @click="redirectToRoot">
<ds-logo />
</a>
</ds-flex-item>
@ -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: {

View File

@ -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
},
}