Skip to content

Commit 8e12609

Browse files
Merge pull request #193 from tmgr-dev/feature/theme-selection
feat: user theme selection (17 palettes + canonical light/dark)
2 parents 7127ed4 + a195351 commit 8e12609

16 files changed

Lines changed: 665 additions & 9 deletions

File tree

‎index.html‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
<!DOCTYPE html>
2-
<html lang="en" class="dark">
2+
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5+
<script>
6+
(function () {
7+
try {
8+
var DARK = { dracula:1, nord:1, 'one-dark':1, monokai:1, 'solarized-dark':1, 'gruvbox-dark':1, 'tokyo-night':1, 'github-dark':1, 'night-owl':1, cobalt2:1, palenight:1, 'ayu-dark':1, 'catppuccin-mocha':1, 'synthwave-84':1, oled:1, colorblind:1 };
9+
var html = document.documentElement;
10+
var theme = localStorage.getItem('theme');
11+
var cs = localStorage.getItem('colorScheme');
12+
var dark;
13+
if (theme && theme !== 'default' && (theme in DARK || theme === 'github-light')) {
14+
html.classList.add('theme-' + theme);
15+
dark = !!DARK[theme];
16+
} else if (cs === 'dark' || cs === 'default') {
17+
dark = cs === 'dark';
18+
} else {
19+
dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
20+
}
21+
if (dark) html.classList.add('dark'); else html.classList.remove('dark');
22+
} catch (e) {}
23+
})();
24+
</script>
525
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
626
<meta content="width=device-width,initial-scale=1.0,viewport-fit=cover" name="viewport" />
727
<!-- CHANGES: Optimized font loading for better LCP -->

‎src/actions/tmgr/user.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import $axios from '@/plugins/axios';
22
import store from '@/store';
33
import { FormSetting, Setting } from '@/actions/tmgr/settings';
4+
import { pickThemeFromSettings } from '@/theme/reconcile';
5+
6+
export { pickThemeFromSettings };
47

58
export interface User {
69
id: number;
@@ -17,6 +20,11 @@ export const getUser = async () => {
1720

1821
store.commit('setUser', data);
1922

23+
const picked = pickThemeFromSettings(data?.settings);
24+
if (picked.theme !== undefined) store.commit('setTheme', picked.theme);
25+
if (picked.colorScheme !== undefined)
26+
store.commit('setColorScheme', picked.colorScheme);
27+
2028
return data;
2129
};
2230

@@ -71,3 +79,19 @@ export const updateUserSettingsV2 = async (payload: UserSettings) => {
7179

7280
return data;
7381
};
82+
83+
export const persistThemeSettings = async (
84+
theme: string,
85+
colorScheme: string,
86+
) => {
87+
const current = Array.isArray(store.state.user?.settings)
88+
? store.state.user.settings
89+
: [];
90+
const payload = current.map((s: any) => {
91+
if (s.key === 'theme') return { id: s.id, value: theme };
92+
if (s.key === 'colorScheme') return { id: s.id, value: colorScheme };
93+
return { id: s.id, value: s.value };
94+
});
95+
const updatedUser = await updateUserSettingsV2(payload);
96+
store.commit('setUser', updatedUser);
97+
};

‎src/components/general/CustomSidebar.vue‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
LogOut,
4343
SquareKanban,
4444
Plus,
45+
Palette,
4546
Settings2,
4647
Inbox,
4748
Package,
@@ -663,6 +664,13 @@
663664
<Sliders />
664665
Feature Settings
665666
</DropdownMenuItem>
667+
<DropdownMenuItem
668+
@click="$router.push('/settings?tab=theme')"
669+
class="cursor-pointer"
670+
>
671+
<Palette />
672+
Theme
673+
</DropdownMenuItem>
666674
<DropdownMenuItem>
667675
<DarkMode />
668676
</DropdownMenuItem>

‎src/components/general/DarkMode.vue‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
import store from '@/store';
44
import { computed } from 'vue';
55
6+
const isDefaultTheme = computed(
7+
() => (store.state.theme || 'default') === 'default',
8+
);
69
const switchOn = computed({
710
get() {
811
return store.state.colorScheme === 'dark';
912
},
1013
set(value) {
14+
if (!isDefaultTheme.value) return;
1115
store.commit('setColorScheme', value ? 'dark' : 'default');
1216
},
1317
});
1418
</script>
1519

1620
<template>
17-
<a href="#" @click="switchOn = !switchOn">
21+
<a v-if="isDefaultTheme" href="#" @click="switchOn = !switchOn">
1822
<div v-if="switchOn" class="flex">
1923
<Sun class="size-4" />
2024
<span class="ml-2">Light mode</span>

0 commit comments

Comments
 (0)