1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-19 06:14:04 +00:00

Frontend reorganisation

This commit is contained in:
2023-02-14 17:51:00 +01:00
parent f606a4807c
commit 3291bc845f
31 changed files with 165 additions and 148 deletions

View File

@ -0,0 +1,20 @@
import { writable } from 'svelte/store';
const { update, subscribe } = writable(0);
subscribe(isBusy => {
if (isBusy) {
document.body.classList.add('busy');
}
else {
document.body.classList.remove('busy');
}
});
const busy = {
start: () => update(v => ++v),
end: () => update(v => --v),
subscribe,
};
export default busy;

View File

@ -0,0 +1,3 @@
import { writable } from 'svelte/store';
export const connections = writable({});

View File

@ -0,0 +1,14 @@
import { writable } from 'svelte/store';
const { set, subscribe } = writable();
const contextMenu = {
show: (evt, menu) => set(Object.keys(menu || {}).length ? {
position: [ evt.clientX, evt.clientY ],
items: menu,
} : undefined),
hide: () => set(undefined),
subscribe,
};
export default contextMenu;

View File

@ -0,0 +1,15 @@
import { writable } from 'svelte/store';
import { Environment } from '../../../wailsjs/go/app/App';
const { set, subscribe } = writable({});
async function reload() {
const newEnv = await Environment();
set(newEnv);
return newEnv;
}
reload();
const environment = { reload, subscribe };
export default environment;

View File

@ -0,0 +1,14 @@
import { derived } from 'svelte/store';
import environment from './environment';
import applicationSettings from './settings';
const applicationInited = derived([ environment, applicationSettings ], ([ env, settings ], set) => {
if (env && settings) {
set(true);
// Remove loading spinner.
document.getElementById('app-loading')?.remove();
}
}, false);
export default applicationInited;

View File

@ -0,0 +1,23 @@
import { writable } from 'svelte/store';
import { Settings, UpdateSettings } from '../../../wailsjs/go/app/App';
const { set, subscribe } = writable({});
let skipUpdate = true;
async function reload() {
const newSettings = await Settings();
set(newSettings);
return newSettings;
}
reload();
subscribe(newSettings => {
if (skipUpdate) {
skipUpdate = false;
return;
}
UpdateSettings(JSON.stringify(newSettings || {}));
});
const applicationSettings = { reload, set, subscribe };
export default applicationSettings;

View 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;