Skip to content

Commit

Permalink
chore: simplify logic for theme -> diagram theme
Browse files Browse the repository at this point in the history
Co-authored-by: Sidharth Vinod <github@sidharth.dev>
  • Loading branch information
Yash-Singh1 and sidharthv96 committed Apr 22, 2022
1 parent c18574c commit 59679ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/util/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export const updateConfig = (config: string, updateEditor: boolean): void => {
});
};

export const toggleDarkTheme = (dark: boolean, theme: string): void => {
export const setDiagramTheme = (theme: 'dark' | 'default' | 'forest'): void => {
codeStore.update((state) => {
const config = JSON.parse(state.mermaid);
if (!config.theme || ['dark', 'default', 'forest'].includes(config.theme)) {
config.theme = dark ? (theme === 'forest' ? 'forest' : 'dark') : 'default';
config.theme = theme;
}

return { ...state, mermaid: JSON.stringify(config, null, 2), updateEditor: true };
Expand Down
4 changes: 2 additions & 2 deletions src/routes/__layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { onMount } from 'svelte';
import { loadingStateStore } from '$lib/util/loading';
import { setTheme, themeStore } from '$lib/util/theme';
import { toggleDarkTheme } from '$lib/util/state';
import { setDiagramTheme } from '$lib/util/state';
// This can be removed once https://github.com/sveltejs/kit/issues/1612 is fixed.
// Then move it into src and vite will bundle it automatically.
Expand All @@ -31,7 +31,7 @@
themeStore.subscribe(({ theme, isDark }) => {
if (theme) {
document.getElementsByTagName('html')[0].setAttribute('data-theme', theme);
toggleDarkTheme(isDark, theme);
setDiagramTheme(isDark ? (theme === 'forest' ? 'forest' : 'dark') : 'default');
}
});
});
Expand Down

0 comments on commit 59679ab

Please sign in to comment.