5.3. Add view to URL params
Choose Loadings and reload the page: you're back on the dashboard. The selected loading doesn't have this problem. Open a row, reload, and the dialog is still there, because UI.init reads loading from the URL and a reaction writes it back. Let's do the same for the view:
init = () => {
const urlSearchParams = new URLSearchParams(window.location.search);
const view = urlSearchParams.get("view");
if (view === "loadings") {
this.view = "loadings";
}
const loadingId = urlSearchParams.get("loading");
// ...
reaction(() => this.view,
view => addQueryParam("view", view, "dashboard"));
reaction(() => this.selectedLoading, loading => addQueryParam("loading", loading?.id ?? "", ""));
};
When the app starts, we only check for loadings. Anything else means the dashboard, our default. A reaction runs its second function every time the value returned by the first one changes. addQueryParam is already in the file. It puts the value into the URL, or removes it when it equals the default, so the dashboard needs no parameter at all.
Now you can send someone a link straight to the table: http://localhost:5173/?view=loadings.
