refactor: replace notify with useNotification for error/success handling in composables
This commit is contained in:
parent
633fc7d4d2
commit
764b837312
5 changed files with 25 additions and 28 deletions
|
|
@ -49,7 +49,6 @@ const throwInstead = ref(false);
|
|||
/**
|
||||
* Notification composable for showing success/error messages.
|
||||
*/
|
||||
const notify = useNotification();
|
||||
|
||||
/**
|
||||
* Sorts conditions by priority (descending - higher number first), then name (A-Z).
|
||||
|
|
@ -102,7 +101,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
|
|||
const handleError = (error: unknown): void => {
|
||||
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
|
||||
lastError.value = message;
|
||||
notify.error(message);
|
||||
useNotification().error(message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -212,7 +211,7 @@ const createCondition = async (
|
|||
const created = await parse_api_response<Condition>(json);
|
||||
|
||||
updateConditions(created);
|
||||
notify.success('Condition created.');
|
||||
useNotification().success('Condition created.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -263,7 +262,7 @@ const updateCondition = async (
|
|||
const updated = await parse_api_response<Condition>(json);
|
||||
|
||||
updateConditions(updated);
|
||||
notify.success(`Condition '${updated.name}' updated.`);
|
||||
useNotification().success(`Condition '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -314,7 +313,7 @@ const patchCondition = async (
|
|||
const updated = await parse_api_response<Condition>(json);
|
||||
|
||||
updateConditions(updated);
|
||||
notify.success(`Condition '${updated.name}' updated.`);
|
||||
useNotification().success(`Condition '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -352,7 +351,7 @@ const deleteCondition = async (
|
|||
await ensureSuccess(response);
|
||||
|
||||
removeCondition(id);
|
||||
notify.success('Condition deleted.');
|
||||
useNotification().success('Condition deleted.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ const throwInstead = ref(false);
|
|||
/**
|
||||
* Notification composable for showing success/error messages.
|
||||
*/
|
||||
const notify = useNotification();
|
||||
|
||||
/**
|
||||
* Sorts presets by priority (descending), then name (A-Z).
|
||||
|
|
@ -92,7 +91,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
|
|||
const handleError = (error: unknown): void => {
|
||||
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
|
||||
lastError.value = message;
|
||||
notify.error(message);
|
||||
useNotification().error(message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -199,7 +198,7 @@ const createPreset = async (
|
|||
const created = await parse_api_response<Preset>(json);
|
||||
|
||||
updatePresets(created);
|
||||
notify.success('Preset created.');
|
||||
useNotification().success('Preset created.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -254,7 +253,7 @@ const updatePreset = async (
|
|||
const updated = await parse_api_response<Preset>(json);
|
||||
|
||||
updatePresets(updated);
|
||||
notify.success(`Preset '${updated.name}' updated.`);
|
||||
useNotification().success(`Preset '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -309,7 +308,7 @@ const patchPreset = async (
|
|||
const updated = await parse_api_response<Preset>(json);
|
||||
|
||||
updatePresets(updated);
|
||||
notify.success(`Preset '${updated.name}' updated.`);
|
||||
useNotification().success(`Preset '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -347,7 +346,7 @@ const deletePreset = async (
|
|||
await ensureSuccess(response);
|
||||
|
||||
removePreset(id);
|
||||
notify.success('Preset deleted.');
|
||||
useNotification().success('Preset deleted.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ const throwInstead = ref(false);
|
|||
/**
|
||||
* Notification composable for showing success/error messages.
|
||||
*/
|
||||
const notify = useNotification();
|
||||
|
||||
/**
|
||||
* Sorts task definition summaries by priority (ascending), then name (A-Z).
|
||||
|
|
@ -83,7 +82,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
|
|||
const handleError = (error: unknown): void => {
|
||||
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
|
||||
lastError.value = message;
|
||||
notify.error(message);
|
||||
useNotification().error(message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -194,7 +193,7 @@ const createDefinition = async (
|
|||
updated_at: payload.updated_at,
|
||||
});
|
||||
|
||||
notify.success('Task definition created.');
|
||||
useNotification().success('Task definition created.');
|
||||
lastError.value = null;
|
||||
return payload;
|
||||
} catch (error) {
|
||||
|
|
@ -234,7 +233,7 @@ const updateDefinition = async (
|
|||
updated_at: payload.updated_at,
|
||||
});
|
||||
|
||||
notify.success('Task definition updated.');
|
||||
useNotification().success('Task definition updated.');
|
||||
lastError.value = null;
|
||||
return payload;
|
||||
} catch (error) {
|
||||
|
|
@ -255,7 +254,7 @@ const deleteDefinition = async (id: number): Promise<boolean> => {
|
|||
await ensureSuccess(response);
|
||||
|
||||
removeSummary(id);
|
||||
notify.success('Task definition deleted.');
|
||||
useNotification().success('Task definition deleted.');
|
||||
lastError.value = null;
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
|
@ -295,7 +294,7 @@ const toggleEnabled = async (
|
|||
updated_at: payload.updated_at,
|
||||
});
|
||||
|
||||
notify.success(`Task definition ${enabled ? 'enabled' : 'disabled'}.`);
|
||||
useNotification().success(`Task definition ${enabled ? 'enabled' : 'disabled'}.`);
|
||||
lastError.value = null;
|
||||
return payload;
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ const throwInstead = ref(false);
|
|||
/**
|
||||
* Notification composable for showing success/error messages.
|
||||
*/
|
||||
const notify = useNotification();
|
||||
|
||||
/**
|
||||
* Sorts tasks by name (A-Z).
|
||||
|
|
@ -95,7 +94,7 @@ const ensureSuccess = async (response: Response): Promise<void> => {
|
|||
const handleError = (error: unknown): void => {
|
||||
const message = error instanceof Error ? error.message : 'Unexpected error occurred.';
|
||||
lastError.value = message;
|
||||
notify.error(message);
|
||||
useNotification().error(message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -202,7 +201,7 @@ const createTask = async (
|
|||
const created = await parse_api_response<Task | Array<Task>>(json);
|
||||
|
||||
if (Array.isArray(created)) {
|
||||
notify.success(`${created.length} tasks created.`);
|
||||
useNotification().success(`${created.length} tasks created.`);
|
||||
created.forEach((t) => updateTasksList(t));
|
||||
lastError.value = null;
|
||||
|
||||
|
|
@ -214,7 +213,7 @@ const createTask = async (
|
|||
}
|
||||
|
||||
updateTasksList(created);
|
||||
notify.success('Task created.');
|
||||
useNotification().success('Task created.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -264,7 +263,7 @@ const updateTask = async (
|
|||
const updated = await parse_api_response<Task>(json);
|
||||
|
||||
updateTasksList(updated);
|
||||
notify.success(`Task '${updated.name}' updated.`);
|
||||
useNotification().success(`Task '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -311,7 +310,7 @@ const patchTask = async (
|
|||
const updated = await parse_api_response<Task>(json);
|
||||
|
||||
updateTasksList(updated);
|
||||
notify.success(`Task '${updated.name}' updated.`);
|
||||
useNotification().success(`Task '${updated.name}' updated.`);
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -349,7 +348,7 @@ const deleteTask = async (
|
|||
await ensureSuccess(response);
|
||||
|
||||
removeTask(id);
|
||||
notify.success('Task deleted.');
|
||||
useNotification().success('Task deleted.');
|
||||
lastError.value = null;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -408,7 +407,7 @@ const markTaskItems = async (id: number): Promise<string | null> => {
|
|||
const json = await response.json();
|
||||
const message = json.message || 'All items marked as downloaded.';
|
||||
|
||||
notify.success(message);
|
||||
useNotification().success(message);
|
||||
lastError.value = null;
|
||||
return message;
|
||||
} catch (error) {
|
||||
|
|
@ -431,7 +430,7 @@ const unmarkTaskItems = async (id: number): Promise<string | null> => {
|
|||
const json = await response.json();
|
||||
const message = json.message || 'All items removed from archive.';
|
||||
|
||||
notify.success(message);
|
||||
useNotification().success(message);
|
||||
lastError.value = null;
|
||||
return message;
|
||||
} catch (error) {
|
||||
|
|
@ -454,7 +453,7 @@ const generateTaskMetadata = async (id: number): Promise<TaskMetadataResponse |
|
|||
const json = await response.json();
|
||||
const metadata = await parse_api_response<TaskMetadataResponse>(json);
|
||||
|
||||
notify.success('Metadata generation completed.');
|
||||
useNotification().success('Metadata generation completed.');
|
||||
lastError.value = null;
|
||||
return metadata;
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ globalThis.requestAnimationFrame = window.requestAnimationFrame
|
|||
globalThis.cancelAnimationFrame = window.cancelAnimationFrame
|
||||
globalThis.localStorage = window.localStorage
|
||||
globalThis.sessionStorage = window.sessionStorage
|
||||
globalThis.Storage = window.Storage
|
||||
|
||||
if (!globalThis.crypto) {
|
||||
globalThis.crypto = window.crypto
|
||||
|
|
|
|||
Loading…
Reference in a new issue