generated from pengx17/logseq-plugin-template-react
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BlockEntity } from "@logseq/libs/dist/LSPlugin"; | ||
|
||
export function getBlockUUID(block: BlockEntity) { | ||
if (typeof block.uuid === 'string') { | ||
return block.uuid; | ||
} | ||
// @ts-ignore | ||
return block.uuid.$uuid$; | ||
} |