@axium/tasks 0.1.10 → 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 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
@@ -11,3 +11,6 @@ export const TaskListInit = z.object({
11
11
  name: z.string().min(1).max(50),
12
12
  description: z.string().max(500).nullish(),
13
13
  });
14
+ export const TaskListUpdate = z.object({
15
+ all_completed: z.boolean().optional(),
16
+ });
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);
@@ -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
- {#snippet task_tree(root: Task)}
28
- <div class="task">
29
- <label for="task-completed#{root.id}" style:cursor="pointer">
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">
@@ -107,6 +63,28 @@
107
63
  >
108
64
  <Icon i="regular/file-export" /> Export
109
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}
110
88
  <div class="menu-item" onclick={() => copy('text/plain', `${location.origin}/tasks/${list.id}`)}>
111
89
  <Icon i="link-horizontal" /> Copy Link
112
90
  </div>
@@ -134,14 +112,14 @@
134
112
  </button>
135
113
  </div>
136
114
  <h4>Pending</h4>
137
- {#each tasks.filter(task => !task.parentId && !task.completed) as task}
138
- {@render task_tree(task)}
115
+ {#each rootPending as task, i (task.id)}
116
+ <TaskTree bind:tasks bind:task={rootPending[i]} />
139
117
  {:else}
140
118
  <i class="subtle">No pending tasks.</i>
141
119
  {/each}
142
120
  <h4>Completed</h4>
143
- {#each tasks.filter(task => !task.parentId && task.completed) as task}
144
- {@render task_tree(task)}
121
+ {#each rootCompleted as task, i (task.id)}
122
+ <TaskTree bind:tasks bind:task={rootCompleted[i]} />
145
123
  {:else}
146
124
  <i class="subtle">No completed tasks.</i>
147
125
  {/each}
@@ -153,17 +131,6 @@
153
131
  border: none;
154
132
  }
155
133
 
156
- .task {
157
- display: grid;
158
- grid-template-columns: 1em 1fr 2em;
159
- align-items: center;
160
- gap: 1em;
161
-
162
- .task {
163
- padding-left: 1em;
164
- }
165
- }
166
-
167
134
  .task-list {
168
135
  display: flex;
169
136
  flex-direction: column;
@@ -185,12 +152,4 @@
185
152
  padding: 0;
186
153
  }
187
154
  }
188
-
189
- .task :global(.popover-toggle) {
190
- visibility: hidden;
191
- }
192
-
193
- .task:hover :global(.popover-toggle) {
194
- visibility: visible;
195
- }
196
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>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/tasks",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "Tasks for Axium",
6
6
  "funding": {