Browse Source

fix hydration issues, remove unnecessary state, rename function

pull/1244/head
Bernd Storath 12 months ago
parent
commit
3c6756d0a4
  1. 7
      src/layouts/Header.vue
  2. 2
      src/pages/index.vue
  3. 10
      src/stores/auth.ts
  4. 4
      src/stores/global.ts

7
src/layouts/Header.vue

@ -36,7 +36,7 @@
</button> </button>
<!-- Show / hide charts --> <!-- Show / hide charts -->
<label <label
v-if="uiChartType > 0" v-if="globalStore.uiChartType > 0"
class="inline-flex items-center justify-center cursor-pointer w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 whitespace-nowrap transition group" class="inline-flex items-center justify-center cursor-pointer w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 whitespace-nowrap transition group"
:title="$t('toggleCharts')" :title="$t('toggleCharts')"
> >
@ -52,7 +52,7 @@
/> />
</label> </label>
<span <span
v-if="authStore.requiresPassword && authStore.authenticated" v-if="authStore.requiresPassword && !isLoginPage"
class="text-sm text-gray-400 dark:text-neutral-400 cursor-pointer hover:underline" class="text-sm text-gray-400 dark:text-neutral-400 cursor-pointer hover:underline"
@click="logout" @click="logout"
> >
@ -87,6 +87,7 @@
<script setup lang="ts"> <script setup lang="ts">
const authStore = useAuthStore(); const authStore = useAuthStore();
const globalStore = useGlobalStore();
const route = useRoute(); const route = useRoute();
const isLoginPage = computed(() => route.path == '/login'); const isLoginPage = computed(() => route.path == '/login');
@ -96,7 +97,7 @@ const latestRelease = ref<null | { version: number; changelog: string }>(null);
const theme = useTheme(); const theme = useTheme();
const uiChartType = ref(0); globalStore.fetchChartType();
const uiShowCharts = ref(getItem('uiShowCharts') === '1'); const uiShowCharts = ref(getItem('uiShowCharts') === '1');
function toggleTheme() { function toggleTheme() {

2
src/pages/index.vue

@ -50,7 +50,7 @@ const clientsStore = useClientsStore();
const intervalId = ref<NodeJS.Timeout | null>(null); const intervalId = ref<NodeJS.Timeout | null>(null);
globalStore.fetchUITrafficStats(); globalStore.fetchTrafficStats();
globalStore.fetchChartType(); globalStore.fetchChartType();
globalStore.fetchRelease(); globalStore.fetchRelease();

10
src/stores/auth.ts

@ -1,5 +1,4 @@
export const useAuthStore = defineStore('Auth', () => { export const useAuthStore = defineStore('Auth', () => {
const authenticated = ref<boolean>(false);
const requiresPassword = ref<boolean>(true); const requiresPassword = ref<boolean>(true);
/** /**
@ -7,7 +6,6 @@ export const useAuthStore = defineStore('Auth', () => {
*/ */
async function login(password: string) { async function login(password: string) {
const response = await api.createSession({ password }); const response = await api.createSession({ password });
authenticated.value = response.success;
requiresPassword.value = response.requiresPassword; requiresPassword.value = response.requiresPassword;
return true as const; return true as const;
} }
@ -17,7 +15,6 @@ export const useAuthStore = defineStore('Auth', () => {
*/ */
async function logout() { async function logout() {
const response = await api.deleteSession(); const response = await api.deleteSession();
authenticated.value = !response.success;
return response.success; return response.success;
} }
@ -25,10 +22,9 @@ export const useAuthStore = defineStore('Auth', () => {
* @throws if unsuccessful * @throws if unsuccessful
*/ */
async function update() { async function update() {
const response = await api.getSession(); const session = await api.getSession();
authenticated.value = response.authenticated; requiresPassword.value = session.requiresPassword;
requiresPassword.value = response.requiresPassword;
} }
return { requiresPassword, authenticated, login, logout, update }; return { requiresPassword, login, logout, update };
}); });

4
src/stores/global.ts

@ -37,7 +37,7 @@ export const useGlobalStore = defineStore('Global', () => {
uiChartType.value = chartType.value ?? 0; uiChartType.value = chartType.value ?? 0;
} }
async function fetchUITrafficStats() { async function fetchTrafficStats() {
const { data: trafficStats } = await api.getTrafficStats(); const { data: trafficStats } = await api.getTrafficStats();
uiTrafficStats.value = trafficStats.value ?? false; uiTrafficStats.value = trafficStats.value ?? false;
} }
@ -53,6 +53,6 @@ export const useGlobalStore = defineStore('Global', () => {
updateCharts, updateCharts,
fetchRelease, fetchRelease,
fetchChartType, fetchChartType,
fetchUITrafficStats, fetchTrafficStats,
}; };
}); });

Loading…
Cancel
Save