From 013f80512802e1907ed00ff5cadf55e32862abd8 Mon Sep 17 00:00:00 2001 From: Vasek Sraier Date: Fri, 23 Oct 2020 14:25:04 +0200 Subject: [PATCH] editor: reset state button and error messages --- frontend/src/Editor.svelte | 17 +++++++++++++---- frontend/src/tasks.ts | 13 ++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/frontend/src/Editor.svelte b/frontend/src/Editor.svelte index 78cc7d6..fa67471 100644 --- a/frontend/src/Editor.svelte +++ b/frontend/src/Editor.svelte @@ -4,7 +4,7 @@ import Graph from "./Graph.svelte"; import { nonNull, saveToLocalDisk } from "./helpers"; import type { TaskDescriptor, TasksFile } from "./tasks"; - import { saveTasks, getCategories, tasksToString } from "./tasks"; + import { resetTasks, saveTasks, getCategories, tasksToString } from "./tasks"; import TaskDisplay from "./TaskDisplay.svelte"; import TaskDetailEditor from "./TaskDetailEditor.svelte"; import { forceSimulation } from "./force-simulation"; @@ -64,7 +64,15 @@ } async function saveCurrentState() { - await saveTasks(tasks); + await saveTasks(tasks).catch((val) => { + alert(val); + }); + } + + async function resetCurrentState() { + await resetTasks().catch((val) => { + alert(val); + }); } // autosave ;) @@ -356,14 +364,15 @@

Toolbox

- +
+
+ on:click={() => removeTask(clicked[clicked.length - 1])}>Odstranit "{clicked[clicked.length - 1] ?? '???'}"
diff --git a/frontend/src/tasks.ts b/frontend/src/tasks.ts index ff30ab8..4a246ea 100644 --- a/frontend/src/tasks.ts +++ b/frontend/src/tasks.ts @@ -74,7 +74,18 @@ export async function saveTasks(tasks: TasksFile) { } } - await fetch("/tasks.json", options) + const result = await fetch("/tasks.json", options) + if (result.status != 200) throw `Failed to save tasks.json. ${result.status} ${result.statusText}` +} + +export async function resetTasks() { + // request options + const options = { + method: 'DELETE', + } + + const result = await fetch("/tasks.json", options) + if (result.status != 200) throw `Failed to reset tasks.json. ${result.status} ${result.statusText}` } export function createTaskMap(tasks: TasksFile): TaskMap {