From 2ab9a92a9d5ea192835229191c502a94d576a033 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Fri, 6 May 2022 19:02:16 +1000
Subject: Fix lack server querying when click-holding leaves

---
 src/App.vue | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 66ed577..c9d752d 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -231,13 +231,31 @@ export default defineComponent({
 				console.log('Ignored expand-to-view on active-root node');
 				return;
 			}
-			LayoutNode.hideUpward(layoutNode);
-			this.activeRoot = layoutNode;
-			tryLayout(this.activeRoot, this.tileAreaPos, this.tileAreaDims, this.lytOpts, {
-				allowCollapse: true,
-				chg: {type: 'expand', node: layoutNode, tolMap: this.tolMap},
-				layoutMap: this.layoutMap
-			});
+			// Function for expanding tile
+			let doExpansion = () => {
+				LayoutNode.hideUpward(layoutNode);
+				this.activeRoot = layoutNode;
+				tryLayout(this.activeRoot, this.tileAreaPos, this.tileAreaDims, this.lytOpts, {
+					allowCollapse: true,
+					chg: {type: 'expand', node: layoutNode, tolMap: this.tolMap},
+					layoutMap: this.layoutMap
+				});
+			};
+			// Check if data for node-to-expand exists, getting from server if needed
+			let tolNode = this.tolMap.get(layoutNode.name)!;
+			if (!this.tolMap.has(tolNode.children[0])){
+				return fetch('/data/node?name=' + encodeURIComponent(layoutNode.name))
+					.then(response => response.json())
+					.then(obj => {
+						Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap.set(key, obj[key])});
+						doExpansion();
+					})
+					.catch(error => {
+						console.log('ERROR loading tolnode data', error);
+					});
+			} else {
+				return new Promise((resolve, reject) => resolve(doExpansion()));
+			}
 		},
 		onNonleafClickHeld(layoutNode: LayoutNode){
 			if (layoutNode == this.activeRoot){
-- 
cgit v1.2.3

