-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ThemeSwitcher refactoring followup (#10342)
* ThemeSwitcher refactoring followup * Update changelog, update import, fix tests * Add auto theme option (localStorage still wrong) * Fix auto theme * Fix auto theme mode * Update snapshots
- Loading branch information
Showing
7 changed files
with
89 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<div> | ||
<oc-select | ||
:model-value="currentThemeOrAuto" | ||
:clearable="false" | ||
:options="availableThemesAndAuto" | ||
option-label="name" | ||
@update:model-value="updateTheme" | ||
/> | ||
</div> | ||
</template> | ||
<script lang="ts"> | ||
import { computed, defineComponent, ref, unref } from 'vue' | ||
import { useMessages, useThemeStore, WebThemeType } from '@ownclouders/web-pkg' | ||
import { storeToRefs } from 'pinia' | ||
import { useGettext } from 'vue3-gettext' | ||
export default defineComponent({ | ||
setup() { | ||
const themeStore = useThemeStore() | ||
const { showMessage } = useMessages() | ||
const { $gettext } = useGettext() | ||
const autoTheme = computed(() => ({ name: $gettext('Auto (same as system)') })) | ||
const { availableThemes, currentTheme } = storeToRefs(themeStore) | ||
const currentThemeSelection = ref(null) | ||
const { setAndApplyTheme, setAutoSystemTheme, isCurrentThemeAutoSystem } = themeStore | ||
const updateTheme = (newTheme: WebThemeType) => { | ||
currentThemeSelection.value = newTheme | ||
showMessage({ title: $gettext('Preference saved.') }) | ||
if (newTheme == unref(autoTheme)) { | ||
return setAutoSystemTheme() | ||
} | ||
setAndApplyTheme(newTheme) | ||
} | ||
const currentThemeOrAuto = computed(() => { | ||
if (unref(currentThemeSelection)) { | ||
return unref(currentThemeSelection) | ||
} | ||
if (unref(isCurrentThemeAutoSystem)) { | ||
return unref(autoTheme) | ||
} | ||
return unref(currentTheme) | ||
}) | ||
const availableThemesAndAuto = computed(() => [unref(autoTheme), ...unref(availableThemes)]) | ||
return { | ||
availableThemesAndAuto, | ||
currentThemeOrAuto, | ||
updateTheme | ||
} | ||
} | ||
}) | ||
</script> |
43 changes: 0 additions & 43 deletions
43
packages/web-runtime/src/components/Topbar/ThemeSwitcher.vue
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/web-runtime/tests/unit/components/Topbar/ThemeSwitcher.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters