Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Active detour in mobile drawer #2844

Merged
merged 27 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4daf63a
feat: Simple drawer component
hannahpurcell Oct 7, 2024
7e603ff
feat: Active detour in drawer on mobile
hannahpurcell Oct 7, 2024
1aba57f
Merge branch 'main' into hp/simple-drawer
hannahpurcell Oct 8, 2024
b5a1d95
Merge branch 'main' into hp/simple-drawer
hannahpurcell Oct 9, 2024
efac010
tweak: move isMobile to separate utility file along with DeviceType
hannahpurcell Oct 9, 2024
3fe4738
tweak: fix grid header for detourModal
hannahpurcell Oct 9, 2024
e9c30b1
test: fix snapshot with updated classname
hannahpurcell Oct 9, 2024
3754d9d
Merge branch 'hp/simple-drawer' into hp/drawer-with-active-detour
hannahpurcell Oct 9, 2024
e18a826
tests: ensure detour uses drawer on mobile
hannahpurcell Oct 10, 2024
b388570
code review: Use more precise grid area name
hannahpurcell Oct 10, 2024
43a2b8e
code review: use grid-area instead of both grid-row and -column
hannahpurcell Oct 10, 2024
c9c0c48
tweak: prettier
hannahpurcell Oct 10, 2024
4fd3f40
Merge branch 'hp/drawer-with-active-detour' of https://github.com/mbt…
hannahpurcell Oct 10, 2024
896517c
tweak: prettier
hannahpurcell Oct 10, 2024
86aecd6
refactor(ts/drawer): split drawer into two components
firestack Oct 8, 2024
d5e92c0
tweak: remove default export
hannahpurcell Oct 10, 2024
6bb2d1c
tweak: export DrawerWithState, not Drawer
hannahpurcell Oct 10, 2024
6d602a3
tweak: prettier
hannahpurcell Oct 10, 2024
d0a4b7a
tweak: remove unneeded prop
hannahpurcell Oct 10, 2024
7e94d7e
Merge branch 'hp/simple-drawer' into hp/drawer-with-active-detour
hannahpurcell Oct 10, 2024
27be4ba
tweak: integration polish after merging updates to DrawerWithState
hannahpurcell Oct 10, 2024
d844c6d
tweak: start with drawer open
hannahpurcell Oct 10, 2024
312054d
tweak: just check button change as opposed to making a whole new snap…
hannahpurcell Oct 10, 2024
96f2b42
Update assets/src/components/detours/diversionPage.tsx
hannahpurcell Oct 10, 2024
b8b1d4b
tweak: fix drawerwithstate ref
hannahpurcell Oct 10, 2024
f10732f
tweak: again! prettier!
hannahpurcell Oct 10, 2024
1d304b4
Merge branch 'main' into hp/drawer-with-active-detour
hannahpurcell Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions assets/css/_diversion_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"map" 80vh
/ 1fr;

&__header {
grid-area: heading;
}

&__panel {
grid-area: panel;
}
Expand All @@ -21,18 +25,48 @@
}
}

&--mobile,
&--mobile_landscape_tablet_portrait {
grid-template:
"heading" min-content
"map-and-panel" auto
/ 1fr;

.l-diversion-page__panel,
.l-diversion-page__map {
grid-area: map-and-panel;
}

.l-diversion-page-panel__scroll-area {
padding-top: 1rem;
}

.l-diversion-page__header {
border-bottom: none;
}
.c-diversion-panel__header_text,
.c-detour-panel__subheader,
.c-diversion-panel__back-button-container,
.c-active-detour__alert-icon {
display: none !important;
}
}

@include media-breakpoint-up(md) {
// For larger breakpoints, layout into grid
grid-template:
"heading heading" min-content
"heading heading-right" min-content
"panel map" auto
/ max(22.5vw, 350px) auto;

.l-diversion-page__header {
grid-area: heading-right;
}
// Overlay the panel and make the panel header match
// the size of the page header if subgrid is supported
@supports (grid-template-rows: subgrid) {
grid-template:
[panel-start] "heading heading" min-content
[panel-start] "heading heading-right" min-content
"panel map" auto
/ max(22.5vw, 350px) auto;

Expand All @@ -45,7 +79,6 @@

grid-area: panel;

.l-diversion-page__header,
.l-diversion-page-panel__header {
grid-row: heading;
}
Expand All @@ -55,6 +88,10 @@
}
}
}

