From 2bdecbb571bc88b98ab097cc4f47632e9f141069 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 26 May 2024 14:25:38 +1200 Subject: [PATCH] add support for a back button in nomadnet page browser --- public/index.html | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/public/index.html b/public/index.html index 25e0260..4a563d7 100644 --- a/public/index.html +++ b/public/index.html @@ -548,6 +548,11 @@ +
{{ nodePagePath }}
@@ -627,6 +632,7 @@ nodePagePath: null, nodePageContent: null, nodePageProgress: 0, + nodePagePathHistory: [], isDownloadingNodeFile: false, nodeFilePath: null, @@ -1151,17 +1157,25 @@ // do nothing if failed to load messages } }, - async loadNodePage(destinationHash, pagePath) { + async loadNodePage(destinationHash, pagePath, addToHistory = true) { // get new sequence for this page load const seq = ++this.nodePageRequestSequence; + // get previous page path + const previousNodePagePath = this.nodePagePath; + // update ui this.isLoadingNodePage = true; this.nodePagePath = `${destinationHash}:${pagePath}`; this.nodePageContent = null; this.nodePageProgress = 0; + // add to previous page to history if we are not loading that previous page + if(addToHistory && previousNodePagePath != null){ + this.nodePagePathHistory.push(previousNodePagePath); + } + this.downloadNomadNetPage(destinationHash, pagePath, (pageContent) => { // do nothing if callback is for a previous request @@ -1206,6 +1220,18 @@ }); }, + async loadPreviousNodePage() { + + // get the previous path from history, or do nothing + const previousNodePagePath = this.nodePagePathHistory.pop(); + if(!previousNodePagePath){ + return; + } + + // load the page + this.onNodePageUrlClick(previousNodePagePath, false); + + }, parseNomadnetworkUrl: function(url) { // parse relative urls @@ -1244,7 +1270,7 @@ return null; }, - onNodePageUrlClick: function(url) { + onNodePageUrlClick: function(url, addToHistory = true) { // open http urls in new tab if(url.startsWith("http://") || url.startsWith("https://")){ @@ -1305,7 +1331,7 @@ }; // navigate to node page - this.loadNodePage(destinationHash, parsedUrl.path); + this.loadNodePage(destinationHash, parsedUrl.path, addToHistory); return; }