@axium/tasks 0.1.10 → 0.2.1

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>, {}];
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
+ }
108
+ return {};
109
+ },
94
110
  async DELETE(event) {
95
111
  const id = event.params.id;
96
112
  await checkAuthForItem(event, 'task_lists', id, Permission.Manage);
@@ -24,51 +24,52 @@
24
24
  }
25
25
  </script>
26
26
 
27
- {#snippet task_tree(root: Task)}
27
+ {#snippet task_tree(task: Task)}
28
28
  <div class="task">
29
- <label for="task-completed#{root.id}" style:cursor="pointer">
30
- <Icon i="regular/circle{root.completed ? '-check' : ''}" --size="20px" />
29
+ <label for="task-completed#{task.id}" style:cursor="pointer">
30
+ <Icon i="regular/circle{task.completed ? '-check' : ''}" --size="20px" />
31
31
  </label>
32
32
  <input
33
33
  type="checkbox"
34
34
  name="completed"
35
- bind:checked={root.completed}
36
- id="task-completed#{root.id}"
35
+ bind:checked={task.completed}
36
+ id="task-completed#{task.id}"
37
37
  style:display="none"
38
38
  onchange={e => {
39
- root.completed = e.currentTarget.checked;
40
- fetchAPI('PATCH', 'tasks/:id', { completed: root.completed }, root.id);
39
+ task.completed = e.currentTarget.checked;
40
+ fetchAPI('PATCH', 'tasks/:id', { completed: task.completed }, task.id);
41
41
  }}
42
42
  />
43
43
  <input
44
44
  type="text"
45
45
  name="summary"
46
46
  class="editable-text"
47
- bind:value={root.summary}
47
+ bind:value={task.summary}
48
48
  onchange={e => {
49
- root.summary = e.currentTarget.value;
50
- fetchAPI('PATCH', 'tasks/:id', { summary: root.summary }, root.id);
49
+ task.summary = e.currentTarget.value;
50
+ fetchAPI('PATCH', 'tasks/:id', { summary: task.summary }, task.id);
51
51
  }}
52
52
  />
53
53
  <Popover>
54
54
  <div
55
55
  class="menu-item"
56
56
  onclick={() =>
57
- fetchAPI('DELETE', 'tasks/:id', {}, root.id).then(() => {
58
- tasks.splice(tasks.indexOf(root), 1);
57
+ fetchAPI('DELETE', 'tasks/:id', {}, task.id).then(() => {
58
+ tasks.splice(tasks.indexOf(task), 1);
59
59
  })}
60
60
  >
61
61
  <Icon i="trash" /> Delete
62
62
  </div>
63
63
  {#if page.data.session?.user.preferences.debug}
64
- <div class="menu-item" onclick={() => copy('text/plain', root.id)}>
64
+ <div class="menu-item" onclick={() => copy('text/plain', task.id)}>
65
65
  <Icon i="hashtag" --size="14px" /> Copy ID
66
66
  </div>
67
67
  {/if}
68
68
  </Popover>
69
69
  </div>
70
- {#each tasks.filter(task => task.parentId == root.id) as child}
71
- {@render task_tree(child)}
70
+
71
+ {#each tasks.filter(task => task.parentId == task.id) as task (task.id)}
72
+ {@render task_tree(task)}
72
73
  {/each}
73
74
  {/snippet}
74
75
 
@@ -107,6 +108,28 @@
107
108
  >
108
109
  <Icon i="regular/file-export" /> Export
109
110
  </div>
111
+ {#if tasks.some(t => !t.completed)}
112
+ <div
113
+ class="menu-item"
114
+ onclick={() => {
115
+ for (const task of tasks) task.completed = true;
116
+ fetchAPI('POST', 'task_lists/:id', { all_completed: true }, list.id);
117
+ }}
118
+ >
119
+ <Icon i="regular/circle-check" /> Complete All
120
+ </div>
121
+ {/if}
122
+ {#if tasks.some(t => t.completed)}
123
+ <div
124
+ class="menu-item"
125
+ onclick={() => {
126
+ for (const task of tasks) task.completed = false;
127
+ fetchAPI('POST', 'task_lists/:id', { all_completed: false }, list.id);
128
+ }}
129
+ >
130
+ <Icon i="regular/circle" /> Un-complete All
131
+ </div>
132
+ {/if}
110
133
  <div class="menu-item" onclick={() => copy('text/plain', `${location.origin}/tasks/${list.id}`)}>
111
134
  <Icon i="link-horizontal" /> Copy Link
112
135
  </div>
@@ -134,13 +157,13 @@
134
157
  </button>
135
158
  </div>
136
159
  <h4>Pending</h4>
137
- {#each tasks.filter(task => !task.parentId && !task.completed) as task}
160
+ {#each tasks.filter(task => !task.parentId && !task.completed) as task (task.id)}
138
161
  {@render task_tree(task)}
139
162
  {:else}
140
163
  <i class="subtle">No pending tasks.</i>
141
164
  {/each}
142
165
  <h4>Completed</h4>
143
- {#each tasks.filter(task => !task.parentId && task.completed) as task}
166
+ {#each tasks.filter(task => !task.parentId && task.completed) as task (task.id)}
144
167
  {@render task_tree(task)}
145
168
  {:else}
146
169
  <i class="subtle">No completed tasks.</i>
@@ -164,6 +187,14 @@
164
187
  }
165
188
  }
166
189
 
190
+ .task :global(.popover-toggle) {
191
+ visibility: hidden;
192
+ }
193
+
194
+ .task:hover :global(.popover-toggle) {
195
+ visibility: visible;
196
+ }
197
+
167
198
  .task-list {
168
199
  display: flex;
169
200
  flex-direction: column;
@@ -185,12 +216,4 @@
185
216
  padding: 0;
186
217
  }
187
218
  }
188
-
189
- .task :global(.popover-toggle) {
190
- visibility: hidden;
191
- }
192
-
193
- .task:hover :global(.popover-toggle) {
194
- visibility: visible;
195
- }
196
219
  </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.1",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "Tasks for Axium",
6
6
  "funding": {