]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/pages/DetailsPage.svelte
details: ignore missing computed postcode (#95)
[nominatim-ui.git] / src / pages / DetailsPage.svelte
index 5b8c1ce5e51d84c8cfa1eb265a023683464b3a72..7fb30b0406290946b0eacc4e4f543adcf2a6e2a9 100644 (file)
@@ -1,25 +1,25 @@
 <script>
-  import { onMount } from 'svelte';
   import { fetch_from_api, update_html_title } from '../lib/api_utils.js';
-  import { current_result_store } from '../lib/stores.js';
+  import { page } from '../lib/stores.js';
 
   import {
-    osmLink, detailsURL, wikipediaLink, coverageType, isAdminBoundary,
+    osmLink, wikipediaLink, coverageType, isAdminBoundary,
     formatAddressRank, formatKeywordToken
   } from '../lib/helpers.js';
+  import Header from '../components/Header.svelte';
   import MapIcon from '../components/MapIcon.svelte';
-  import DetailsIndex from '../components/DetailsIndex.svelte';
+  import SearchSectionDetails from '../components/SearchSectionDetails.svelte';
   import DetailsOneRow from '../components/DetailsOneRow.svelte';
+  import DetailsLink from '../components/DetailsLink.svelte';
   import Map from '../components/Map.svelte';
 
   let aPlace;
-  let errorResponse;
   let base_url = window.location.search;
+  let api_request_params;
+  let api_request_finished = false;
 
-  function loaddata() {
-    var search_params = new URLSearchParams(window.location.search);
-
-    var api_request_params = {
+  function loaddata(search_params) {
+    api_request_params = {
       place_id: search_params.get('place_id'),
       osmtype: search_params.get('osmtype'),
       osmid: search_params.get('osmid'),
@@ -31,6 +31,7 @@
       polygon_geojson: 1,
       format: 'json'
     };
+    api_request_finished = false;
 
     if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid)) {
 
       }
 
       fetch_from_api('details', api_request_params, function (data) {
-        if (data.error) {
-          errorResponse = data;
-          current_result_store.set(undefined);
-        } else {
-          aPlace = data;
-          errorResponse = undefined;
-          current_result_store.set(data);
-        }
+        window.scrollTo(0, 0);
+        api_request_finished = true;
+        aPlace = (data && !data.error) ? data : undefined;
       });
     } else {
       aPlace = undefined;
     }
   }
-  onMount(loaddata);
 
+  $: {
+    let pageinfo = $page;
+    if (pageinfo.tab === 'details') {
+      loaddata(pageinfo.params);
+    }
+  }
 </script>
 
-{#if errorResponse}
-  {errorResponse.error.message}
-{/if}
-{#if aPlace}
-  <div class="container">
+<Header>
+  <SearchSectionDetails api_request_params={api_request_params}/>
+</Header>
+
+<div class="container">
+  {#if aPlace}
     <div class="row">
       <div class="col-sm-10">
         <h1>
           {aPlace.localname}
-          <small><a href="{detailsURL(aPlace)}">link to this page</a></small>
+          <small><DetailsLink feature={aPlace}>link to this page</DetailsLink></small>
         </h1>
       </div>
       <div class="col-sm-2 text-right">
             {/if}
             <tr>
               <td>Computed Postcode</td>
-              <td>{aPlace.calculated_postcode}</td>
+              <td>{aPlace.calculated_postcode || ''}</td>
             </tr>
             <tr>
               <td>Address Tags</td>
       </div>
       <div class="col-md-6">
         <div id="map-wrapper">
-          <Map/>
+          <Map current_result={aPlace} />
         </div>
       </div>
     </div>
         </table>
       </div>
     </div>
-  </div>
-{:else if (window.location.search === '')}
-  <DetailsIndex/>
-{:else}
-  No such place found.
-{/if}
+  {:else if (window.location.search !== '' && api_request_finished)}
+    No such place found.
+  {/if}
+</div>
 
 
 
     padding-left: 8px;
   }
 
-  h1 small a {
+  h1 small :global(a) {
     font-size: 0.5em;
     white-space: nowrap;
   }
     height:300px;
     border: 1px solid #666;
   }
-</style>
\ No newline at end of file
+</style>