@axium/tasks 0.1.9 → 0.2.0
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/dist/common.d.ts +5 -0
- package/dist/common.js +3 -0
- package/dist/server.js +17 -1
- package/lib/TaskList.svelte +34 -72
- package/lib/TaskTree.svelte +85 -0
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export declare const TaskListInit: z.ZodObject<{
|
|
|
19
19
|
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
21
|
export type TaskListInit = z.infer<typeof TaskListInit>;
|
|
22
|
+
export declare const TaskListUpdate: z.ZodObject<{
|
|
23
|
+
all_completed: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type TaskListUpdate = z.infer<typeof TaskListUpdate>;
|
|
22
26
|
export interface TaskList extends TaskListInit {
|
|
23
27
|
id: string;
|
|
24
28
|
userId: string;
|
|
@@ -35,6 +39,7 @@ declare module '@axium/core/api' {
|
|
|
35
39
|
'task_lists/:id': {
|
|
36
40
|
GET: WithRequired<TaskList, 'tasks'>;
|
|
37
41
|
PATCH: [z.input<typeof TaskListInit>, TaskList];
|
|
42
|
+
POST: [z.input<typeof TaskListUpdate>, void];
|
|
38
43
|
PUT: [Omit<z.input<typeof TaskInit>, 'listId'>, Task];
|
|
39
44
|
DELETE: TaskList;
|
|
40
45
|
};
|
package/dist/common.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { database, expectedTypes } from '@axium/server/database';
|
|
|
4
4
|
import { parseBody, withError } from '@axium/server/requests';
|
|
5
5
|
import { addRoute } from '@axium/server/routes';
|
|
6
6
|
import * as z from 'zod';
|
|
7
|
-
import { TaskInit, TaskListInit } from './common.js';
|
|
7
|
+
import { TaskInit, TaskListInit, TaskListUpdate } from './common.js';
|
|
8
8
|
import { jsonArrayFrom } from 'kysely/helpers/postgres';
|
|
9
9
|
expectedTypes.tasks = {
|
|
10
10
|
id: { type: 'uuid', required: true, hasDefault: true },
|
|
@@ -91,6 +91,22 @@ addRoute({
|
|
|
91
91
|
.executeTakeFirstOrThrow()
|
|
92
92
|
.catch(withError('Could not update task list'));
|
|
93
93
|
},
|
|
94
|
+
async POST(event) {
|
|
95
|
+
const body = await parseBody(event, TaskListUpdate);
|
|
96
|
+
const id = event.params.id;
|
|
97
|
+
await checkAuthForItem(event, 'task_lists', id, Permission.Edit);
|
|
98
|
+
if (typeof body.all_completed == 'boolean') {
|
|
99
|
+
await database
|
|
100
|
+
.updateTable('tasks')
|
|
101
|
+
.set('completed', body.all_completed)
|
|
102
|
+
.where('listId', '=', id)
|
|
103
|
+
.where('completed', '=', !body.all_completed)
|
|
104
|
+
.returningAll()
|
|
105
|
+
.executeTakeFirstOrThrow()
|
|
106
|
+
.catch(withError('Could not update task list'));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
94
110
|
async DELETE(event) {
|
|
95
111
|
const id = event.params.id;
|
|
96
112
|
await checkAuthForItem(event, 'task_lists', id, Permission.Manage);
|
package/lib/TaskList.svelte
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { Task, TaskList } from '@axium/tasks/common';
|
|
8
8
|
import type { WithRequired } from 'utilium';
|
|
9
9
|
import { download } from 'utilium/dom.js';
|
|
10
|
+
import TaskTree from './TaskTree.svelte';
|
|
10
11
|
|
|
11
12
|
let { list = $bindable(), lists = $bindable() }: { list: WithRequired<TaskList, 'tasks'>; lists?: WithRequired<TaskList, 'tasks'>[] } =
|
|
12
13
|
$props();
|
|
@@ -22,55 +23,10 @@
|
|
|
22
23
|
|
|
23
24
|
return `[${task.completed ? 'x' : ' '}] ${task.summary}` + children;
|
|
24
25
|
}
|
|
25
|
-
</script>
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<Icon i="regular/circle{root.completed ? '-check' : ''}" --size="20px" />
|
|
31
|
-
</label>
|
|
32
|
-
<input
|
|
33
|
-
type="checkbox"
|
|
34
|
-
name="completed"
|
|
35
|
-
bind:checked={root.completed}
|
|
36
|
-
id="task-completed#{root.id}"
|
|
37
|
-
style:display="none"
|
|
38
|
-
onchange={e => {
|
|
39
|
-
root.completed = e.currentTarget.checked;
|
|
40
|
-
fetchAPI('PATCH', 'tasks/:id', { completed: root.completed }, root.id);
|
|
41
|
-
}}
|
|
42
|
-
/>
|
|
43
|
-
<input
|
|
44
|
-
type="text"
|
|
45
|
-
name="summary"
|
|
46
|
-
class="editable-text"
|
|
47
|
-
bind:value={root.summary}
|
|
48
|
-
onchange={e => {
|
|
49
|
-
root.summary = e.currentTarget.value;
|
|
50
|
-
fetchAPI('PATCH', 'tasks/:id', { summary: root.summary }, root.id);
|
|
51
|
-
}}
|
|
52
|
-
/>
|
|
53
|
-
<Popover>
|
|
54
|
-
<div
|
|
55
|
-
class="menu-item"
|
|
56
|
-
onclick={() =>
|
|
57
|
-
fetchAPI('DELETE', 'tasks/:id', {}, root.id).then(() => {
|
|
58
|
-
tasks.splice(tasks.indexOf(root), 1);
|
|
59
|
-
})}
|
|
60
|
-
>
|
|
61
|
-
<Icon i="trash" /> Delete
|
|
62
|
-
</div>
|
|
63
|
-
{#if page.data.session?.user.preferences.debug}
|
|
64
|
-
<div class="menu-item" onclick={() => copy('text/plain', root.id)}>
|
|
65
|
-
<Icon i="hashtag" --size="14px" /> Copy ID
|
|
66
|
-
</div>
|
|
67
|
-
{/if}
|
|
68
|
-
</Popover>
|
|
69
|
-
</div>
|
|
70
|
-
{#each tasks.filter(task => task.parentId == root.id) as child}
|
|
71
|
-
{@render task_tree(child)}
|
|
72
|
-
{/each}
|
|
73
|
-
{/snippet}
|
|
27
|
+
const rootPending = $derived(tasks.filter(task => !task.parentId && !task.completed));
|
|
28
|
+
const rootCompleted = $derived(tasks.filter(task => !task.parentId && task.completed));
|
|
29
|
+
</script>
|
|
74
30
|
|
|
75
31
|
<div class="task-list">
|
|
76
32
|
<div class="task-list-header">
|
|
@@ -105,7 +61,32 @@
|
|
|
105
61
|
.join('\n')
|
|
106
62
|
)}
|
|
107
63
|
>
|
|
108
|
-
<Icon i="file-
|
|
64
|
+
<Icon i="regular/file-export" /> Export
|
|
65
|
+
</div>
|
|
66
|
+
{#if tasks.some(t => !t.completed)}
|
|
67
|
+
<div
|
|
68
|
+
class="menu-item"
|
|
69
|
+
onclick={() => {
|
|
70
|
+
for (const task of tasks) task.completed = true;
|
|
71
|
+
fetchAPI('POST', 'task_lists/:id', { all_completed: true }, list.id);
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<Icon i="regular/circle-check" /> Complete All
|
|
75
|
+
</div>
|
|
76
|
+
{/if}
|
|
77
|
+
{#if tasks.some(t => t.completed)}
|
|
78
|
+
<div
|
|
79
|
+
class="menu-item"
|
|
80
|
+
onclick={() => {
|
|
81
|
+
for (const task of tasks) task.completed = false;
|
|
82
|
+
fetchAPI('POST', 'task_lists/:id', { all_completed: false }, list.id);
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<Icon i="regular/circle" /> Un-complete All
|
|
86
|
+
</div>
|
|
87
|
+
{/if}
|
|
88
|
+
<div class="menu-item" onclick={() => copy('text/plain', `${location.origin}/tasks/${list.id}`)}>
|
|
89
|
+
<Icon i="link-horizontal" /> Copy Link
|
|
109
90
|
</div>
|
|
110
91
|
{#if lists}
|
|
111
92
|
<div class="menu-item" onclick={() => open(`/tasks/${list.id}`)}>
|
|
@@ -131,14 +112,14 @@
|
|
|
131
112
|
</button>
|
|
132
113
|
</div>
|
|
133
114
|
<h4>Pending</h4>
|
|
134
|
-
{#each
|
|
135
|
-
|
|
115
|
+
{#each rootPending as task, i (task.id)}
|
|
116
|
+
<TaskTree bind:tasks bind:task={rootPending[i]} />
|
|
136
117
|
{:else}
|
|
137
118
|
<i class="subtle">No pending tasks.</i>
|
|
138
119
|
{/each}
|
|
139
120
|
<h4>Completed</h4>
|
|
140
|
-
{#each
|
|
141
|
-
|
|
121
|
+
{#each rootCompleted as task, i (task.id)}
|
|
122
|
+
<TaskTree bind:tasks bind:task={rootCompleted[i]} />
|
|
142
123
|
{:else}
|
|
143
124
|
<i class="subtle">No completed tasks.</i>
|
|
144
125
|
{/each}
|
|
@@ -150,17 +131,6 @@
|
|
|
150
131
|
border: none;
|
|
151
132
|
}
|
|
152
133
|
|
|
153
|
-
.task {
|
|
154
|
-
display: grid;
|
|
155
|
-
grid-template-columns: 1em 1fr 2em;
|
|
156
|
-
align-items: center;
|
|
157
|
-
gap: 1em;
|
|
158
|
-
|
|
159
|
-
.task {
|
|
160
|
-
padding-left: 1em;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
134
|
.task-list {
|
|
165
135
|
display: flex;
|
|
166
136
|
flex-direction: column;
|
|
@@ -182,12 +152,4 @@
|
|
|
182
152
|
padding: 0;
|
|
183
153
|
}
|
|
184
154
|
}
|
|
185
|
-
|
|
186
|
-
.task :global(.popover-toggle) {
|
|
187
|
-
visibility: hidden;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.task:hover :global(.popover-toggle) {
|
|
191
|
-
visibility: visible;
|
|
192
|
-
}
|
|
193
155
|
</style>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { fetchAPI } from '@axium/client/requests';
|
|
3
|
+
import type { Task } from '@axium/tasks/common';
|
|
4
|
+
import { Icon, Popover } from '@axium/client/components';
|
|
5
|
+
import { page } from '$app/state';
|
|
6
|
+
import { copy } from '@axium/client/clipboard';
|
|
7
|
+
import TaskTree from './TaskTree.svelte';
|
|
8
|
+
|
|
9
|
+
let { task = $bindable(), tasks = $bindable() }: { task: Task; tasks: Task[] } = $props();
|
|
10
|
+
|
|
11
|
+
const children = $derived(tasks.filter(task => task.parentId == task.id));
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div class="task">
|
|
15
|
+
<label for="task-completed#{task.id}" style:cursor="pointer">
|
|
16
|
+
<Icon i="regular/circle{task.completed ? '-check' : ''}" --size="20px" />
|
|
17
|
+
</label>
|
|
18
|
+
<input
|
|
19
|
+
type="checkbox"
|
|
20
|
+
name="completed"
|
|
21
|
+
bind:checked={task.completed}
|
|
22
|
+
id="task-completed#{task.id}"
|
|
23
|
+
style:display="none"
|
|
24
|
+
onchange={e => {
|
|
25
|
+
task.completed = e.currentTarget.checked;
|
|
26
|
+
fetchAPI('PATCH', 'tasks/:id', { completed: task.completed }, task.id);
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
<input
|
|
30
|
+
type="text"
|
|
31
|
+
name="summary"
|
|
32
|
+
class="editable-text"
|
|
33
|
+
bind:value={task.summary}
|
|
34
|
+
onchange={e => {
|
|
35
|
+
task.summary = e.currentTarget.value;
|
|
36
|
+
fetchAPI('PATCH', 'tasks/:id', { summary: task.summary }, task.id);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
<Popover>
|
|
40
|
+
<div
|
|
41
|
+
class="menu-item"
|
|
42
|
+
onclick={() =>
|
|
43
|
+
fetchAPI('DELETE', 'tasks/:id', {}, task.id).then(() => {
|
|
44
|
+
tasks.splice(tasks.indexOf(task), 1);
|
|
45
|
+
})}
|
|
46
|
+
>
|
|
47
|
+
<Icon i="trash" /> Delete
|
|
48
|
+
</div>
|
|
49
|
+
{#if page.data.session?.user.preferences.debug}
|
|
50
|
+
<div class="menu-item" onclick={() => copy('text/plain', task.id)}>
|
|
51
|
+
<Icon i="hashtag" --size="14px" /> Copy ID
|
|
52
|
+
</div>
|
|
53
|
+
{/if}
|
|
54
|
+
</Popover>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
{#each children as task, i (task.id)}
|
|
58
|
+
<TaskTree bind:tasks bind:task={children[i]} />
|
|
59
|
+
{/each}
|
|
60
|
+
|
|
61
|
+
<style>
|
|
62
|
+
.editable-text {
|
|
63
|
+
background: none;
|
|
64
|
+
border: none;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.task {
|
|
68
|
+
display: grid;
|
|
69
|
+
grid-template-columns: 1em 1fr 2em;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 1em;
|
|
72
|
+
|
|
73
|
+
.task {
|
|
74
|
+
padding-left: 1em;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.task :global(.popover-toggle) {
|
|
79
|
+
visibility: hidden;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.task:hover :global(.popover-toggle) {
|
|
83
|
+
visibility: visible;
|
|
84
|
+
}
|
|
85
|
+
</style>
|