1 import { writable } from 'svelte/store';
3 export const map_store = writable();
4 export const results_store = writable();
5 export const last_api_request_url_store = writable();
6 export const error_store = writable();
7 export const page = writable();
10 * Update the global page state.
12 * When called without a parameter, then the current window.location is
13 * parsed and the page state is set accordingly. Otherwise the page state
14 * is set from the parameters. 'pagename' is the overall subpage (without
15 * .html extension). 'params' must be an URLSearchParams object and contain
16 * the requested query parameters. It may also be omitted completely for a
17 * link without query parameters.
19 const pagenames = ['search', 'reverse', 'details', 'deletable', 'polygons', 'about'];
21 export function refresh_page(pagename, params) {
22 if (typeof pagename === 'undefined') {
23 pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
25 if (!pagenames.includes(pagename)) pagename = 'search';
27 params = new URLSearchParams(window.location.search);
29 if (typeof params === 'undefined') {
30 params = new URLSearchParams();
33 let param_str = params.toString();
35 param_str = '?' + param_str;
37 let new_url = pagename + '.html' + param_str;
39 if (window.location.protocol.match(/^http/)) {
40 window.history.pushState([], '', new_url);
42 window.location.href = new_url;
46 page.set({ tab: pagename, params: params });
47 last_api_request_url_store.set(null);
48 error_store.set(null);