feat: add prettier and eslint with pre-commit hook
This commit is contained in:
@@ -1,41 +1,41 @@
|
||||
type Theme = 'light' | 'dark'
|
||||
type Theme = 'light' | 'dark';
|
||||
|
||||
const STORAGE_KEY = 'theme'
|
||||
const STORAGE_KEY = 'theme';
|
||||
|
||||
const getSavedTheme = (): Theme => {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw === 'light' || raw === 'dark') {
|
||||
return raw
|
||||
return raw;
|
||||
}
|
||||
return 'dark'
|
||||
}
|
||||
return 'dark';
|
||||
};
|
||||
|
||||
const applyTheme = (theme: Theme): void => {
|
||||
document.documentElement.setAttribute('data-theme', theme)
|
||||
localStorage.setItem(STORAGE_KEY, theme)
|
||||
}
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem(STORAGE_KEY, theme);
|
||||
};
|
||||
|
||||
const cycleTheme = (): void => {
|
||||
const current = getSavedTheme()
|
||||
const next: Theme = current === 'light' ? 'dark' : 'light'
|
||||
applyTheme(next)
|
||||
}
|
||||
const current = getSavedTheme();
|
||||
const next: Theme = current === 'light' ? 'dark' : 'light';
|
||||
applyTheme(next);
|
||||
};
|
||||
|
||||
const initTheme = (): void => {
|
||||
const saved = getSavedTheme()
|
||||
applyTheme(saved)
|
||||
const saved = getSavedTheme();
|
||||
applyTheme(saved);
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
const target = e.target as HTMLElement
|
||||
const btn = target.closest('#theme-toggle, #footer-theme-toggle') as HTMLButtonElement | null
|
||||
document.addEventListener('click', e => {
|
||||
const target = e.target as HTMLElement;
|
||||
const btn = target.closest('#theme-toggle, #footer-theme-toggle') as HTMLButtonElement | null;
|
||||
if (btn) {
|
||||
cycleTheme()
|
||||
cycleTheme();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initTheme)
|
||||
document.addEventListener('DOMContentLoaded', initTheme);
|
||||
} else {
|
||||
initTheme()
|
||||
initTheme();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user