save perspective to file

This commit is contained in:
Jan Prochazka
2022-08-06 17:43:49 +02:00
parent cc019281d4
commit 563a35560b
7 changed files with 101 additions and 48 deletions

View File

@@ -1,27 +0,0 @@
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;
}