Skip to content

Commit

Permalink
fix: direct mutation of store bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanzyTHEbar committed Apr 12, 2023
1 parent a161b65 commit ad0c1d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions GUI/ETVR/src/store/camera/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ export const setCameraStatus = (camera: ICamera, status: CameraStatus) => {
)
}

export const setCameraWS = (camera: ICamera, ws: object) => {
setState(
produce((s) => {
s.cameras = s.cameras.filter((c: { address: string }) => c.address !== camera.address)
s.cameras.push({ ...camera, ws })
}),
)
}

export const setSelectedCamera = (camera: ICamera) => {
setState(
produce((s) => {
Expand Down
4 changes: 2 additions & 2 deletions GUI/ETVR/src/utils/hooks/websocket/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useWebSocket } from 'solidjs-use'
import { addNotification, ENotificationType } from '@hooks/notifications'
import { getGlobalNotificationsType } from '@store/app/settings/selectors'
import { CameraStatus, setCameraStatus } from '@store/camera/camera'
import { CameraStatus, setCameraStatus, setCameraWS } from '@store/camera/camera'
import { cameras } from '@store/camera/selectors'
import { isEmpty } from '@utils/index'
const PORT = 7856
Expand Down Expand Up @@ -32,7 +32,7 @@ export const generateWebsocketClients = () => {
pongTimeout: 1000,
},
})
camera.ws = { status, data, send, open, close }
setCameraWS(camera, { status, data, send, open, close })
return
}
})
Expand Down

0 comments on commit ad0c1d8

Please sign in to comment.