Skip to content

Commit 7673b36

Browse files
committed
fix light/dark theme not currectly initializing on shared report, unify logic
1 parent da5fc3f commit 7673b36

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

resources/js/Components/AuthenticationCard.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<script setup lang="ts">
2-
import { onMounted, watch } from "vue";
3-
import { theme } from "@/utils/theme.js";
2+
import { onMounted } from "vue";
3+
import { useTheme } from "@/utils/theme.js";
44
55
onMounted(async () => {
6-
document.documentElement.classList.add(theme.value);
7-
watch(theme, (newTheme, oldTheme) => {
8-
document.documentElement.classList.remove(oldTheme);
9-
document.documentElement.classList.add(newTheme);
10-
});
6+
useTheme()
117
});
128
</script>
139

resources/js/Layouts/AppLayout.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import NavigationSidebarItem from '@/Components/NavigationSidebarItem.vue';
2121
import UserSettingsIcon from '@/Components/UserSettingsIcon.vue';
2222
import MainContainer from '@/packages/ui/src/MainContainer.vue';
23-
import { onMounted, ref, watch } from "vue";
23+
import { onMounted, ref } from "vue";
2424
import NotificationContainer from '@/Components/NotificationContainer.vue';
2525
import { initializeStores, refreshStores } from '@/utils/init';
2626
import {
@@ -31,13 +31,13 @@ import {
3131
canViewProjects, canViewReport,
3232
canViewTags,
3333
} from '@/utils/permissions';
34-
import {isBillingActivated, isInvoicingActivated} from '@/utils/billing';
34+
import { isBillingActivated, isInvoicingActivated } from '@/utils/billing';
3535
import type { User } from '@/types/models';
3636
import { ArrowsRightLeftIcon } from '@heroicons/vue/16/solid';
3737
import { fetchToken, isTokenValid } from '@/utils/session';
3838
import UpdateSidebarNotification from '@/Components/UpdateSidebarNotification.vue';
3939
import BillingBanner from '@/Components/Billing/BillingBanner.vue';
40-
import { theme } from "@/utils/theme";
40+
import { useTheme } from "@/utils/theme";
4141
4242
defineProps({
4343
title: String,
@@ -47,12 +47,7 @@ const showSidebarMenu = ref(false);
4747
const isUnloading = ref(false);
4848
onMounted(async () => {
4949
50-
document.documentElement.classList.add(theme.value);
51-
watch(theme, (newTheme, oldTheme) => {
52-
document.documentElement.classList.remove(oldTheme);
53-
document.documentElement.classList.add(newTheme);
54-
});
55-
50+
useTheme()
5651
// make sure that the initial requests are only loaded once, this can be removed once we move away from inertia
5752
if (window.initialDataLoaded !== true) {
5853
window.initialDataLoaded = true;

resources/js/Pages/SharedReport.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { api } from '@/packages/api/src';
1414
import { getRandomColorWithSeed } from '@/packages/ui/src/utils/color';
1515
import { useReportingStore } from '@/utils/useReporting';
1616
import { Head } from '@inertiajs/vue3';
17+
import { useTheme } from "@/utils/theme";
1718
1819
const sharedSecret = ref<string | null>(null);
1920
@@ -136,6 +137,10 @@ function getGroupLabel(key: string) {
136137
return option.value === key;
137138
})?.label;
138139
}
140+
onMounted(async () => {
141+
useTheme();
142+
})
143+
139144
</script>
140145

141146
<template>

resources/js/utils/theme.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ const theme = computed(() => {
2222
return themeSetting.value
2323
});
2424

25-
export { type themeOption, themeSetting, theme };
25+
function useTheme() {
26+
document.documentElement.classList.add(theme.value);
27+
watch(theme, (newTheme, oldTheme) => {
28+
document.documentElement.classList.remove(oldTheme);
29+
document.documentElement.classList.add(newTheme);
30+
});
31+
}
32+
33+
export { type themeOption, themeSetting, theme, useTheme };

0 commit comments

Comments
 (0)