dbgate/packages/web/src/stores.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-02-17 19:08:16 +00:00
import { writable } from 'svelte/store';
2021-02-22 17:50:54 +00:00
import { ExtensionsDirectory } from 'dbgate-types';
2021-02-17 19:08:16 +00:00
2021-02-22 16:34:24 +00:00
interface TabDefinition {
title: string;
closedTime?: number;
icon: string;
props: any;
selected: boolean;
busy: boolean;
tabid: string;
}
export function writableWithStorage<T>(defaultValue: T, storageName) {
const init = localStorage.getItem(storageName);
const res = writable<T>(init ? JSON.parse(init) : defaultValue);
res.subscribe(value => {
localStorage.setItem(storageName, JSON.stringify(value));
});
return res;
}
2021-02-17 19:08:16 +00:00
export const selectedWidget = writable('database');
2021-02-20 18:14:22 +00:00
export const openedConnections = writable([]);
export const currentDatabase = writable(null);
2021-02-22 16:34:24 +00:00
export const openedTabs = writableWithStorage<TabDefinition[]>([], 'openedTabs');
2021-02-22 17:50:54 +00:00
export const extensions = writable<ExtensionsDirectory>(null);
2021-02-25 17:05:44 +00:00
export const visibleCommandPalette = writable(false);
export const commands = writable({});
export const currentTheme = writableWithStorage('theme-light', 'currentTheme');
2021-02-20 18:14:22 +00:00
2021-02-20 09:43:43 +00:00
// export const leftPanelWidth = writable(300);