set category filter as stored in db after login

This commit is contained in:
Moriz Wahl 2022-09-07 20:19:10 +02:00
parent a65e306b85
commit b323d0f580
2 changed files with 17 additions and 4 deletions

View File

@ -58,6 +58,7 @@ import PageParamsLink from '~/components/_new/features/PageParamsLink/PageParams
import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch'
import Logo from '~/components/Logo/Logo'
import ShowPassword from '../ShowPassword/ShowPassword.vue'
import { mapGetters, mapMutations } from 'vuex'
export default {
components: {
@ -84,12 +85,28 @@ export default {
iconName() {
return this.showPassword ? 'eye-slash' : 'eye'
},
...mapGetters({
currentUser: 'auth/user',
}),
},
methods: {
...mapMutations({
toggleCategory: 'posts/TOGGLE_CATEGORY',
resetCategories: 'posts/RESET_CATEGORIES',
}),
async onSubmit() {
const { email, password } = this.form
try {
await this.$store.dispatch('auth/login', { email, password })
if (this.currentUser && this.currentUser.activeCategories) {
if (this.currentUser.activeCategories.length > 0) {
this.currentUser.activeCategories.forEach((categoryId) => {
this.toggleCategory(categoryId)
})
} else {
this.resetCategories()
}
}
this.$toast.success(this.$t('login.success'))
this.$emit('success')
} catch (err) {

View File

@ -3,7 +3,6 @@ import { VERSION } from '~/constants/terms-and-conditions-version.js'
import { currentUserQuery } from '~/graphql/User'
import Cookie from 'universal-cookie'
import metadata from '~/constants/metadata'
import { mutations as postMutations } from './posts.js'
const cookies = new Cookie()
@ -17,9 +16,6 @@ export const state = () => {
export const mutations = {
SET_USER(state, user) {
if (user.activeCategories) {
console.log(user.activeCategories)
}
state.user = user || null
},
SET_TOKEN(state, token) {