ui refactor
This commit is contained in:
@@ -2,6 +2,9 @@ import { atom, map } from 'nanostores';
|
||||
import { workbenchStore } from './workbench';
|
||||
import { PROVIDER_LIST } from '~/utils/constants';
|
||||
import type { IProviderConfig } from '~/types/model';
|
||||
import type { TabVisibilityConfig, TabWindowConfig } from '~/components/settings/settings.types';
|
||||
import { DEFAULT_TAB_CONFIG } from '~/components/settings/settings.types';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export interface Shortcut {
|
||||
key: string;
|
||||
@@ -46,7 +49,9 @@ export const providersStore = map<ProviderSetting>(initialProviderSettings);
|
||||
|
||||
export const isDebugMode = atom(false);
|
||||
|
||||
export const isEventLogsEnabled = atom(false);
|
||||
// Initialize event logs from cookie or default to false
|
||||
const savedEventLogs = Cookies.get('isEventLogsEnabled');
|
||||
export const isEventLogsEnabled = atom(savedEventLogs === 'true');
|
||||
|
||||
export const isLocalModelsEnabled = atom(true);
|
||||
|
||||
@@ -56,3 +61,48 @@ export const latestBranchStore = atom(false);
|
||||
|
||||
export const autoSelectStarterTemplate = atom(false);
|
||||
export const enableContextOptimizationStore = atom(false);
|
||||
|
||||
// Initialize tab configuration from cookie or default
|
||||
const savedTabConfig = Cookies.get('tabConfiguration');
|
||||
const initialTabConfig: TabWindowConfig = savedTabConfig
|
||||
? JSON.parse(savedTabConfig)
|
||||
: {
|
||||
userTabs: DEFAULT_TAB_CONFIG.filter((tab) => tab.window === 'user'),
|
||||
developerTabs: DEFAULT_TAB_CONFIG.filter((tab) => tab.window === 'developer'),
|
||||
};
|
||||
|
||||
export const tabConfigurationStore = map<TabWindowConfig>(initialTabConfig);
|
||||
|
||||
// Helper function to update tab configuration
|
||||
export const updateTabConfiguration = (config: TabVisibilityConfig) => {
|
||||
const currentConfig = tabConfigurationStore.get();
|
||||
const isUserTab = config.window === 'user';
|
||||
const targetArray = isUserTab ? 'userTabs' : 'developerTabs';
|
||||
|
||||
// Only update the tab in its respective window
|
||||
const updatedTabs = currentConfig[targetArray].map((tab) => (tab.id === config.id ? { ...config } : tab));
|
||||
|
||||
// If tab doesn't exist in this window yet, add it
|
||||
if (!updatedTabs.find((tab) => tab.id === config.id)) {
|
||||
updatedTabs.push(config);
|
||||
}
|
||||
|
||||
// Create new config, only updating the target window's tabs
|
||||
const newConfig: TabWindowConfig = {
|
||||
...currentConfig,
|
||||
[targetArray]: updatedTabs,
|
||||
};
|
||||
|
||||
tabConfigurationStore.set(newConfig);
|
||||
Cookies.set('tabConfiguration', JSON.stringify(newConfig));
|
||||
};
|
||||
|
||||
// Helper function to reset tab configuration
|
||||
export const resetTabConfiguration = () => {
|
||||
const defaultConfig: TabWindowConfig = {
|
||||
userTabs: DEFAULT_TAB_CONFIG.filter((tab) => tab.window === 'user'),
|
||||
developerTabs: DEFAULT_TAB_CONFIG.filter((tab) => tab.window === 'developer'),
|
||||
};
|
||||
tabConfigurationStore.set(defaultConfig);
|
||||
Cookies.set('tabConfiguration', JSON.stringify(defaultConfig));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user