Skip to content

Commit

Permalink
disable active detours on ladder (#2941)
Browse files Browse the repository at this point in the history
  • Loading branch information
firestack authored Jan 27, 2025
1 parent bb0fc04 commit a53cba9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion assets/src/components/routeLadders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SocketContext } from "../contexts/socketContext"
import useAlerts from "../hooks/useAlerts"
import { DetoursMap, useActiveDetours } from "../hooks/useDetours"
import { DetourId, SimpleDetour } from "../models/detoursList"
import inTestGroup, { TestGroups } from "../userInTestGroup"

export const findRouteById = (
routes: Route[] | null,
Expand Down Expand Up @@ -65,7 +66,10 @@ const RouteLadders = ({

// TODO: once DB is optimized for querying by route and status, we can open individual channels for each route ladder
// const skateDetours = useActiveDetoursByRoute(socket, selectedRouteIds)
const allActiveSkateDetours = useActiveDetours(socket)
const allActiveSkateDetours = useActiveDetours(
socket,
inTestGroup(TestGroups.DetoursOnLadder)
)

const skateDetoursByRouteName = Object.values(allActiveSkateDetours).reduce(
(acc: ByRouteId<DetoursMap>, cur: SimpleDetour) => {
Expand Down
11 changes: 9 additions & 2 deletions assets/src/hooks/useDetours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ const subscribe = (
}

// This is to refresh the Detours List page. We need all active detours
export const useActiveDetours = (socket: Socket | undefined) => {
export const useActiveDetours = (
socket: Socket | undefined,
enable: boolean = true
) => {
const topic = "detours:active"
const [activeDetours, setActiveDetours] = useState<DetoursMap>({})

Expand All @@ -105,6 +108,10 @@ export const useActiveDetours = (socket: Socket | undefined) => {
}

useEffect(() => {
if (enable === false) {
return
}

let channel: Channel | undefined
if (socket) {
channel = subscribe(
Expand All @@ -125,7 +132,7 @@ export const useActiveDetours = (socket: Socket | undefined) => {
channel = undefined
}
}
}, [socket])
}, [socket, enable])
return activeDetours
}

Expand Down
1 change: 1 addition & 0 deletions assets/src/userInTestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum TestGroups {
CopyButton = "copy-button",
DeleteDraftDetours = "delete-draft-detours",
ChangeDetourDuration = "change-detour-duration",
DetoursOnLadder = "detours-on-ladder",
}

const inTestGroup = (key: TestGroups): boolean => {
Expand Down

0 comments on commit a53cba9

Please sign in to comment.