Skip to content

Commit

Permalink
feat: Don't open the drawer on mobile when a search result is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Nov 20, 2023
1 parent ea9be0c commit 81c1e79
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions assets/src/components/mapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { joinClasses } from "../helpers/dom"
import { ChevronLeftIcon, SearchIcon } from "../helpers/icon"
import useMostRecentVehicleById from "../hooks/useMostRecentVehicleById"
import usePatternsByIdForRoute from "../hooks/usePatternsByIdForRoute"
import useScreenSize from "../hooks/useScreenSize"
import useSocket from "../hooks/useSocket"
import { Ghost, Vehicle, VehicleId } from "../realtime"
import { RoutePattern } from "../schedule"
Expand Down Expand Up @@ -212,10 +213,15 @@ const MapPage = (): ReactElement<HTMLDivElement> => {
const [{ searchPageState }, dispatch] = useContext(StateDispatchContext),
{ selectedEntity = null } = searchPageState

const deviceType = useScreenSize()
const isMobile =
deviceType === "mobile" || deviceType === "mobile_landscape_tablet_portrait"
const defaultSearchOpen = !selectedEntity || !isMobile

const { openVehiclePropertiesPanel } = usePanelStateFromStateDispatchContext()

// #region Search Drawer Logic
const [searchOpen, setSearchOpen] = useState<boolean>(true)
const [searchOpen, setSearchOpen] = useState<boolean>(defaultSearchOpen)
const toggleSearchDrawer = useCallback(
() => setSearchOpen((open) => !open),
[setSearchOpen]
Expand Down Expand Up @@ -243,12 +249,12 @@ const MapPage = (): ReactElement<HTMLDivElement> => {
fullStoryEvent("RPC Opened", {})
}
if (selectedEntity) {
setSearchOpen(true)
setSearchOpen(!isMobile)
}

dispatch(setSelectedEntity(selectedEntity))
},
[dispatch]
[dispatch, isMobile]
)

const selectVehicleResult = useCallback(
Expand Down

0 comments on commit 81c1e79

Please sign in to comment.