mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 11:56:00 +00:00
perspectives WIP
This commit is contained in:
25
packages/web/src/utility/usePerspectiveConfig.ts
Normal file
25
packages/web/src/utility/usePerspectiveConfig.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createPerspectiveConfig } from 'dbgate-datalib';
|
||||
import { writable } from 'svelte/store';
|
||||
import { onDestroy } from 'svelte';
|
||||
|
||||
function doLoadPerspectiveConfigFunc(tabid) {
|
||||
try {
|
||||
const existing = localStorage.getItem(`tabdata_perspective_${tabid}`);
|
||||
if (existing) {
|
||||
return {
|
||||
...createPerspectiveConfig(),
|
||||
...JSON.parse(existing),
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Error loading perspective config:', err.message);
|
||||
}
|
||||
return createPerspectiveConfig();
|
||||
}
|
||||
|
||||
export default function usePerspectiveConfig(tabid) {
|
||||
const config = writable(doLoadPerspectiveConfigFunc(tabid));
|
||||
const unsubscribe = config.subscribe(value => localStorage.setItem(`tabdata_perspective_${tabid}`, JSON.stringify(value)));
|
||||
onDestroy(unsubscribe);
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user