This lets you reload the page and stay on the same form.
interface Props {
tr: TaxReturn;
+ showForm?: string
+ onFormChange?: (formName: string) => void;
}
export default function App(props: Props) {
// version 3.0. The full text of the license can be found in LICENSE.txt.
// SPDX-License-Identifier: GPL-3.0-only
-import { createMemo, createState } from 'solid-js';
+import { createEffect, createMemo, createState } from 'solid-js';
import { For } from 'solid-js/dom';
import { Form, Person, TaxReturn } from 'ustaxlib/core';
interface Props {
tr: TaxReturn;
+ showForm?: string;
+ onFormChange?: (formName: string) => void;
+}
+
+function hashifyFormName(name: string): string {
+ return '#' + name.replace(/[^\w]+/g, '_');
}
export default function TaxReturnView(props: Props) {
const changeForm = e => {
setState({ form: props.tr.forms[e.target.value] });
+ if (props.onFormChange)
+ props.onFormChange(hashifyFormName(e.target.selectedOptions[0].textContent));
};
const formIndexToName = createMemo(() => {
return forms;
});
+ createEffect(() => {
+ if (props.showForm) {
+ for (let f of formIndexToName()) {
+ if (hashifyFormName(f[1] as string) === props.showForm) {
+ setState({ form: props.tr.forms[f[0]] });
+ }
+ }
+ }
+ });
+
const formSelector = (
<select onchange={changeForm}>
<For each={formIndexToName()}>
- {tuple => (<option value={tuple[0]}>{tuple[1]}</option>)}
+ {tuple => (<option value={tuple[0]} selected={state.form === props.tr.forms[tuple[0]]}>{tuple[1]}</option>)}
</For>
</select>
);
// version 3.0. The full text of the license can be found in LICENSE.txt.
// SPDX-License-Identifier: GPL-3.0-only
-import { createSignal } from 'solid-js';
+import { createSignal, createState } from 'solid-js';
import { Show, render } from 'solid-js/dom';
import { TaxReturn } from 'ustaxlib/core';
declare const TAX_RETURN_PATH: string;
function TaxViewerLoader() {
- const [ state, setState ] = createSignal(undefined as TaxReturn);
+ const [ state, setState ] = createState({
+ // TODO - consider using dynamic import()
+ taxReturn: require(TAX_RETURN_PATH).default,
+ showForm: window.location.hash
+ });
- // TODO - consider using dynamic import()
- setState(require(TAX_RETURN_PATH).default);
+ const onFormChange = (formName: string) => {
+ window.location.hash = formName;
+ };
+
+ window.onhashchange = () => setState({ showForm: window.location.hash });
return (
- <Show when={state() !== undefined} fallback={<h1>Loading...</h1>}>
- <App tr={state()} />
+ <Show when={state.taxReturn !== undefined} fallback={<h1>Loading...</h1>}>
+ <App tr={state.taxReturn} showForm={state.showForm} onFormChange={onFormChange} />
</Show>
);
}