mod.tsimport {
patch,
useStatusBar,
openInTheSameTab,
} from "../scrapbox-userscript-std/mod.ts";
import { delay as sleep } from "../deno_std%2Fasync/mod.ts";
export async function addToInbox(
project: string, title: string, items: string[]
): Promise<void> {
const { render, dispose } = useStatusBar();
try {
render(
{ type: "spinner" },
{ type: "text", text: `Adding ${items.length} items...` },
);
await patch(project, title, (lines) => [
...lines.map((line) => line.text),
...items,
]);
render(
{ type: "check-circle" },
{ type: "text", text: "Added to the inbox." },
);
} catch(e: unknown) {
render(
{ type: "exclamation-triangle" },
{ type: "text", text: "Failed to add (see console). Write directory instead." },
);
console.error(e);
openInTheSameTab(project, title, items.join("\n"));
} finally {
await sleep(1000);
dispose();
}
}