web/state/task-manager: use writable-readonly store instead of readable

This commit is contained in:
jj
2025-06-01 10:11:40 +00:00
parent 7f5a9cfa75
commit b4a53d0fde

View File

@ -1,38 +1,32 @@
import { readable, type Updater } from "svelte/store";
import { readonly, writable } from "svelte/store";
import type { CobaltWorkerProgress } from "$lib/types/workers";
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/task-manager";
let update: (_: Updater<CobaltCurrentTasks>) => void;
export const currentTasks = readable<CobaltCurrentTasks>(
{},
(_, _update) => { update = _update }
);
const currentTasks_ = writable<CobaltCurrentTasks>({});
export const currentTasks = readonly(currentTasks_);
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
update(tasks => {
currentTasks_.update(tasks => {
tasks[workerId] = item;
return tasks;
});
}
export function removeWorkerFromQueue(id: string) {
update(tasks => {
currentTasks_.update(tasks => {
delete tasks[id];
return tasks;
});
}
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
update(allTasks => {
currentTasks_.update(allTasks => {
allTasks[workerId].progress = progress;
return allTasks;
});
}
export function clearCurrentTasks() {
update(() => {
return {};
});
currentTasks_.set({});
}