Skip to content

Commit

Permalink
feat: suport WAITING task status, #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonn committed Oct 14, 2022
1 parent 5f069c1 commit f0869b3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import dayjs from 'dayjs';
import { TaskEntityObject, TaskMarker } from './models/TaskEntity';

export const MARKER_GROUPS: Record<string, TaskMarker[]> = {
[TaskMarker.TODO]: [TaskMarker.TODO, TaskMarker.DOING, TaskMarker.DONE],
[TaskMarker.LATER]: [TaskMarker.LATER, TaskMarker.NOW, TaskMarker.DONE],
}

export function isTodayTask(task: TaskEntityObject) {
const { scheduled } = task;
if (!scheduled) return false;
Expand Down Expand Up @@ -44,10 +49,16 @@ export function openTaskPage(page: TaskEntityObject['page'], opts?: IOpenTaskOpt

export async function toggleTaskMarker(task: TaskEntityObject, options: IToggleOptions) {
const { uuid, rawContent, marker } = task;
let newMarker = marker === TaskMarker.TODO ? TaskMarker.DOING : TaskMarker.TODO;
if (options.preferredTodo === TaskMarker.LATER) {
newMarker = marker === TaskMarker.LATER ? TaskMarker.NOW : TaskMarker.LATER;

let newMarker = marker;
if (marker === TaskMarker.WAITING) {
newMarker = options.preferredTodo === TaskMarker.LATER ? TaskMarker.LATER : TaskMarker.TODO;
} else {
const markerGroup = MARKER_GROUPS[options.preferredTodo];
const currentMarkIndex = markerGroup.findIndex(m => m === marker);
newMarker = markerGroup[(currentMarkIndex + 1) % markerGroup.length];
}

const newRawContent = rawContent.replace(new RegExp(`^${marker}`), newMarker);
await window.logseq.Editor.updateBlock(uuid, newRawContent);
}
Expand Down
1 change: 1 addition & 0 deletions src/models/TaskEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum TaskMarker {
TODO = 'TODO',
DOING = 'DOING',
DONE = 'DONE',
WAITING = 'WAITING',
}

export enum TaskPriority {
Expand Down
2 changes: 1 addition & 1 deletion src/querys/anytime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function getAnytimeTaskQuery() {
[:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
[?b :block/page ?p]
(not [?p :block/journal? true])
(not [?p :block/journalDay])
Expand Down
2 changes: 1 addition & 1 deletion src/querys/scheduled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function getScheduledTaskQuery() {
[:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
[?b :block/page ?p]
(or
[?b :block/scheduled ?d]
Expand Down
2 changes: 1 addition & 1 deletion src/querys/today.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function getTodayTaskQuery() {
[:find (pull ?b [*])
:where
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
[(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
[?b :block/page ?p]
(or
(and
Expand Down

0 comments on commit f0869b3

Please sign in to comment.