-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
31 lines (25 loc) · 759 Bytes
/
index.ts
File metadata and controls
31 lines (25 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import "@logseq/libs";
import * as dayjs from 'dayjs'
const TASK_MARKERS = new Set(["DONE", "NOW", "LATER", "DOING", "TODO", "WAITING"]);
function main() {
logseq.DB.onChanged(async (e) => {
const taskBlock = e.blocks.find((block) => TASK_MARKERS.has(block.marker));
if (!taskBlock) {
return;
}
const hasProperty = taskBlock.properties?.doneMs;
if (taskBlock.marker === "DONE") {
if (hasProperty) {
return;
}
const now = dayjs();
logseq.Editor.upsertBlockProperty(taskBlock.uuid, "done-ms", now.valueOf());
} else {
if (!hasProperty) {
return;
}
logseq.Editor.removeBlockProperty(taskBlock.uuid, "done-ms");
}
});
}
logseq.ready(main).catch(console.error);