From 345b9438695b852019299e338e170e858a0b078a Mon Sep 17 00:00:00 2001 From: carlosjr Date: Wed, 20 Apr 2022 13:10:37 +0200 Subject: [PATCH 1/3] feat(darkMode): current darkMode value is now saved in vn.userConfig.darkMode --- src/components/UserPanel.vue | 36 ++++++++++++++-------- src/composables/useRole.js | 9 +++++- src/composables/useSession.js | 2 ++ src/composables/useState.js | 6 ++++ src/pages/Login/Login.vue | 56 +++++------------------------------ 5 files changed, 46 insertions(+), 63 deletions(-) diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 1d97bfbc9..28c99758a 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -3,6 +3,7 @@ import { onMounted, computed } from 'vue'; import { Dark, useQuasar } from 'quasar'; import { useI18n } from 'vue-i18n'; import { useRouter } from 'vue-router'; +import axios from 'axios'; import { useState } from 'src/composables/useState'; import { useSession } from 'src/composables/useSession'; @@ -27,9 +28,11 @@ const darkMode = computed({ const user = state.getUser(); const token = session.getToken(); +if (user.value.darkMode) darkMode.value = user.value.darkMode; + onMounted(async () => { try { - const stateRoles = state.getRoles().value + const stateRoles = state.getRoles().value; if (stateRoles.length === 0) { await role.fetch(); } @@ -42,11 +45,25 @@ onMounted(async () => { } }); +async function saveDarkMode(value) { + const query = `/api/UserConfigs/${user.value.id}`; + await axios.patch(query, { + darkMode: value, + }); + user.value.darkMode = value; +} + +async function saveLanguage(value) { + const query = `/api/Accounts/${user.value.id}`; + await axios.patch(query, { + lang: value, + }); +} + function logout() { session.destroy(); router.push('/login'); } -