From 3d083c5584b3e0593639f4b89c67257797062fb0 Mon Sep 17 00:00:00 2001 From: Norman Fomferra Date: Thu, 28 Nov 2024 17:23:15 +0100 Subject: [PATCH] Fixes --- src/actions/dataActions.tsx | 85 ++++++++++--------------------------- src/connected/AppBar.tsx | 4 +- 2 files changed, 24 insertions(+), 65 deletions(-) diff --git a/src/actions/dataActions.tsx b/src/actions/dataActions.tsx index 5143d8b8..9e4ae453 100644 --- a/src/actions/dataActions.tsx +++ b/src/actions/dataActions.tsx @@ -848,7 +848,7 @@ export function _configureServers( //////////////////////////////////////////////////////////////////////////////// export function syncWithServer(store: Store, init: boolean = false) { - return (dispatch: Dispatch, getState: () => AppState) => { + return (dispatch: Dispatch) => { dispatch(updateServerInfo() as unknown as Action); dispatch(updateDatasets() as unknown as Action); dispatch(updateExpressionCapabilities() as unknown as Action); @@ -857,73 +857,34 @@ export function syncWithServer(store: Store, init: boolean = false) { const stateKey = appParams.get("stateKey"); if (stateKey && init) { - const serverUrl = selectedServerSelector(store.getState()).url; - api - .getViewerState( - serverUrl, - getState().userAuthState.accessToken, - stateKey, - ) - .then((stateResult) => { - if (typeof stateResult === "object") { - const persistedState = stateResult as PersistedState; - const { apiUrl } = persistedState as PersistedState; - if (apiUrl === serverUrl) { - dispatch( - applyPersistentState(persistedState) as unknown as Action, - ); - } else { - dispatch( - postMessage( - "warning", - "Failed to restore state, backend mismatch", - ), - ); - } - } else { - dispatch(postMessage("warning", stateResult)); - } - }); + dispatch(restorePersistedState(store, stateKey) as unknown as Action); } }; } -function newHostStore(store: Store): StoreApi & { - _initialState: AppState; - _prevState: AppState; -} { - return { - _initialState: store.getState(), - getInitialState(): AppState { - // noinspection JSPotentiallyInvalidUsageOfThis - return this._initialState; - }, - getState(): AppState { - return store.getState(); - }, - setState( - _state: - | AppState - | Partial - | ((state: AppState) => AppState | Partial), - _replace?: boolean, - ): void { - throw new Error( - "Changing the host state from contributions is not yet supported", - ); - }, - _prevState: store.getState(), - subscribe( - listener: (store: AppState, prevState: AppState) => void, - ): () => void { - return store.subscribe(() => { - const state = store.getState(); - if (state !== this._prevState) { - listener(state, this._prevState); - this._prevState = state; +function restorePersistedState(store: Store, stateKey: string) { + return (dispatch: Dispatch, getState: () => AppState) => { + const serverUrl = selectedServerSelector(store.getState()).url; + api + .getViewerState(serverUrl, getState().userAuthState.accessToken, stateKey) + .then((stateResult) => { + if (typeof stateResult === "object") { + const persistedState = stateResult as PersistedState; + const { apiUrl } = persistedState as PersistedState; + if (apiUrl === serverUrl) { + dispatch(applyPersistentState(persistedState) as unknown as Action); + } else { + dispatch( + postMessage( + "warning", + "Failed to restore state, backend mismatch", + ), + ); + } + } else { + dispatch(postMessage("warning", stateResult)); } }); - }, }; } diff --git a/src/connected/AppBar.tsx b/src/connected/AppBar.tsx index 2b525c69..ca3072a9 100644 --- a/src/connected/AppBar.tsx +++ b/src/connected/AppBar.tsx @@ -46,11 +46,9 @@ import { Config } from "@/config"; import { AppState } from "@/states/appState"; import { WithLocale } from "@/util/lang"; import { openDialog } from "@/actions/controlActions"; -import { updateResources } from "@/actions/dataActions"; +import { shareStatePermalink, updateResources } from "@/actions/dataActions"; import DevRefPage from "@/components/DevRefPage"; import ImprintPage from "@/components/ImprintPage"; -import { shareStatePermalink, updateResources } from "@/actions/dataActions"; -import MarkdownPage from "@/components/MarkdownPage"; import UserControl from "./UserControl"; interface AppBarProps extends WithLocale {