]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/lib/stores.js
when searching for OSM Url, show detail page result page
[nominatim-ui.git] / src / lib / stores.js
index 7ada7761489c0ddba2547c29f753f688cdc95f37..5e755c1eddfa9c36046e560b121356e81b67a257 100644 (file)
@@ -1,4 +1,5 @@
 import { writable } from 'svelte/store';
+import { identifyLinkInQuery } from './helpers.js';
 
 export const map_store = writable();
 export const results_store = writable();
@@ -16,16 +17,27 @@ export const page = writable();
  * the requested query parameters. It may also be omitted completely for a
  * link without query parameters.
  */
-const pagenames = ['search', 'reverse', 'details', 'deletable', 'polygons', 'about'];
+const default_pagename = Nominatim_Config.Reverse_Only ? 'reverse' : 'search';
+const pagenames = [
+  default_pagename,
+  'reverse',
+  'details',
+  'deletable',
+  'polygons',
+  'status',
+  'about'
+];
 
 export function refresh_page(pagename, params) {
   if (typeof pagename === 'undefined') {
     pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
 
-    if (!pagenames.includes(pagename)) pagename = 'search';
+    if (!pagenames.includes(pagename)) pagename = default_pagename;
 
     params = new URLSearchParams(window.location.search);
   } else {
+    if (!pagenames.includes(pagename)) pagename = default_pagename;
+
     if (typeof params === 'undefined') {
       params = new URLSearchParams();
     }
@@ -34,7 +46,23 @@ export function refresh_page(pagename, params) {
     if (param_str) {
       param_str = '?' + param_str;
     }
-    window.history.pushState([], '', pagename + '.html' + param_str);
+    let new_url = pagename + '.html' + param_str;
+
+    if (window.location.protocol.match(/^http/)) {
+      window.history.pushState([], '', new_url);
+    } else {
+      window.location.href = new_url;
+    }
+  }
+
+  if (pagename === 'search' && params.has('q')) {
+    const arrTypeAndId = identifyLinkInQuery(params.get('q'));
+    if (arrTypeAndId instanceof Array) {
+      pagename = 'details';
+      params = new URLSearchParams();
+      params.set('osmtype', arrTypeAndId[0]);
+      params.set('osmid', arrTypeAndId[1]);
+    }
   }
 
   page.set({ tab: pagename, params: params });