From 8d8f56999771d48f8dcf124edf8dbab453781ea8 Mon Sep 17 00:00:00 2001
From: Vasek Sraier <git@vakabus.cz>
Date: Sat, 17 Oct 2020 21:38:22 +0200
Subject: [PATCH] grafik: close task dialog when clicking outside of it

---
 frontend/src/App.svelte       | 3 ++-
 frontend/src/Graph.svelte     | 5 +++++
 frontend/src/GraphNode.svelte | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index fb14b56..b2541f4 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -39,7 +39,8 @@
         <div style="height: 100%">
           <Graph
             tasks={t}
-            on:selectTask={(e) => { if (e.detail.type != "label") (location.hash = `#task/${e.detail.id}`)}}/>
+            on:selectTask={(e) => { if (e.detail.type != "label") (location.hash = `#task/${e.detail.id}`)}}
+            on:closeTask={() => {location.hash = '#'}} />
         </div>
       </TasksLoader>
     {/if}
diff --git a/frontend/src/Graph.svelte b/frontend/src/Graph.svelte
index 6d535b6..448a5e8 100644
--- a/frontend/src/Graph.svelte
+++ b/frontend/src/Graph.svelte
@@ -81,6 +81,10 @@ import TaskDetailEditor from "./TaskDetailEditor.svelte";
     d3.select(container).call(zoomer);
   }
 
+  function containerClickHandler(e: MouseEvent) {
+    eventDispatcher("closeTask");
+  }
+
   function groupSelectionHandler(e: MouseEvent) {
     // not enabled?
     if (!selectionToolEnabled) return;
@@ -271,6 +275,7 @@ import TaskDetailEditor from "./TaskDetailEditor.svelte";
   bind:this={container}
   bind:clientHeight
   bind:clientWidth
+  on:click={containerClickHandler}
   on:mousedown={groupSelectionHandler}
   on:contextmenu={(e) => {
     if (selectionToolEnabled) {
diff --git a/frontend/src/GraphNode.svelte b/frontend/src/GraphNode.svelte
index 58fc0bf..62056be 100644
--- a/frontend/src/GraphNode.svelte
+++ b/frontend/src/GraphNode.svelte
@@ -25,6 +25,7 @@
   }
 
   function click(e: MouseEvent) {
+    e.stopPropagation();
     eventDispatcher("click", e);
   }