Skip to content

Commit

Permalink
fix: performance
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jan 7, 2024
1 parent 5e295d4 commit 53d67d7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from "react";
import { useTranslations } from "next-intl";
import type { Call911 } from "@snailycad/types";
import { Manage911CallModal } from "components/dispatch/active-calls/modals/manage-911-call-modal";
import { useListener } from "@casperiv/use-socket.io";
import { SocketEvents } from "@snailycad/config";
import { CallItem } from "./call-item";
Expand Down Expand Up @@ -75,11 +74,6 @@ export function ActiveMapCalls() {
})}
</Accordion>
)}

<Manage911CallModal
onClose={() => calls911State.setCurrentlySelectedCall(null)}
call={calls911State.currentlySelectedCall}
/>
</div>
);
}
6 changes: 3 additions & 3 deletions apps/client/src/components/dispatch/map/map-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function MapActions() {
<div className="grid grid-cols-2 gap-2">
<DropdownMenu>
<DropdownMenuTrigger asChild key="trigger">
<Button>{t("Leo.toggle")}</Button>
<Button size="xs">{t("Leo.toggle")}</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="min-w-[175px]" align="start" key="content">
{hasManageSmartSignsPermissions ? (
Expand Down Expand Up @@ -71,10 +71,10 @@ export function MapActions() {
</DropdownMenuContent>
</DropdownMenu>

<Button onPress={() => modalState.openModal(ModalIds.Manage911Call)}>
<Button size="xs" onPress={() => modalState.openModal(ModalIds.Manage911Call)}>
{t("Calls.create911Call")}
</Button>
<Button onPress={() => modalState.openModal(ModalIds.SelectMapServer)}>
<Button size="xs" onPress={() => modalState.openModal(ModalIds.SelectMapServer)}>
{t("Leo.selectMapServer")}
</Button>
</div>
Expand Down
18 changes: 13 additions & 5 deletions apps/client/src/components/dispatch/map/sidebar/map-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,37 @@ import { useTranslations } from "use-intl";
import { ActiveMapCalls } from "../calls/active-map-calls";
import { ActiveMapUnits } from "../units/active-map-units";
import { MapActions } from "../map-actions";
import { Manage911CallModal } from "components/dispatch/active-calls/modals/manage-911-call-modal";
import { useCall911State } from "state/dispatch/call-911-state";

export function MapSidebar() {
const t = useTranslations();
const calls911State = useCall911State((state) => ({
currentlySelectedCall: state.currentlySelectedCall,
setCurrentlySelectedCall: state.setCurrentlySelectedCall,
}));

const tabs = [
{ value: "active-calls", name: t("Calls.active911Calls") },
{
value: "active-units",
name: t("Leo.activeUnits"),
},
{ value: "active-units", name: t("Leo.activeUnits") },
];

return (
<aside className="col-span-1 p-3">
<MapActions />
<TabList tabs={tabs}>
<TabList queryState={false} tabs={tabs}>
<TabsContent value="active-calls">
<ActiveMapCalls />
</TabsContent>
<TabsContent value="active-units">
<ActiveMapUnits />
</TabsContent>
</TabList>

<Manage911CallModal
onClose={() => calls911State.setCurrentlySelectedCall(null)}
call={calls911State.currentlySelectedCall}
/>
</aside>
);
}
9 changes: 8 additions & 1 deletion apps/client/src/hooks/realtime/use-active-dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ export function useActiveDispatchers() {

const router = useRouter();
const isCitizen = router.pathname.includes("/citizen");
const activeDispatcherState = useActiveDispatcherState();
const activeDispatcherState = useActiveDispatcherState((state) => ({
activeDispatchersCount: state.activeDispatchersCount,
userActiveDispatcher: state.userActiveDispatcher,
setActiveDispatchersCount: state.setActiveDispatchersCount,
setUserActiveDispatcher: state.setUserActiveDispatcher,
}));

useQuery({
queryKey: ["/dispatch"],
enabled: !isCitizen,
queryFn: getActiveDispatchers,
refetchOnMount: false,
});

async function getActiveDispatchers() {
Expand Down Expand Up @@ -48,6 +54,7 @@ export function useActiveDispatchers() {
async () => {
await queryClient.resetQueries({ queryKey: ["/dispatch"] });
},
[queryClient.resetQueries],
);

return {
Expand Down

0 comments on commit 53d67d7

Please sign in to comment.