generated from pengx17/logseq-plugin-template-react
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
TaskEntity.ts
64 lines (52 loc) · 1.22 KB
/
TaskEntity.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { BlockEntity, PageEntity } from '@logseq/libs/dist/LSPlugin.user';
import { getBlockUUID } from '../utils';
export enum TaskMarker {
LATER = 'LATER',
NOW = 'NOW',
TODO = 'TODO',
DONE = 'DONE',
}
export interface TaskEntityObject {
uuid: string;
content: string;
marker: TaskMarker;
scheduled: number;
completed: boolean;
}
class TaskEntity {
private block: BlockEntity;
private page: PageEntity;
constructor(block: BlockEntity, page: PageEntity) {
this.block = block;
this.page = page;
}
public get uuid() {
return getBlockUUID(this.block);
}
public get content() {
return this.block.content;
}
public get marker() {
return this.block.marker;
}
public get scheduled() {
return this.block.scheduled ?? this.block.deadline ?? this.page.journalDay;
}
public get completed() {
return this.marker === TaskMarker.DONE;
}
public getPageProperty(key: string) {
// @ts-ignore
return this.page.properties?.[key];
}
public toObject(): TaskEntityObject {
return {
uuid: this.uuid,
content: this.content,
marker: this.marker,
scheduled: this.scheduled,
completed: this.completed,
};
}
}
export default TaskEntity;