.l-diversion-page-panel__header .c-diversion-panel__back-button {
display: none;
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions assets/src/components/detours/detourPanelComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export const AffectedRoute = ({
routeOrigin,
routeDirection,
}: AffectedRouteProps) => (
<section className="pb-3 border-bottom">
<h2 className="c-diversion-panel__h2">Affected route</h2>
<section className="pb-3">
<h2 className="c-diversion-panel__h2 c-detour-panel__subheader">
Affected route
</h2>
<div className="d-flex">
<RoutePill className="me-2 align-top" routeName={routeName} />

Expand Down
143 changes: 75 additions & 68 deletions assets/src/components/detours/detourPanels/activeDetourPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,77 +33,84 @@ export const ActiveDetourPanel = ({
onOpenDeactivateModal,
onNavigateBack,
children,
}: ActiveDetourPanelProps) => (
<Panel as="article" className="c-diversion-panel">
<Panel.Header>
<h1 className="c-diversion-panel__h1 my-3">Active Detour</h1>
</Panel.Header>
}: ActiveDetourPanelProps) => {
const backButton = (
<Button
className="c-diversion-panel__back-button icon-link my-3"
variant="outline-primary"
onClick={onNavigateBack}
>
<ArrowLeft />
Back
</Button>
)

<Panel.Body className="d-flex flex-column">
<Panel.Body.ScrollArea>
<div className="d-flex justify-content-between align-items-center">
{onNavigateBack && (
<Button
className="icon-link my-3"
variant="outline-primary"
onClick={onNavigateBack}
>
<ArrowLeft />
Back
</Button>
return (
<Panel as="article" className="c-diversion-panel">
<Panel.Header className="d-inline-flex justify-content-between">
<h1 className="c-diversion-panel__header_text c-diversion-panel__h1 my-3">
Active Detour
</h1>
{backButton}
</Panel.Header>

<Panel.Body className="d-flex flex-column">
<Panel.Body.ScrollArea>
<div className="d-flex c-diversion-panel__back-button-container justify-content-between align-items-center">
{backButton}
firestack marked this conversation as resolved.
Show resolved Hide resolved
<ExclamationTriangleFill className="c-active-detour__alert-icon" />
</div>
<AffectedRoute
routeName={routeName}
routeDescription={routeDescription}
routeOrigin={routeOrigin}
routeDirection={routeDirection}
/>

{connectionPoints && (
<section className="pb-3">
<h2 className="c-diversion-panel__h2">Connection Points</h2>
<ListGroup as="ul">
<ListGroup.Item>{connectionPoints[0]}</ListGroup.Item>
<ListGroup.Item>{connectionPoints[1]}</ListGroup.Item>
</ListGroup>
</section>
)}
<ExclamationTriangleFill className="c-active-detour__alert-icon" />
</div>
<AffectedRoute
routeName={routeName}
routeDescription={routeDescription}
routeOrigin={routeOrigin}
routeDirection={routeDirection}
/>

{connectionPoints && (
<MissedStops missedStops={missedStops} />

<section className="pb-3">
<h2 className="c-diversion-panel__h2">Connection Points</h2>
<ListGroup as="ul">
<ListGroup.Item>{connectionPoints[0]}</ListGroup.Item>
<ListGroup.Item>{connectionPoints[1]}</ListGroup.Item>
</ListGroup>
<h2 className="c-diversion-panel__h2">Detour Directions</h2>
{directions ? (
<ListGroup as="ol">
{directions.map((d) => (
<ListGroup.Item key={d.instruction} as="li">
{d.instruction == "Regular Route" ? (
<strong className="fw-medium">{d.instruction}</strong>
) : (
d.instruction
)}
</ListGroup.Item>
))}
</ListGroup>
) : null}
</section>
)}

<MissedStops missedStops={missedStops} />
</Panel.Body.ScrollArea>

<section className="pb-3">
<h2 className="c-diversion-panel__h2">Detour Directions</h2>
{directions ? (
<ListGroup as="ol">
{directions.map((d) => (
<ListGroup.Item key={d.instruction} as="li">
{d.instruction == "Regular Route" ? (
<strong className="fw-medium">{d.instruction}</strong>
) : (
d.instruction
)}
</ListGroup.Item>
))}
</ListGroup>
) : null}
</section>
</Panel.Body.ScrollArea>

<Panel.Body.Footer>
{onOpenDeactivateModal && (
<Button
variant="ui-alert"
className="flex-grow-1 m-3 icon-link text-light justify-content-center"
onClick={onOpenDeactivateModal}
>
<StopCircle />
Return to regular route
</Button>
)}
</Panel.Body.Footer>
</Panel.Body>
{children}
</Panel>
)
<Panel.Body.Footer>
{onOpenDeactivateModal && (
<Button
variant="ui-alert"
className="flex-grow-1 m-3 icon-link text-light justify-content-center"
onClick={onOpenDeactivateModal}
>
<StopCircle />
Return to regular route
</Button>
)}
</Panel.Body.Footer>
</Panel.Body>
{children}
</Panel>
)
}
19 changes: 16 additions & 3 deletions assets/src/components/detours/diversionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { timeAgoLabel } from "../../util/dateTime"
import { DetourStatus, timestampLabelFromStatus } from "../detoursTable"
import { ActivateDetour } from "./activateDetourModal"
import { DeactivateDetourModal } from "./deactivateDetourModal"
import useScreenSize from "../../hooks/useScreenSize"
import { Drawer } from "../drawer"
import { isMobile } from "../../util/screenSize"

const displayFieldsFromRouteAndPattern = (
route: Route,
Expand Down Expand Up @@ -394,9 +397,13 @@ export const DiversionPage = ({
}
}

const displayType = useScreenSize()

return (
<>
<article className="l-diversion-page h-100 border-box inherit-box">
<article
className={`l-diversion-page l-diversion-page--${displayType} h-100 border-box inherit-box`}
>
<header
className={joinClasses([
"l-diversion-page__header",
Expand All @@ -407,7 +414,7 @@ export const DiversionPage = ({
: "text-bg-light",
])}
>
{"snapshot" in useDetourProps && (
{"snapshot" in useDetourProps && !isMobile(displayType) ? (
<>
<span className="l-diversion-page__header-details">
<strong className="font-m-semi me-2">
Expand All @@ -420,6 +427,8 @@ export const DiversionPage = ({
{useDetourProps.author}
</span>
</>
) : (
<div className="flex-grow-1 fw-semibold text-center">Detours</div>
)}
<CloseButton className="p-4" onClick={onClose} />
</header>
Expand All @@ -433,7 +442,11 @@ export const DiversionPage = ({
: "text-bg-light",
])}
>
{detourPanel()}
{isMobile(displayType) ? (
<Drawer.WithState startOpen>{detourPanel()}</Drawer.WithState>
) : (
detourPanel()
)}
</div>
<div className="l-diversion-page__map position-relative">
{snapshot.matches({ "Detour Drawing": "Share Detour" }) && (
Expand Down
8 changes: 3 additions & 5 deletions assets/src/components/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
onToggleOpen?: () => void
}

const Drawer = ({
export const Drawer = ({
open = true,
onToggleOpen,
children,
Expand Down Expand Up @@ -35,10 +35,8 @@ interface DrawerWithStateProps {
startOpen?: boolean
}

export const DrawerWithState = (
props: PropsWithChildren<DrawerWithStateProps>
) => {
const [drawerOpen, setDrawerOpen] = useState(props.startOpen)
const DrawerWithState = (props: PropsWithChildren<DrawerWithStateProps>) => {
const [drawerOpen, setDrawerOpen] = useState(props.startOpen || false)
firestack marked this conversation as resolved.
Show resolved Hide resolved

return (
<Drawer
Expand Down
2 changes: 1 addition & 1 deletion assets/src/hooks/useScreenSize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react"
import { DeviceType } from "../skate"
import { DeviceType } from "../util/screenSize"

const maxMobileWidth = 480
const minMobileLandscapeTabletPortraitWidth = maxMobileWidth + 1
Expand Down
6 changes: 0 additions & 6 deletions assets/src/skate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ declare global {
}

export type UserToken = string

export type DeviceType =
| "mobile"
| "mobile_landscape_tablet_portrait"
| "tablet"
| "desktop"
8 changes: 8 additions & 0 deletions assets/src/util/screenSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type DeviceType =
| "mobile"
| "mobile_landscape_tablet_portrait"
| "tablet"
| "desktop"

export const isMobile = (deviceType: string) =>
deviceType === "mobile" || deviceType === "mobile_landscape_tablet_portrait"
Loading
Loading