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