From af57e530f8c5a2cd8aa23948442fae7840b91f5d Mon Sep 17 00:00:00 2001 From: exyi Date: Wed, 30 Sep 2020 14:08:36 +0000 Subject: [PATCH] Display task status in TaskDisplay --- frontend/src/Graph.svelte | 15 ++------------ frontend/src/GraphNode.svelte | 16 +++++++++++++-- frontend/src/TaskDisplay.svelte | 34 ++++++++++++++++++++++++++++++- frontend/src/TasksLoader.svelte | 2 ++ frontend/src/ksp-task-grabber.ts | 12 +++++++---- frontend/src/task-status-cache.ts | 29 ++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 20 deletions(-) create mode 100644 frontend/src/task-status-cache.ts diff --git a/frontend/src/Graph.svelte b/frontend/src/Graph.svelte index bbeffc1..be08632 100644 --- a/frontend/src/Graph.svelte +++ b/frontend/src/Graph.svelte @@ -6,6 +6,7 @@ import type { TasksFile, TaskDescriptor } from "./task-loader"; import { createNodesAndEdges } from "./graph-types"; import { taskForce } from "./task-force"; + import { taskStatuses } from './task-status-cache' import { grabTaskStates, isLoggedIn } from "./ksp-task-grabber"; import type { TaskStatus } from "./ksp-task-grabber" @@ -20,7 +21,6 @@ let clientHeight: number; let clientWidth: number; let svgElement: SVGElement; - let taskStatuses = new Map(); // this prevents svelte from updating nodes and edges // when we update nodes and edges @@ -94,17 +94,6 @@ } - if (isLoggedIn()) { - const cachedTaskStatuses = localStorage.getItem("taskStatuses-cache") - if (cachedTaskStatuses) { - try { taskStatuses = new Map(JSON.parse(cachedTaskStatuses)) } catch(e) { console.warn(e) } - } - grabTaskStates(tasks.tasks.map(t => t.id)).then(t => { - taskStatuses = t - localStorage.setItem("taskStatuses-cache", JSON.stringify(Array.from(t.entries()))) - }) - } - // start simulation and center view on create onMount(() => { // set center of the SVG at (0,0) @@ -155,7 +144,7 @@ on:click={nodeClick(task.task)} on:hoveringChange={nodeHover(task.task)} on:positionChange={() => { tasks = tasks; }} - status={taskStatuses.get(task.id)} + status={$taskStatuses.get(task.id)} draggingEnabled={nodeDraggingEnabled} on:dblclick={nodeDoubleClick(task.task)} /> {/each} diff --git a/frontend/src/GraphNode.svelte b/frontend/src/GraphNode.svelte index 02c9723..e369393 100644 --- a/frontend/src/GraphNode.svelte +++ b/frontend/src/GraphNode.svelte @@ -83,11 +83,23 @@ fill: #69b3a2 } .submitted ellipse { - fill: red + fill: red; /* TODO */ + } + .solved ellipse { + fill: green; /* TODO */ } - + import { grabAssignment, grabSolution } from "./ksp-task-grabber"; + import type { TaskStatus } from "./ksp-task-grabber"; import { nonNull } from './helpers' import App from "./App.svelte"; +import { taskStatuses } from "./task-status-cache"; export let taskId: string | null | undefined export let showSolution: boolean = false @@ -9,11 +11,26 @@ import App from "./App.svelte"; taskId showSolution = false } + + let status: TaskStatus | undefined + $: if (taskId) status = $taskStatuses.get(taskId)
@@ -21,7 +38,22 @@ import App from "./App.svelte"; {#await grabAssignment(nonNull(taskId))} Načítám úlohu {:then task} - {@html task.titleHtml} +
+

{task.name}

+ +
+

+ {task.id} | {task.points} bodů + {#if status && status.submitted} + {#if nonNull(status).solved} + | Vyřešeno 🥳 + {:else} + | odevzdáno za {nonNull(status).points} bod{ "ů yyy"[nonNull(status).points] ?? "ů" } + {/if} + {/if} +

+
+
{@html task.description}
diff --git a/frontend/src/TasksLoader.svelte b/frontend/src/TasksLoader.svelte index 4d81661..18b2b75 100644 --- a/frontend/src/TasksLoader.svelte +++ b/frontend/src/TasksLoader.svelte @@ -1,5 +1,6 @@