1
0
silverbullet/plugs/tasks/complete.ts
Zef Hemel a2dbf7b3db
PlugOS refactor and other tweaks (#631)
* Prep for in-process plug loading (e.g. for CF workers, Deno Deploy)
* Prototype of fixed in-process loading plugs
* Fix: buttons not to scroll with content
* Better positioning of modal especially on mobile
* Move query caching outside query
* Fix annoying mouse behavior when filter box appears
* Page navigator search tweaks
2024-01-15 16:43:12 +01:00

22 lines
626 B
TypeScript

import { CompleteEvent } from "$sb/app_event.ts";
import { queryObjects } from "../index/plug_api.ts";
import { TaskStateObject } from "./task.ts";
export async function completeTaskState(completeEvent: CompleteEvent) {
const taskMatch = /([\-\*]\s+\[)([^\[\]]+)$/.exec(
completeEvent.linePrefix,
);
if (!taskMatch) {
return null;
}
const allStates = await queryObjects<TaskStateObject>("taskstate", {}, 5);
const states = [...new Set(allStates.map((s) => s.state))];
return {
from: completeEvent.pos - taskMatch[2].length,
options: states.map((state) => ({
label: state,
})),
};
}