feat: Refactor theme management and localization for camera and terminal components
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { ACCESS_TOKEN, REFRESH_TOKEN } from '@/constants';
|
||||
import {
|
||||
ACCESS_TOKEN,
|
||||
REFRESH_TOKEN,
|
||||
TERMINAL_THEME_KEY,
|
||||
THEME_KEY,
|
||||
} from '@/constants';
|
||||
|
||||
export function getAccessToken(): string {
|
||||
return localStorage.getItem(ACCESS_TOKEN) || '';
|
||||
@@ -24,6 +29,30 @@ export function removeRefreshToken() {
|
||||
localStorage.removeItem(REFRESH_TOKEN);
|
||||
}
|
||||
|
||||
export function getTerminalTheme(): string {
|
||||
return localStorage.getItem(TERMINAL_THEME_KEY) || 'dark';
|
||||
}
|
||||
|
||||
export function setTerminalTheme(themeKey: string) {
|
||||
localStorage.setItem(TERMINAL_THEME_KEY, themeKey);
|
||||
}
|
||||
|
||||
export function removeTerminalTheme() {
|
||||
localStorage.removeItem(TERMINAL_THEME_KEY);
|
||||
}
|
||||
|
||||
export function getTheme(): string {
|
||||
return localStorage.getItem(THEME_KEY) || 'light';
|
||||
}
|
||||
|
||||
export function setTheme(themeKey: string) {
|
||||
localStorage.setItem(THEME_KEY, themeKey);
|
||||
}
|
||||
|
||||
export function removeTheme() {
|
||||
localStorage.removeItem(THEME_KEY);
|
||||
}
|
||||
|
||||
export function getBrowserId() {
|
||||
const id = localStorage.getItem('sip-browserid');
|
||||
if (!id) {
|
||||
@@ -42,14 +71,18 @@ export function getBrowserId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all localStorage data except browserId
|
||||
* Clear all localStorage data except browserId, theme and terminal theme
|
||||
*/
|
||||
export function clearAllData() {
|
||||
const browserId = localStorage.getItem('sip-browserid');
|
||||
const theme = getTheme();
|
||||
const terminalTheme = getTerminalTheme();
|
||||
localStorage.clear();
|
||||
if (browserId) {
|
||||
localStorage.setItem('sip-browserid', browserId);
|
||||
}
|
||||
localStorage.setItem(THEME_KEY, theme);
|
||||
localStorage.setItem(TERMINAL_THEME_KEY, terminalTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user