Skip to content
Snippets Groups Projects
Commit e1c5f3a4 authored by Leonardo Christino's avatar Leonardo Christino
Browse files

feat(url): sync saveID as a URL query param

parent 1df930e3
No related branches found
No related tags found
No related merge requests found
Pipeline #129336 failed
import { useEffect } from 'react';
import { WebSocketHandler } from '../socket';
import Broker from '../socket/broker';
import { keyTypeI, subKeyTypeI } from '../socket/types';
import { useAppDispatch, useConfig } from '../store';
import { addSaveState, updateSaveStateList } from '../store/sessionSlice';
import { URLParams, setParam } from './url';
// export function wsGetState() {
// Broker.instance().subscribe((data) => dispatch(readInSchemaFromBackend(data)), 'schema_result');
......@@ -58,6 +54,7 @@ export function wsSelectState(saveStateId: string | undefined) {
body: { saveStateId: saveStateId }, //messageTypeGetSaveState
});
WebSocketHandler.instance().useSaveStateID(saveStateId);
setParam(URLParams.saveState, saveStateId);
}
export function wsCreateState(request: SaveStateI) {
......
import { includes } from 'lodash-es';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from './store';
import { DatabaseInfo, DatabaseStatus, SaveStateI, wsSelectState } from '../api/wsState';
import { DatabaseStatus, SaveStateI, wsSelectState } from '../api/wsState';
import { getParam, URLParams } from '../api/url';
/** Message format of the error message from the backend */
export type ErrorMessage = {
......@@ -42,6 +42,7 @@ export const sessionSlice = createSlice({
});
state.saveStates = newState;
state.currentSaveState = getParam(URLParams.saveState) || state.currentSaveState;
if (!state.currentSaveState || !(state.currentSaveState in state.saveStates)) {
if (Object.keys(state.saveStates).length > 0) {
state.currentSaveState = Object.keys(state.saveStates)[0];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment