Skip to content

Commit

Permalink
fix: move roomKey to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-welker committed May 17, 2024
1 parent f3bfe75 commit c1a6e4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/lib/store/runtimeConfig/runtimeConfig.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const initialState: RuntimeConfigState = {
pluginVersion: '',
disconnectionMessage: '',
token: '',
roomKey: '',
roomData: {
clientId: '',
roomKey: '',
Expand Down Expand Up @@ -45,7 +46,7 @@ const runtimeConfigSlice = createSlice({
state.roomData = action.payload;
},
setCurrentRoomKey(state, action: PayloadAction<string>) {
state.roomData.roomKey = action.payload;
state.roomKey = action.payload;
},
setUserCode(state, action: PayloadAction<UserCode>) {
state.roomData.userCode = action.payload.userCode;
Expand All @@ -63,6 +64,7 @@ export interface RuntimeConfigState {
pluginVersion: string;
disconnectionMessage: string;
token: string;
roomKey: string;
roomData: RoomData;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/store/runtimeConfig/runtimeSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAppSelector } from '../hooks';

export const useWsIsConnected = () => useAppSelector((state) => state.runtimeConfig.websocket.isConnected);

export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomData.roomKey);
export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomKey);

export const useClientId = () => useAppSelector((state) => state.runtimeConfig.roomData.clientId);

Expand Down
8 changes: 5 additions & 3 deletions src/lib/utils/WebsocketProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => {
* @param value
*/
const sendSimpleMessage =
useCallback(
(type: string, value: boolean | number | string ) => {
sendMessage(type, { value });
};
},[sendMessage])

const addEventHandler = useCallback(
(eventType: string, key: string, callback: (data: Message) => void) => {
Expand Down Expand Up @@ -261,7 +262,7 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => {

clientRef.current = null;
};
}, [appConfig.apiPath, appConfig.gatewayAppPath, getRoomData, roomKey, serverIsRunningOnProcessorHardware, systemUuid, token, userCode, waitingToReconnect]);
}, [appConfig.apiPath, appConfig.gatewayAppPath, getRoomData, serverIsRunningOnProcessorHardware, systemUuid, token, userCode, waitingToReconnect]);

/**
* Send a status message to the server to get the current state of the room when the roomKey changes
Expand All @@ -270,7 +271,8 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => {
if (roomKey) {
sendMessage(`/room/${roomKey}/status`, null);
}
}, [roomKey, sendMessage]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [roomKey]);

//* RENDER **********************************************************/
return (
Expand Down

0 comments on commit c1a6e4e

Please sign in to comment.