Skip to content

Commit

Permalink
fix: moved theme related code to theme.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Jan 4, 2025
1 parent 36e8ae1 commit 211107f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
5 changes: 4 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<script setup>
import { Dialogs } from '@/utils/dialogs'
import { sessionStore as session } from '@/stores/session'
import { setTheme } from '@/stores/theme'
import { Toasts, setConfig } from 'frappe-ui'
import { computed, defineAsyncComponent } from 'vue'
import { computed, defineAsyncComponent, onMounted } from 'vue'
const MobileLayout = defineAsyncComponent(
() => import('./components/Layouts/MobileLayout.vue'),
Expand All @@ -26,6 +27,8 @@ const Layout = computed(() => {
}
})
onMounted(() => setTheme())
setConfig('systemTimezone', window.timezone?.system || null)
setConfig('localTimezone', window.timezone?.user || null)
</script>
4 changes: 2 additions & 2 deletions frontend/src/components/Layouts/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ import {
unreadNotificationsCount,
notificationsStore,
} from '@/stores/notifications'
import { FeatherIcon, TrialBanner, createResource } from 'frappe-ui'
import { FeatherIcon } from 'frappe-ui'
import { useStorage } from '@vueuse/core'
import { computed, h, provide } from 'vue'
import { computed, h } from 'vue'
const { getPinnedViews, getPublicViews } = viewsStore()
const { toggle: toggleNotificationPanel } = notificationsStore()
Expand Down
18 changes: 2 additions & 16 deletions frontend/src/components/UserDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import { usersStore } from '@/stores/users'
import { getSettings } from '@/stores/settings'
import { showSettings } from '@/composables/settings'
import { Dropdown } from 'frappe-ui'
import { useStorage } from '@vueuse/core'
import { computed, h, markRaw, onMounted } from 'vue'
import { theme, toggleTheme } from '@/stores/theme'
import { computed, h, markRaw } from 'vue'
const props = defineProps({
isCollapsed: {
Expand All @@ -72,8 +72,6 @@ const { getUser } = usersStore()
const user = computed(() => getUser() || {})
const theme = useStorage('theme', 'light')
const dropdownItems = computed(() => {
if (!settings.value?.dropdown_items) return []
Expand Down Expand Up @@ -165,16 +163,4 @@ function getStandardItem(item) {
}
}
}
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme')
theme.value = currentTheme === 'dark' ? 'light' : 'dark'
document.documentElement.setAttribute('data-theme', theme.value)
}
onMounted(() => {
if (['light', 'dark'].includes(theme.value)) {
document.documentElement.setAttribute('data-theme', theme.value)
}
})
</script>
16 changes: 16 additions & 0 deletions frontend/src/stores/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useStorage } from '@vueuse/core'

export const theme = useStorage('theme', 'light')

export function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme')
theme.value = currentTheme === 'dark' ? 'light' : 'dark'
document.documentElement.setAttribute('data-theme', theme.value)
}

export function setTheme(value) {
theme.value = value || theme.value
if (['light', 'dark'].includes(theme.value)) {
document.documentElement.setAttribute('data-theme', theme.value)
}
}

0 comments on commit 211107f

Please sign in to comment.