mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-10 20:35:48 +02:00
web/state/task-manager: use writable-readonly store instead of readable
This commit is contained in:
@ -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({});
|
||||
}
|
||||
|
Reference in New Issue
Block a user