mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-19 06:14:04 +00:00
Frontend reorganisation
This commit is contained in:
20
frontend/src/lib/stores/busy.js
Normal file
20
frontend/src/lib/stores/busy.js
Normal 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;
|
3
frontend/src/lib/stores/connections.js
Normal file
3
frontend/src/lib/stores/connections.js
Normal file
@ -0,0 +1,3 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const connections = writable({});
|
14
frontend/src/lib/stores/contextmenu.js
Normal file
14
frontend/src/lib/stores/contextmenu.js
Normal 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;
|
15
frontend/src/lib/stores/environment.js
Normal file
15
frontend/src/lib/stores/environment.js
Normal 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;
|
14
frontend/src/lib/stores/inited.js
Normal file
14
frontend/src/lib/stores/inited.js
Normal 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;
|
23
frontend/src/lib/stores/settings.js
Normal file
23
frontend/src/lib/stores/settings.js
Normal 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;
|
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