mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-01-22 19:06:12 +00:00
e39f16e436
Date & Time Display Added a real-time clock component in the sidebar Event Logs System Implemented an EventLogsTab component for system monitoring Provides a structured way to: Track user interactions Monitor system events Display activity history
35 lines
975 B
TypeScript
35 lines
975 B
TypeScript
import { atom } from 'nanostores';
|
|
import { logStore } from './logs';
|
|
|
|
export type Theme = 'dark' | 'light';
|
|
|
|
export const kTheme = 'bolt_theme';
|
|
|
|
export function themeIsDark() {
|
|
return themeStore.get() === 'dark';
|
|
}
|
|
|
|
export const DEFAULT_THEME = 'light';
|
|
|
|
export const themeStore = atom<Theme>(initStore());
|
|
|
|
function initStore() {
|
|
if (!import.meta.env.SSR) {
|
|
const persistedTheme = localStorage.getItem(kTheme) as Theme | undefined;
|
|
const themeAttribute = document.querySelector('html')?.getAttribute('data-theme');
|
|
|
|
return persistedTheme ?? (themeAttribute as Theme) ?? DEFAULT_THEME;
|
|
}
|
|
|
|
return DEFAULT_THEME;
|
|
}
|
|
|
|
export function toggleTheme() {
|
|
const currentTheme = themeStore.get();
|
|
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
|
themeStore.set(newTheme);
|
|
logStore.logSystem(`Theme changed to ${newTheme} mode`);
|
|
localStorage.setItem(kTheme, newTheme);
|
|
document.querySelector('html')?.setAttribute('data-theme', newTheme);
|
|
}
|