Skip to content

Commit 764b837

Browse files
committed
refactor: replace notify with useNotification for error/success handling in composables
1 parent 633fc7d commit 764b837

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

ui/app/composables/useConditions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const throwInstead = ref(false);
4949
/**
5050
* Notification composable for showing success/error messages.
5151
*/
52-
const notify = useNotification();
5352

5453
/**
5554
* Sorts conditions by priority (descending - higher number first), then name (A-Z).
@@ -102,7 +101,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
102101
const handleError = (error: unknown): void => {
103102
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
104103
lastError.value = message;
105-
notify.error(message);
104+
useNotification().error(message);
106105
};
107106

108107
/**
@@ -212,7 +211,7 @@ const createCondition = async (
212211
const created = await parse_api_response<Condition>(json);
213212

214213
updateConditions(created);
215-
notify.success('Condition created.');
214+
useNotification().success('Condition created.');
216215
lastError.value = null;
217216

218217
if (callback) {
@@ -263,7 +262,7 @@ const updateCondition = async (
263262
const updated = await parse_api_response<Condition>(json);
264263

265264
updateConditions(updated);
266-
notify.success(`Condition '${updated.name}' updated.`);
265+
useNotification().success(`Condition '${updated.name}' updated.`);
267266
lastError.value = null;
268267

269268
if (callback) {
@@ -314,7 +313,7 @@ const patchCondition = async (
314313
const updated = await parse_api_response<Condition>(json);
315314

316315
updateConditions(updated);
317-
notify.success(`Condition '${updated.name}' updated.`);
316+
useNotification().success(`Condition '${updated.name}' updated.`);
318317
lastError.value = null;
319318

320319
if (callback) {
@@ -352,7 +351,7 @@ const deleteCondition = async (
352351
await ensureSuccess(response);
353352

354353
removeCondition(id);
355-
notify.success('Condition deleted.');
354+
useNotification().success('Condition deleted.');
356355
lastError.value = null;
357356

358357
if (callback) {

ui/app/composables/usePresets.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const throwInstead = ref(false);
3939
/**
4040
* Notification composable for showing success/error messages.
4141
*/
42-
const notify = useNotification();
4342

4443
/**
4544
* Sorts presets by priority (descending), then name (A-Z).
@@ -92,7 +91,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
9291
const handleError = (error: unknown): void => {
9392
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
9493
lastError.value = message;
95-
notify.error(message);
94+
useNotification().error(message);
9695
};
9796

9897
/**
@@ -199,7 +198,7 @@ const createPreset = async (
199198
const created = await parse_api_response<Preset>(json);
200199

201200
updatePresets(created);
202-
notify.success('Preset created.');
201+
useNotification().success('Preset created.');
203202
lastError.value = null;
204203

205204
if (callback) {
@@ -254,7 +253,7 @@ const updatePreset = async (
254253
const updated = await parse_api_response<Preset>(json);
255254

256255
updatePresets(updated);
257-
notify.success(`Preset '${updated.name}' updated.`);
256+
useNotification().success(`Preset '${updated.name}' updated.`);
258257
lastError.value = null;
259258

260259
if (callback) {
@@ -309,7 +308,7 @@ const patchPreset = async (
309308
const updated = await parse_api_response<Preset>(json);
310309

311310
updatePresets(updated);
312-
notify.success(`Preset '${updated.name}' updated.`);
311+
useNotification().success(`Preset '${updated.name}' updated.`);
313312
lastError.value = null;
314313

315314
if (callback) {
@@ -347,7 +346,7 @@ const deletePreset = async (
347346
await ensureSuccess(response);
348347

349348
removePreset(id);
350-
notify.success('Preset deleted.');
349+
useNotification().success('Preset deleted.');
351350
lastError.value = null;
352351

353352
if (callback) {

ui/app/composables/useTaskDefinitions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const throwInstead = ref(false);
4141
/**
4242
* Notification composable for showing success/error messages.
4343
*/
44-
const notify = useNotification();
4544

