Skip to content

Commit 8f23304

Browse files
committed
Fix Delete
1 parent 7d2ff21 commit 8f23304

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎src/lib/actions/form.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ export const enhance = (form: HTMLFormElement,{
33
}) => {
44

55
const handleSubmit = async (event: Event) => {
6+
67
event.preventDefault();
7-
8+
89
try {
10+
911
const body = new FormData(form);
12+
1013
const res = await fetch(form.action, {
1114
method: form.method,
1215
headers: {
1316
accept: "application/json"
1417
},
18+
1519
body
1620
});
1721

18-
if (res.ok) {
19-
result(res,form);
22+
23+
if (res) {
24+
result(res, form);
2025
} else {
2126
console.error("Fetch error:", await res.text());
2227
}

‎src/routes/index.svelte‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
};
3333
3434
const processUpdatedTodoResult = async (res: Response) => {
35+
3536
const updatedTodo = await res.json();
3637
todos = todos.map(t => {
3738
if (t.uid === updatedTodo.uid) return updatedTodo;
@@ -83,7 +84,9 @@
8384
{#each todos as todo}
8485
<TodoItem
8586
{todo}
87+
8688
processDeletedTodoResult={() => {
89+
8790
todos = todos.filter(t => t.uid !== todo.uid);
8891
}}
8992
{processUpdatedTodoResult}

0 commit comments

Comments
 (0)