Implement simple routing for TaskPanel

This commit is contained in:
Standa Lukeš 2020-09-29 14:37:54 +00:00
parent 4e1db0168b
commit f4601a782b
2 changed files with 15 additions and 8 deletions

View file

@ -15,8 +15,9 @@ import type { detach } from "svelte/internal";
// react to hash changes
let hash = window.location.hash.substr(1);
window.onhashchange = () => {
hash = window.location.hash.substr(1);
hash = window.location.hash.substr(1);
}
$: selectedTaskId = (/^task\/([^\/]*)/.exec(hash) || [null, null])[1]
</script>
<style>
@ -34,10 +35,10 @@ import type { detach } from "svelte/internal";
</TasksLoader>
{:else}
<TasksLoader promise={tasksPromise} let:data={t}>
<TaskPanel bind:this={taskPanel} />
<TaskPanel tasks={t} bind:this={taskPanel} {selectedTaskId} />
<div style="height: 100%">
<Graph tasks={t}
on:selectTask={e => taskPanel.select(e.detail)}
on:selectTask={e => location.hash=`#task/${e.detail.id}`}
on:preSelectTask={e => taskPanel.preSelect(e.detail)}
on:unPreSelectTask={e => taskPanel.unPreselect(e.detail)} />
</div>

View file

@ -4,8 +4,9 @@
import type { TasksFile, TaskDescriptor } from "./task-loader";
import TaskDisplay from "./TaskDisplay.svelte";
// export let tasks: TasksFile;
export let tasks: TasksFile;
let selectedTask: TaskDescriptor | null = null
export let selectedTaskId: string | null = null
let heightClass: "collapsed" | "full" | "preview" = "collapsed"
@ -24,12 +25,17 @@ import TaskDisplay from "./TaskDisplay.svelte";
}, 10);
}
export function select(task: TaskDescriptor) {
selectedTask = task
heightClass = "full"
$: {
if (selectedTaskId) {
heightClass = "full"
selectedTask = tasks.tasks.find(t => t.id == selectedTaskId) ?? null
} else {
heightClass = "collapsed"
}
}
function close() {
location.hash = ""
heightClass = "collapsed"
window.setTimeout(() => window.scrollTo({
top: 0,
@ -81,7 +87,7 @@ import TaskDisplay from "./TaskDisplay.svelte";
</style>
<div class="panel {heightClass}"
on:click={() => selectedTask && select(selectedTask)}>
on:click={() => location.hash = `#task/${selectedTask?.id}`}>
<TaskDisplay taskId={selectedTask?.id} />
<button type=button class="closeButton" on:click|stopPropagation={close}></button>
</div>