From b48e08ec8da0fd92e4810ef2b18091659437f395 Mon Sep 17 00:00:00 2001 From: ahonn Date: Mon, 25 Apr 2022 20:11:26 +0800 Subject: [PATCH] feat: show task scheduled time and open task in right sidebar --- src/components/TaskItem.tsx | 29 +++++++++++++++++++++++------ src/models/Task.ts | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/components/TaskItem.tsx b/src/components/TaskItem.tsx index b6e47e3..43d930b 100644 --- a/src/components/TaskItem.tsx +++ b/src/components/TaskItem.tsx @@ -3,6 +3,7 @@ import classnames from 'classnames'; import dayjs from 'dayjs'; import Checkbox from 'rc-checkbox'; import Task from '../models/Task'; +import { InfoCircle } from 'tabler-icons-react'; import useUserConfigs from '../hooks/useUserConfigs'; import 'rc-checkbox/assets/index.css'; @@ -15,6 +16,11 @@ const TaskItem: React.FC = (props) => { const { item: task, onChange } = props; const [checked, setChecked] = React.useState(task.isDone()); const { preferredDateFormat } = useUserConfigs(); + const [scheduled, setScheduled] = React.useState(null); + + useEffect(() => { + task.getScheduledDate().then(setScheduled); + }, [task]); const handleTaskChange = async () => { await task.toggle(); @@ -22,6 +28,10 @@ const TaskItem: React.FC = (props) => { onChange(task); }; + const openTaskBlock = () => { + window.logseq.Editor.openInRightSidebar(task.uuid); + }; + const contentClassName = classnames( 'flex-1 border-b border-gray-100 pb-2 pt-1 text-sm leading-normal', { @@ -40,12 +50,19 @@ const TaskItem: React.FC = (props) => { />
-

{task.content}

- {task.scheduled && ( - - )} +
+
+

{task.content}

+ {scheduled && ( + + )} +
+
+ +
+
); diff --git a/src/models/Task.ts b/src/models/Task.ts index 6c29111..92ede10 100644 --- a/src/models/Task.ts +++ b/src/models/Task.ts @@ -1,4 +1,4 @@ -import { BlockEntity } from '@logseq/libs/dist/LSPlugin'; +import { BlockEntity, PageEntity } from '@logseq/libs/dist/LSPlugin'; import dayjs, { Dayjs } from 'dayjs'; export enum TaskMarker { @@ -120,6 +120,21 @@ class Task { return this.block.marker === TaskMarker.DONE; } + public async getScheduledDate(): Promise { + if (this.block.scheduled) { + return dayjs(this.block.scheduled.toString(), 'YYYYMMDD').toDate(); + } + + const block = await window.logseq.Editor.getBlock(this.uuid, { includeChildren: true }); + const page = block?.page as PageEntity | undefined; + console.log(block); + if (page?.journalDay) { + return dayjs(page.journalDay.toString(), 'YYYYMMDD').toDate(); + } + + return null; + } + public async toggle(): Promise { const nextMarker = this.isDone() ? TaskMarker.LATER : TaskMarker.DONE; await window.logseq.Editor.updateBlock(