Repository navigation
Expand file tree
/
Copy pathviews.ts
More file actions
109 lines (97 loc) · 2.26 KB
/
Copy pathviews.ts
File metadata and controls
109 lines (97 loc) · 2.26 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
export type DetailLevel = "compact" | "full";
type ItemType = "to-do" | "project" | "heading";
type ItemStatus = "incomplete" | "canceled" | "completed";
type StartBucket = "Inbox" | "Anytime" | "Someday" | "";
type ChecklistItem = {
id: string;
title: string;
status: ItemStatus;
stopDate: string | null;
};
type TaskLike = {
id: string;
type: ItemType;
title: string;
status: ItemStatus;
trashed: boolean;
notes: string;
start: StartBucket;
startDate: string | null;
deadline: string | null;
deadlineSuppressed: boolean;
stopDate: string | null;
created: string | null;
modified: string | null;
areaId: string | null;
areaTitle: string | null;
projectId: string | null;
projectTitle: string | null;
headingId: string | null;
headingTitle: string | null;
tags: string[];
checklist: ChecklistItem[];
index: number;
todayIndex: number;
};
type AreaLike = {
id: string;
title: string;
tags: string[];
};
type TagLike = {
id: string;
title: string;
shortcut: string | null;
};
export function applyLimit<T>(items: T[], limit?: number): T[] {
if (!limit || limit <= 0) return items;
return items.slice(0, limit);
}
export function toCompactTask(task: TaskLike) {
return {
id: task.id,
type: task.type,
title: task.title,
status: task.status,
start: task.start,
startDate: task.startDate,
deadline: task.deadline,
stopDate: task.stopDate,
areaId: task.areaId,
areaTitle: task.areaTitle,
projectId: task.projectId,
projectTitle: task.projectTitle,
headingId: task.headingId,
headingTitle: task.headingTitle,
};
}
export function toFullTask(task: TaskLike, options?: { includeChecklist?: boolean }) {
if (options?.includeChecklist === false) {
return {
...task,
checklist: [],
};
}
return task;
}
export function toTaskView(
task: TaskLike,
detail: DetailLevel,
options?: { includeChecklist?: boolean }
) {
return detail === "full" ? toFullTask(task, options) : toCompactTask(task);
}
export function toCompactArea(area: AreaLike) {
return {
id: area.id,
title: area.title,
tags: area.tags,
};
}
export function toCompactTag(tag: TagLike) {
return {
id: tag.id,
title: tag.title,
shortcut: tag.shortcut,
};
}