Store the current form in the location hash.
[ustaxviewer.git] / src / main.tsx
1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
5
6 import { createSignal, createState } from 'solid-js';
7 import { Show, render } from 'solid-js/dom';
8 import { TaxReturn } from 'ustaxlib/core';
9
10 import App from './App';
11
12 declare const TAX_RETURN_PATH: string;
13
14 function TaxViewerLoader() {
15 const [ state, setState ] = createState({
16 // TODO - consider using dynamic import()
17 taxReturn: require(TAX_RETURN_PATH).default,
18 showForm: window.location.hash
19 });
20
21 const onFormChange = (formName: string) => {
22 window.location.hash = formName;
23 };
24
25 window.onhashchange = () => setState({ showForm: window.location.hash });
26
27 return (
28 <Show when={state.taxReturn !== undefined} fallback={<h1>Loading...</h1>}>
29 <App tr={state.taxReturn} showForm={state.showForm} onFormChange={onFormChange} />
30 </Show>
31 );
32 }
33
34 render(TaxViewerLoader, document.getElementById('root'));