Skip to content

Commit 2387c21

Browse files
Merge pull request #76 from MobilityData/fix/41-feed-detail-back-button
fix: feed detail and map improved back navigation
2 parents 5b0a796 + 652509f commit 2387c21

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/app/screens/Feed/FeedView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default async function FeedView({
168168
feedId={feed.id ?? ''}
169169
/>
170170

171-
<Box sx={{ mt: 2 }}>
171+
<Box sx={{ mt: 1 }}>
172172
<FeedTitle sortedProviders={sortedProviders} feed={feed} />
173173
</Box>
174174

src/app/screens/Feed/components/FeedNavigationControls.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ export default function FeedNavigationControls({
1717
const t = useTranslations('common');
1818
const router = useRouter();
1919

20+
const handleBack = (): void => {
21+
if (window.history.length > 1) {
22+
router.back();
23+
return;
24+
}
25+
router.push('/feeds');
26+
};
27+
2028
return (
21-
<Grid container spacing={3} alignItems='flex-end'>
29+
<Grid container spacing={3} alignItems='center'>
2230
<Button
23-
sx={{ py: 0 }}
2431
size='large'
2532
startIcon={<ChevronLeft />}
2633
color={'inherit'}
27-
onClick={() => {
28-
if (window.history.length > 1) {
29-
router.back();
30-
} else {
31-
router.push('/feeds');
32-
}
33-
}}
34+
onClick={handleBack}
3435
>
3536
{t('back')}
3637
</Button>

src/app/screens/Feed/components/FullMapView.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ export default function FullMapView({
119119
const isGtfsFeed = feed?.data_type === 'gtfs';
120120
const hasError = !isGtfsFeed || feed == null || boundingBox == null;
121121

122+
const handleExitMap = (): void => {
123+
if (window.history.length > 1) {
124+
router.back();
125+
return;
126+
}
127+
128+
if (feedId != null) {
129+
router.replace(`/feeds/${feed?.data_type ?? 'gtfs'}/${feedId}`);
130+
return;
131+
}
132+
133+
router.replace('/feeds');
134+
};
135+
122136
const errorDetails = useMemo(() => {
123137
const messages: string[] = [];
124138
if (feed == null) {
@@ -251,13 +265,7 @@ export default function FullMapView({
251265
startIcon={<ChevronLeft />}
252266
color={'inherit'}
253267
sx={{ pl: 0, display: { xs: 'none', md: 'inline-flex' } }}
254-
onClick={() => {
255-
if (!hasError && feedId != null) {
256-
router.push(`/feeds/gtfs/${feedId}`);
257-
} else {
258-
router.push('/');
259-
}
260-
}}
268+
onClick={handleExitMap}
261269
>
262270
{tCommon('back')}
263271
</Button>
@@ -387,13 +395,7 @@ export default function FullMapView({
387395
size='small'
388396
aria-label={t('fullMapView.aria.close')}
389397
sx={{ position: 'absolute', top: 10, right: 10, zIndex: 1000 }}
390-
onClick={() => {
391-
if (!hasError && feedId != null) {
392-
router.push(`/feeds/${feed?.data_type}/${feedId}`);
393-
} else {
394-
router.push('/');
395-
}
396-
}}
398+
onClick={handleExitMap}
397399
>
398400
<CloseIcon />
399401
</Fab>

0 commit comments

Comments
 (0)