4645
/**
4746
* Sorts task definition summaries by priority (ascending), then name (A-Z).
@@ -83,7 +82,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
8382
const handleError = (error: unknown): void => {
8483
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
8584
lastError.value = message;
86-
notify.error(message);
85+
useNotification().error(message);
8786
};
8887

8988
/**
@@ -194,7 +193,7 @@ const createDefinition = async (
194193
updated_at: payload.updated_at,
195194
});
196195

197-
notify.success('Task definition created.');
196+
useNotification().success('Task definition created.');
198197
lastError.value = null;
199198
return payload;
200199
} catch (error) {
@@ -234,7 +233,7 @@ const updateDefinition = async (
234233
updated_at: payload.updated_at,
235234
});
236235

237-
notify.success('Task definition updated.');
236+
useNotification().success('Task definition updated.');
238237
lastError.value = null;
239238
return payload;
240239
} catch (error) {
@@ -255,7 +254,7 @@ const deleteDefinition = async (id: number): Promise<boolean> => {
255254
await ensureSuccess(response);
256255

257256
removeSummary(id);
258-
notify.success('Task definition deleted.');
257+
useNotification().success('Task definition deleted.');
259258
lastError.value = null;
260259
return true;
261260
} catch (error) {
@@ -295,7 +294,7 @@ const toggleEnabled = async (
295294
updated_at: payload.updated_at,
296295
});
297296

298-
notify.success(`Task definition ${enabled ? 'enabled' : 'disabled'}.`);
297+
useNotification().success(`Task definition ${enabled ? 'enabled' : 'disabled'}.`);
299298
lastError.value = null;
300299
return payload;
301300
} catch (error) {

ui/app/composables/useTasks.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const throwInstead = ref(false);
4848
/**
4949
* Notification composable for showing success/error messages.
5050
*/
51-
const notify = useNotification();
5251

5352
/**
5453
* Sorts tasks by name (A-Z).
@@ -95,7 +94,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
9594
const handleError = (error: unknown): void => {
9695
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
9796
lastError.value = message;
98-
notify.error(message);
97+
useNotification().error(message);
9998
};
10099

101100
/**
@@ -202,7 +201,7 @@ const createTask = async (
202201
const created = await parse_api_response<Task | Array<Task>>(json);
203202

204203
if (Array.isArray(created)) {
205-
notify.success(`${created.length} tasks created.`);
204+
useNotification().success(`${created.length} tasks created.`);
206205
created.forEach((t) => updateTasksList(t));
207206
lastError.value = null;
208207

@@ -214,7 +213,7 @@ const createTask = async (
214213
}
215214

216215
updateTasksList(created);
217-
notify.success('Task created.');
216+
useNotification().success('Task created.');
218217
lastError.value = null;
219218

220219
if (callback) {
@@ -264,7 +263,7 @@ const updateTask = async (
264263
const updated = await parse_api_response<Task>(json);
265264

266265
updateTasksList(updated);
267-
notify.success(`Task '${updated.name}' updated.`);
266+
useNotification().success(`Task '${updated.name}' updated.`);
268267
lastError.value = null;
269268

270269
if (callback) {
@@ -311,7 +310,7 @@ const patchTask = async (
311310
const updated = await parse_api_response<Task>(json);
312311

313312
updateTasksList(updated);
314-
notify.success(`Task '${updated.name}' updated.`);
313+
useNotification().success(`Task '${updated.name}' updated.`);
315314
lastError.value = null;
316315

317316
if (callback) {
@@ -349,7 +348,7 @@ const deleteTask = async (
349348
await ensureSuccess(response);
350349

351350
removeTask(id);
352-
notify.success('Task deleted.');
351+
useNotification().success('Task deleted.');
353352
lastError.value = null;
354353

355354
if (callback) {
@@ -408,7 +407,7 @@ const markTaskItems = async (id: number): Promise<string | null> => {
408407
const json = await response.json();
409408
const message = json.message || 'All items marked as downloaded.';
410409

411-
notify.success(message);
410+
useNotification().success(message);
412411
lastError.value = null;
413412
return message;
414413
} catch (error) {
@@ -431,7 +430,7 @@ const unmarkTaskItems = async (id: number): Promise<string | null> => {
431430
const json = await response.json();
432431
const message = json.message || 'All items removed from archive.';
433432

434-
notify.success(message);
433+
useNotification().success(message);
435434
lastError.value = null;
436435
return message;
437436
} catch (error) {
@@ -454,7 +453,7 @@ const generateTaskMetadata = async (id: number): Promise<TaskMetadataResponse |
454453
const json = await response.json();
455454
const metadata = await parse_api_response<TaskMetadataResponse>(json);
456455

457-
notify.success('Metadata generation completed.');
456+
useNotification().success('Metadata generation completed.');
458457
lastError.value = null;
459458
return metadata;
460459
} catch (error) {

ui/tests/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ globalThis.requestAnimationFrame = window.requestAnimationFrame
1717
globalThis.cancelAnimationFrame = window.cancelAnimationFrame
1818
globalThis.localStorage = window.localStorage
1919
globalThis.sessionStorage = window.sessionStorage
20+
globalThis.Storage = window.Storage
2021

2122
if (!globalThis.crypto) {
2223
globalThis.crypto = window.crypto

0 commit comments

Comments
 (0)