mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-16 13:04:06 +00:00
Frontend reorganisation
This commit is contained in:
36
frontend/src/lib/stores/views.js
Normal file
36
frontend/src/lib/stores/views.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { UpdateViewStore, Views } from '../../../wailsjs/go/app/App';
|
||||
|
||||
const { set, subscribe } = writable({});
|
||||
let skipUpdate = true;
|
||||
|
||||
async function reload() {
|
||||
const newViewStore = await Views();
|
||||
set(newViewStore);
|
||||
return newViewStore;
|
||||
}
|
||||
|
||||
function forCollection(hostKey, dbKey, collKey) {
|
||||
const allViews = get({ subscribe });
|
||||
const entries = Object.entries(allViews).filter(v => (
|
||||
v[0] === 'list' || (
|
||||
v[1].host === hostKey &&
|
||||
v[1].database === dbKey &&
|
||||
v[1].collection === collKey
|
||||
)
|
||||
));
|
||||
|
||||
return Object.fromEntries(entries);
|
||||
}
|
||||
|
||||
reload();
|
||||
subscribe(newViewStore => {
|
||||
if (skipUpdate) {
|
||||
skipUpdate = false;
|
||||
return;
|
||||
}
|
||||
UpdateViewStore(JSON.stringify(newViewStore));
|
||||
});
|
||||
|
||||
const views = { reload, set, subscribe, forCollection };
|
||||
export default views;
|
Reference in New Issue
Block a user