Skip to content

Commit

Permalink
Update TaskAdd.svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 17, 2024
1 parent cac7be9 commit 4fbde6f
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/components/TaskAdd.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script lang="ts">
import { addTask, getMe } from '@taskratchet/sdk';
import { addTask, getMe, editTask } from '@taskratchet/sdk';
import { onMount, createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
import { formatDue } from '../lib/formatDue';
export let isOpen = false;
export let isEditing = false;
export let taskToCopy: TaskType;
export let isEditing = false;
export let taskToCopy: TaskType;
export let task = '';
export let cents = 500;
$: if (isOpen) {
// Only reset values if not copying a task
if (!task) {
task = '';
cents = 500;
}
// Only reset values if not copying a task
if (!task) {
task = '';
cents = 500;
}
}
let due = getDefaultDue();
let error = '';
Expand Down Expand Up @@ -74,17 +74,22 @@ export let taskToCopy: TaskType;
for (const line of lines) {
const dueDate = new Date(due);
const formattedDue = formatDue(dueDate);
const response = await addTask({ task: line, due: formattedDue, cents });
if (!response.ok) {
error = await response.text();
return;
const response = await addTask({
task: line,
due: formattedDue,
cents,
});
if (!response.ok) {
error = await response.text();
return;
}
}
error = '';
success = 'Tasks added successfully';
dispatch('tasksAdded');
} catch (e) {
error = e instanceof Error ? e.message : 'Failed to add task';
}
error = '';
success = 'Tasks added successfully';
dispatch('tasksAdded');
} catch (e) {
error = e instanceof Error ? e.message : 'Failed to add task';
}
}
</script>
Expand Down Expand Up @@ -137,7 +142,7 @@ export let taskToCopy: TaskType;

<div class="buttons">
<button on:click={() => (isOpen = false)}>Cancel</button>
<button on:click={onSubmit}>Add</button>
<button on:click={onSubmit}>{isEditing ? 'Save' : 'Add'}</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 4fbde6f

Please sign in to comment.