1
0
mirror of https://github.com/koloml/philomena-tagging-assistant.git synced 2026-05-09 15:12:21 +00:00

Setting and resetting active maintenance profile using stores

This commit is contained in:
2024-03-23 03:12:24 +04:00
parent 98ae8ef1c0
commit 659d9d4e73
3 changed files with 134 additions and 61 deletions

View File

@@ -1,7 +1,12 @@
import {writable} from "svelte/store";
import MaintenanceProfile from "$lib/extension/entities/MaintenanceProfile.js";
import MaintenanceSettings from "$lib/extension/settings/MaintenanceSettings.js";
/** @type {import('svelte/store').Writable<MaintenanceProfile[]>} */
/**
* Store for working with maintenance profiles in the Svelte popup.
*
* @type {import('svelte/store').Writable<MaintenanceProfile[]>}
*/
export const maintenanceProfilesStore = writable([]);
MaintenanceProfile.readAll().then(profiles => {
@@ -10,4 +15,31 @@ MaintenanceProfile.readAll().then(profiles => {
MaintenanceProfile.subscribe(profiles => {
maintenanceProfilesStore.set(profiles);
});
});
/**
* Store for the active maintenance profile ID.
*
* @type {import('svelte/store').Writable<string|null>}
*/
export const activeProfileStore = writable(null);
const maintenanceSettings = new MaintenanceSettings();
maintenanceSettings.resolveActiveProfileId().then(activeProfileId => {
activeProfileStore.set(activeProfileId);
});
MaintenanceSettings.subscribe(settings => {
activeProfileStore.set(settings.activeProfileId || null);
});
let lastActiveProfileId = null;
activeProfileStore.subscribe(profileId => {
if (profileId === lastActiveProfileId) {
return;
}
void maintenanceSettings.setActiveProfileId(profileId);
})