From b323d0f5806f8afc52688cbfa8aee43d89d4bba1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 7 Sep 2022 20:19:10 +0200 Subject: [PATCH] set category filter as stored in db after login --- webapp/components/LoginForm/LoginForm.vue | 17 +++++++++++++++++ webapp/store/auth.js | 4 ---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/webapp/components/LoginForm/LoginForm.vue b/webapp/components/LoginForm/LoginForm.vue index 0d85ca33a..ce2f3338b 100644 --- a/webapp/components/LoginForm/LoginForm.vue +++ b/webapp/components/LoginForm/LoginForm.vue @@ -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) { diff --git a/webapp/store/auth.js b/webapp/store/auth.js index 0147b97ac..4ef63e3ea 100644 --- a/webapp/store/auth.js +++ b/webapp/store/auth.js @@ -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) {