Skip to content

Commit

Permalink
fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 20, 2024
1 parent 6fe39c5 commit 3e79ede
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/TaskModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
export let isOpen = false;
export let mode: 'add' | 'edit' = 'add';
export let sourceTask: TaskType | undefined = undefined;
export let onSave: (task: TaskType) => Promise<Response> | string | void;
export let onSave: (
task: TaskType,
) => Promise<Response | string | void> | string | void;
let task = '';
let cents = 500;
Expand Down Expand Up @@ -56,9 +58,9 @@
const dueDate = new Date(due);
const formattedDue = formatDue(dueDate);
const taskData = { task, due: formattedDue, cents } as TaskType;
const result = await onSave(taskData);
if (typeof result === 'string') {
error = result;
return;
Expand All @@ -69,7 +71,10 @@
return;
}
success = mode === 'edit' ? 'Task updated successfully' : 'Tasks added successfully';
success =
mode === 'edit'
? 'Task updated successfully'
: 'Tasks added successfully';
dispatch('close');
} catch (e) {
error = e instanceof Error ? e.message : 'Failed to save task';
Expand Down Expand Up @@ -126,7 +131,8 @@

<div class="buttons">
<button on:click={() => dispatch('close')}>Cancel</button>
<button on:click={onSubmit}>{mode === 'edit' ? 'Save' : 'Add'}</button>
<button on:click={onSubmit}>{mode === 'edit' ? 'Save' : 'Add'}</button
>
</div>
</div>
</div>
Expand Down

0 comments on commit 3e79ede

Please sign in to comment.