Skip to content

Commit

Permalink
chore: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Aug 24, 2023
1 parent 55a5360 commit 47ecaa0
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function ManagePetMedicalRecordModal(props: Props) {
const modalState = useModal();
const common = useTranslations("Common");
const t = useTranslations("MedicalRecords");
const { currentPet } = usePetsState();
const currentPet = usePetsState((state) => state.currentPet);

function handleClose() {
modalState.closeModal(ModalIds.ManagePetMedicalRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function ManagePetNoteModal(props: Props) {
const common = useTranslations("Common");
const t = useTranslations("Pets");
const { state, execute } = useFetch();
const { currentPet } = usePetsState();
const currentPet = usePetsState((state) => state.currentPet);

function handleClose() {
modalState.closeModal(ModalIds.ManageNote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useTranslations } from "use-intl";
export function PetInformationCard() {
const t = useTranslations("Pets");
const { cad } = useAuth();
const { currentPet } = usePetsState();
const currentPet = usePetsState((state) => state.currentPet);
const modalState = useModal();
const { state, execute } = useFetch();
const router = useRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function NameSearchVehiclesTab() {
const { DMV } = useFeatureEnabled();
const currentResult = useNameSearch((state) => state.currentResult);
const modalState = useModal();
const { setCurrentResult: setVehicleResult } = useVehicleSearch();
const setVehicleResult = useVehicleSearch((state) => state.setCurrentResult);
const tableState = useTableState();

function handlePlateClick(vehicle: VehicleSearchResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import type {
import { useDebounce, useHoverDirty } from "react-use";
import { isUnitCombined, isUnitCombinedEmsFd } from "@snailycad/utils";
import useFetch from "lib/useFetch";
import { create } from "zustand";
import { HoverCard, HoverCardContent, HoverCardTrigger, Loader } from "@snailycad/ui";
import type { GetUnitQualificationsByUnitIdData } from "@snailycad/types/api";
import dynamic from "next/dynamic";
import { createWithEqualityFn } from "zustand/traditional";
import { shallow } from "zustand/shallow";

const UnitQualificationsTable = dynamic(
async () => (await import("./UnitQualificationsTable")).UnitQualificationsTable,
Expand All @@ -33,10 +34,13 @@ interface CacheStore {
setUnits(units: CacheStore["units"]): void;
}

const useCacheStore = create<CacheStore>((set) => ({
units: {},
setUnits: (units) => set({ units }),
}));
const useCacheStore = createWithEqualityFn<CacheStore>(
(set) => ({
units: {},
setUnits: (units) => set({ units }),
}),
shallow,
);

export function ActiveUnitsQualificationsCard({ canBeOpened = true, unit, children }: Props) {
const { state, execute } = useFetch();
Expand Down
16 changes: 10 additions & 6 deletions apps/client/src/hooks/shared/useSignal100.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import { useTranslations } from "use-intl";
import { useAudio } from "react-use";
import { useCall911State } from "state/dispatch/call-911-state";
import { Alert } from "@snailycad/ui";
import { create } from "zustand";
import { createWithEqualityFn } from "zustand/traditional";
import { shallow } from "zustand/shallow";

const useSignal100Store = create<{
const useSignal100Store = createWithEqualityFn<{
playCount: number;
setPlayCount(value: number): void;
}>()((set) => ({
playCount: 0,
setPlayCount: (value: number) => set({ playCount: value }),
}));
}>()(
(set) => ({
playCount: 0,
setPlayCount: (value: number) => set({ playCount: value }),
}),
shallow,
);

const SIGNAL_100_SRC = "/sounds/signal100.mp3";
export function useSignal100() {
Expand Down
30 changes: 17 additions & 13 deletions apps/client/src/state/callsFiltersState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { create } from "zustand";
import type { Record, Citizen, MedicalRecord, RegisteredVehicle, Weapon } from "@snailycad/types";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";

export type CitizenWithVehAndWep = Citizen & {
weapons: Weapon[];
Expand All @@ -25,19 +26,22 @@ interface CallFiltersState {
setAssignedUnit(assignedUnit: string | null): void;
}

export const useCallsFilters = create<CallFiltersState>()((set) => ({
showFilters: false,
setShowFilters: (showFilters) => set({ showFilters }),
export const useCallsFilters = createWithEqualityFn<CallFiltersState>()(
(set) => ({
showFilters: false,
setShowFilters: (showFilters) => set({ showFilters }),

search: "",
setSearch: (search) => set({ search }),
search: "",
setSearch: (search) => set({ search }),

assignedUnit: null,
setAssignedUnit: (assignedUnit) => set({ assignedUnit }),
assignedUnit: null,
setAssignedUnit: (assignedUnit) => set({ assignedUnit }),

department: null,
setDepartment: (department) => set({ department }),
department: null,
setDepartment: (department) => set({ department }),

division: null,
setDivision: (division) => set({ division }),
}));
division: null,
setDivision: (division) => set({ division }),
}),
shallow,
);
14 changes: 9 additions & 5 deletions apps/client/src/state/citizen/pets-state.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type { Pet } from "@snailycad/types";
import { create } from "zustand";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";

interface PetsState {
currentPet: Pet | null;
setCurrentPet(pet: Pet): void;
}

export const usePetsState = create<PetsState>()((set) => ({
currentPet: null,
setCurrentPet: (pet) => set({ currentPet: pet }),
}));
export const usePetsState = createWithEqualityFn<PetsState>()(
(set) => ({
currentPet: null,
setCurrentPet: (pet) => set({ currentPet: pet }),
}),
shallow,
);
24 changes: 13 additions & 11 deletions apps/client/src/state/mapState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ConnectionStatus } from "@snailycad/ui";
import { Socket } from "socket.io-client";
import { SmartSignMarker } from "types/map";
import { create } from "zustand";
import { persist, createJSONStorage } from "zustand/middleware";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
Expand Down Expand Up @@ -67,14 +66,17 @@ export const useDispatchMapState = createWithEqualityFn<DispatchMapState>()(
shallow,
);

export const useSocketStore = create<SocketStore>()((set) => ({
status: null,
setStatus(status) {
set({ status });
},
export const useSocketStore = createWithEqualityFn<SocketStore>()(
(set) => ({
status: null,
setStatus(status) {
set({ status });
},

socket: null,
setSocket(socket) {
set({ socket });
},
}));
socket: null,
setSocket(socket) {
set({ socket });
},
}),
shallow,
);
14 changes: 9 additions & 5 deletions apps/client/src/state/search/vehicle-search-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PostLeoSearchVehicleData } from "@snailycad/types/api";
import { create } from "zustand";
import { createWithEqualityFn } from "zustand/traditional";
import { shallow } from "zustand/shallow";

export type VehicleSearchResult = NonNullable<PostLeoSearchVehicleData>;

Expand All @@ -8,7 +9,10 @@ interface VehicleSearchState {
setCurrentResult(v: VehicleSearchResult | null | "initial"): void;
}

export const useVehicleSearch = create<VehicleSearchState>()((set) => ({
currentResult: "initial",
setCurrentResult: (v) => set({ currentResult: v }),
}));
export const useVehicleSearch = createWithEqualityFn<VehicleSearchState>()(
(set) => ({
currentResult: "initial",
setCurrentResult: (v) => set({ currentResult: v }),
}),
shallow,
);

0 comments on commit 47ecaa0

Please sign in to comment.