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:
@@ -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);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user