@axium/tasks 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/TaskList.svelte +33 -21
- package/package.json +1 -1
package/lib/TaskList.svelte
CHANGED
|
@@ -6,11 +6,22 @@
|
|
|
6
6
|
import { fetchAPI } from '@axium/client/requests';
|
|
7
7
|
import type { Task, TaskList } from '@axium/tasks/common';
|
|
8
8
|
import type { WithRequired } from 'utilium';
|
|
9
|
+
import { download } from 'utilium/dom.js';
|
|
9
10
|
|
|
10
11
|
let { list = $bindable(), lists = $bindable() }: { list: WithRequired<TaskList, 'tasks'>; lists?: WithRequired<TaskList, 'tasks'>[] } =
|
|
11
12
|
$props();
|
|
12
13
|
|
|
13
14
|
let tasks = $state(list.tasks);
|
|
15
|
+
|
|
16
|
+
function exportTask(task: Task): string {
|
|
17
|
+
const children = tasks
|
|
18
|
+
.filter(t => t.parentId === task.id)
|
|
19
|
+
.map(exportTask)
|
|
20
|
+
.map(str => '\t' + str)
|
|
21
|
+
.join('\n');
|
|
22
|
+
|
|
23
|
+
return `[${task.completed ? 'x' : ' '}] ${task.summary}` + children;
|
|
24
|
+
}
|
|
14
25
|
</script>
|
|
15
26
|
|
|
16
27
|
{#snippet task_tree(root: Task)}
|
|
@@ -42,18 +53,16 @@
|
|
|
42
53
|
<Popover>
|
|
43
54
|
<div
|
|
44
55
|
class="menu-item"
|
|
45
|
-
onclick={
|
|
46
|
-
e.stopPropagation();
|
|
56
|
+
onclick={() =>
|
|
47
57
|
fetchAPI('DELETE', 'tasks/:id', {}, root.id).then(() => {
|
|
48
58
|
tasks.splice(tasks.indexOf(root), 1);
|
|
49
|
-
})
|
|
50
|
-
}}
|
|
59
|
+
})}
|
|
51
60
|
>
|
|
52
61
|
<Icon i="trash" /> Delete
|
|
53
62
|
</div>
|
|
54
63
|
{#if page.data.session?.user.preferences.debug}
|
|
55
64
|
<div class="menu-item" onclick={() => copy('text/plain', root.id)}>
|
|
56
|
-
<Icon i="
|
|
65
|
+
<Icon i="hashtag" --size="14px" /> Copy ID
|
|
57
66
|
</div>
|
|
58
67
|
{/if}
|
|
59
68
|
</Popover>
|
|
@@ -77,30 +86,35 @@
|
|
|
77
86
|
<Popover>
|
|
78
87
|
<div
|
|
79
88
|
class="menu-item"
|
|
80
|
-
onclick={
|
|
81
|
-
e.stopPropagation();
|
|
89
|
+
onclick={() =>
|
|
82
90
|
fetchAPI('DELETE', 'task_lists/:id', {}, list.id).then(() => {
|
|
83
91
|
if (!lists) goto('/tasks');
|
|
84
92
|
else lists.splice(lists.indexOf(list), 1);
|
|
85
|
-
})
|
|
86
|
-
}}
|
|
93
|
+
})}
|
|
87
94
|
>
|
|
88
95
|
<Icon i="trash" /> Delete
|
|
89
96
|
</div>
|
|
97
|
+
<div
|
|
98
|
+
class="menu-item"
|
|
99
|
+
onclick={() =>
|
|
100
|
+
download(
|
|
101
|
+
list.name + '.txt',
|
|
102
|
+
list.tasks
|
|
103
|
+
.filter(task => !task.parentId)
|
|
104
|
+
.map(exportTask)
|
|
105
|
+
.join('\n')
|
|
106
|
+
)}
|
|
107
|
+
>
|
|
108
|
+
<Icon i="file-arrow-down" /> Export
|
|
109
|
+
</div>
|
|
90
110
|
{#if lists}
|
|
91
|
-
<div
|
|
92
|
-
class="menu-item"
|
|
93
|
-
onclick={e => {
|
|
94
|
-
e.currentTarget.parentElement?.togglePopover();
|
|
95
|
-
open(`/tasks/${list.id}`);
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
111
|
+
<div class="menu-item" onclick={() => open(`/tasks/${list.id}`)}>
|
|
98
112
|
<Icon i="arrow-up-right-from-square" /> Open in New Tab
|
|
99
113
|
</div>
|
|
100
114
|
{/if}
|
|
101
115
|
{#if page.data.session?.user.preferences.debug}
|
|
102
116
|
<div class="menu-item" onclick={() => copy('text/plain', list.id)}>
|
|
103
|
-
<Icon i="
|
|
117
|
+
<Icon i="hashtag" --size="14px" /> Copy ID
|
|
104
118
|
</div>
|
|
105
119
|
{/if}
|
|
106
120
|
</Popover>
|
|
@@ -108,12 +122,10 @@
|
|
|
108
122
|
<div>
|
|
109
123
|
<button
|
|
110
124
|
class="icon-text"
|
|
111
|
-
onclick={
|
|
112
|
-
e.stopPropagation();
|
|
125
|
+
onclick={() =>
|
|
113
126
|
fetchAPI('PUT', 'task_lists/:id', { summary: '' }, list.id)
|
|
114
127
|
.then(t => t)
|
|
115
|
-
.then(tasks.push.bind(tasks))
|
|
116
|
-
}}
|
|
128
|
+
.then(tasks.push.bind(tasks))}
|
|
117
129
|
>
|
|
118
130
|
<Icon i="regular/circle-plus" /> Add Task
|
|
119
131
|
</button>
|