Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Nov 28, 2024
1 parent ba4183d commit 3d083c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 65 deletions.
85 changes: 23 additions & 62 deletions src/actions/dataActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<AppState> & {
_initialState: AppState;
_prevState: AppState;
} {
return {
_initialState: store.getState(),
getInitialState(): AppState {
// noinspection JSPotentiallyInvalidUsageOfThis
return this._initialState;
},
getState(): AppState {
return store.getState();
},
setState(
_state:
| AppState
| Partial<AppState>
| ((state: AppState) => AppState | Partial<AppState>),
_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));
}
});
},
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/connected/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3d083c5

Please sign in to comment.