aboutsummaryrefslogtreecommitdiff
path: root/src/components/SearchModal.vue
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-06-27 14:26:34 +1000
committerTerry Truong <terry06890@gmail.com>2022-06-27 14:26:34 +1000
commit2b9cb003fbcf2a6aa2cc6b340a439e7e09c72aad (patch)
treec9ddedc074d11bdd8d434ed58579a08e9f3f68f8 /src/components/SearchModal.vue
parentca08089c004e9714753b5dcf8b60ce3c0902ae34 (diff)
Add getServerResponse()
Diffstat (limited to 'src/components/SearchModal.vue')
-rw-r--r--src/components/SearchModal.vue38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue
index 7d86a76..86712ef 100644
--- a/src/components/SearchModal.vue
+++ b/src/components/SearchModal.vue
@@ -40,6 +40,7 @@ import LogInIcon from './icon/LogInIcon.vue';
import InfoIcon from './icon/InfoIcon.vue';
import {TolNode, TolMap, UiOptions, SearchSugg, SearchSuggResponse} from '../lib';
import {LayoutNode, LayoutOptions} from '../layout';
+import {getServerResponse} from '../util';
export default defineComponent({
props: {
@@ -51,7 +52,7 @@ export default defineComponent({
return {
// For search-suggestion requests
lastSuggReqTime: 0, // Set when a search-suggestions request is initiated
- pendingSuggReqUrl: '', // Used by a search-suggestion requester to use the latest user input
+ pendingSuggReqParams: '', // Used by a search-suggestion requester to use the latest user input
pendingDelayedSuggReq: 0, // Set via setTimeout() for a non-initial search-suggestions request
// Search-suggestion data
searchSuggs: [] as SearchSugg[],
@@ -102,21 +103,16 @@ export default defineComponent({
this.focusedSuggIdx = null;
return;
}
- // Get URL to use for querying search-suggestions
- let url = new URL(window.location.href);
- url.pathname = '/data/search';
- url.search = '?name=' + encodeURIComponent(input.value);
- url.search += this.uiOpts.useReducedTree ? '&tree=reduced' : '';
- url.search += '&limit=' + this.uiOpts.searchSuggLimit;
+ // Get URL params to use for querying search-suggestions
+ let urlParams = 'name=' + encodeURIComponent(input.value);
+ urlParams += '&limit=' + this.uiOpts.searchSuggLimit;
+ urlParams += this.uiOpts.useReducedTree ? '&tree=reduced' : '';
// Query server, delaying/skipping if a request was recently sent
- this.pendingSuggReqUrl = url.toString();
+ this.pendingSuggReqParams = urlParams;
let doReq = async () => {
- let responseObj: SearchSuggResponse;
- try {
- let response = await fetch(this.pendingSuggReqUrl);
- responseObj = await response.json();
- } catch (error){
- console.log('Error with getting search suggestions from server: ' + error)
+ let responseObj: SearchSuggResponse =
+ await getServerResponse('/data/search', this.pendingSuggReqParams);
+ if (responseObj == null){
return;
}
this.searchSuggs = responseObj.suggs;
@@ -175,16 +171,10 @@ export default defineComponent({
return;
}
// Ask server for nodes in parent-chain, updates tolMap, then emits search event
- let url = new URL(window.location.href);
- url.pathname = '/data/chain';
- url.search = '?name=' + encodeURIComponent(tolNodeName);
- url.search += (this.uiOpts.useReducedTree ? '&tree=reduced' : '');
- let responseObj: {[x: string]: TolNode};
- try {
- let response = await fetch(url.toString());
- responseObj = await response.json();
- } catch (error){
- console.log('Error with getting tolnode chain: ' + error);
+ let urlParams = 'name=' + encodeURIComponent(tolNodeName);
+ urlParams += this.uiOpts.useReducedTree ? '&tree=reduced' : '';
+ let responseObj: {[x: string]: TolNode} = await getServerResponse('/data/chain', urlParams);
+ if (responseObj == null){
return;
}
let keys = Object.getOwnPropertyNames(responseObj);