Skip to content

Commit

Permalink
chore: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Aug 16, 2023
1 parent 82c5bfc commit 9a8d959
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
16 changes: 10 additions & 6 deletions apps/client/src/hooks/realtime/use-map-players.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ import type {
} from "types/map";
import useFetch from "lib/useFetch";
import { toastMessage } from "lib/toastMessage";
import { create } from "zustand";
import { useDispatchMapState, useSocketStore } from "state/mapState";
import { ModalIds } from "types/modal-ids";
import { useModal } from "state/modalState";
import { makeSocketConnection } from "components/dispatch/map/modals/select-map-server-modal";
import { ConnectionStatus } from "@snailycad/ui";
import { createWithEqualityFn } from "zustand/traditional";
import { shallow } from "zustand/shallow";

export const useMapPlayersStore = create<{
export const useMapPlayersStore = createWithEqualityFn<{
players: Map<string, MapPlayer | PlayerDataEventPayload>;
setPlayers(players: Map<string, MapPlayer | PlayerDataEventPayload>): void;
}>((set) => ({
players: new Map<string, MapPlayer | PlayerDataEventPayload>(),
setPlayers: (players: Map<string, MapPlayer | PlayerDataEventPayload>) => set({ players }),
}));
}>(
(set) => ({
players: new Map<string, MapPlayer | PlayerDataEventPayload>(),
setPlayers: (players: Map<string, MapPlayer | PlayerDataEventPayload>) => set({ players }),
}),
shallow,
);

export function useMapPlayers() {
const { players, setPlayers } = useMapPlayersStore();
Expand Down
20 changes: 12 additions & 8 deletions apps/client/src/state/dispatch/active-dispatcher-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Call911, Call911Event, ActiveDispatchers, AssignedUnit } from "@snailycad/types";
import { create } from "zustand";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";

export type Full911Call = Call911 & { assignedUnits: AssignedUnit[]; events: Call911Event[] };

Expand All @@ -11,11 +12,14 @@ interface ActiveDispatcherState {
setUserActiveDispatcher(dispatcher: ActiveDispatchers | null, count?: number): void;
}

export const useActiveDispatcherState = create<ActiveDispatcherState>()((set) => ({
activeDispatchersCount: 0,
setActiveDispatchersCount: (count) => set({ activeDispatchersCount: count }),
export const useActiveDispatcherState = createWithEqualityFn<ActiveDispatcherState>()(
(set) => ({
activeDispatchersCount: 0,
setActiveDispatchersCount: (count) => set({ activeDispatchersCount: count }),

userActiveDispatcher: null,
setUserActiveDispatcher: (dispatcher, count) =>
set({ userActiveDispatcher: dispatcher, activeDispatchersCount: count }),
}));
userActiveDispatcher: null,
setUserActiveDispatcher: (dispatcher, count) =>
set({ userActiveDispatcher: dispatcher, activeDispatchersCount: count }),
}),
shallow,
);

0 comments on commit 9a8d959

Please sign in to comment.