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

Define go back button on details pages #1303

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions frontend/src/components/ToolTip/ToolTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const ToolTipGT: FC<Props> = ({
className={cn(
'tooltipSpan',
'relative absolute left-1/2 -translate-x-1/2 p-1.5 text-center rounded-md z-1',
'w-0 invisible',
'group-hover:w-max group-hover:visible',
'w-0 hidden',
'group-hover:w-max group-hover:inline',
"after:content-[''] after:block after:absolute after:left-1/2 after:-ml-1 after:border-4 after:border-transparent",
invertPosition
? 'top-full after:bottom-full after:border-b-primary1'
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/components/pages/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import { DetailsViewPoints } from './components/DetailsViewPoints';
import { DetailsFiles } from './components/DetailsFiles';
import { theme } from '../../../../tailwind.config';
import { DetailsBackButton } from './components/DetailsPreview/DetailsBackButton';

interface Props {
slug: string | string[] | undefined;
Expand Down Expand Up @@ -706,7 +707,7 @@
)}
</>
),
[

Check warning on line 710 in frontend/src/components/pages/details/Details.tsx

View workflow job for this annotation

GitHub Actions / install-and-test

React Hook useMemo has missing dependencies: 'anchors', 'handleViewPointClick', 'hasNavigator', 'sectionRef', 'sections', and 'setMapId'. Either include them or remove the dependency array
details,
displayAltimetricProfile,
displayMobileMap,
Expand Down Expand Up @@ -736,15 +737,18 @@
return (
<div
id="details_headerMobile"
className={`py-3 px-4
text-P2 font-bold text-primary1
shadow-md bg-white
${displayState === 'DISPLAYED' ? 'top-mobileHeader sticky' : '-top-mobileHeader'}
desktop:hidden z-headerDetails truncate
transition-all duration-500
`}
className={cn(
'flex gap-3 items-center py-3 px-4',
'text-P2 font-bold text-primary1',
'shadow-md bg-white',
'-top-4 right-0 left-0 z-headerDetails fixed',
displayState === 'DISPLAYED' && 'top-0 translate-y-mobileHeader',
'desktop:hidden',
'transition-transform duration-500 will-change-transform',
)}
>
{name}
<DetailsBackButton className="border-r border-solid pr-4" />
<span className="truncate">{name}</span>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TouristicEventDetails } from 'modules/touristicEvent/interface';
import { ContentType } from 'modules/interface';
import { DetailsHeaderSection, DetailsSections } from '../../useDetails';
import { useDetailsHeader } from './useDetailsHeader';
import { DetailsBackButton } from '../DetailsPreview/DetailsBackButton';

interface DetailsHeaderProps {
anchors: Partial<DetailsSections>[];
Expand Down Expand Up @@ -42,16 +43,17 @@ export const DetailsHeader: React.FC<DetailsHeaderProps> = ({
id="details_headerDesktop"
className="hidden desktop:flex items-center
sticky top-desktopHeader z-subHeader
shadow-md bg-white h-14"
shadow-md bg-white h-14 pl-3"
role="navigation"
>
<DetailsBackButton className="border-r border-solid pr-5" />
{sections.length > 0 && (
<ul id="details_headerDesktop_inlineMenu" className="flex flex-1 ml-3">
<ul id="details_headerDesktop_inlineMenu" className="pl-5 flex flex-1 gap-5">
{sections.map(sectionId => (
<li key={sectionId}>
<a
className={cn(
'mx-5 pb-1 border-b-2 border-transparent border-solid transition-all duration-300 hover:text-primary1 hover:border-primary1 focus:text-primary1 focus:border-primary1',
'pb-1 border-b-2 border-transparent border-solid transition-all duration-300 hover:text-primary1 hover:border-primary1 focus:text-primary1 focus:border-primary1',
currentSectionId === sectionId && isMounted && 'text-primary1 border-primary1',
)}
href={`#details_${sectionId}`}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { HTMLAttributes } from 'react';
import { cn } from 'services/utils/cn';
import { ArrowLeft } from 'components/Icons/ArrowLeft';
import { useRouter } from 'next/router';
import { useListAndMapContext } from 'modules/map/ListAndMapContext';
import ToolTip from 'components/ToolTip';
import { useIntl } from 'react-intl';

export const DetailsBackButton: React.FC<HTMLAttributes<HTMLButtonElement>> = ({ className }) => {
const router = useRouter();
const { previousRouter } = useListAndMapContext();
const intl = useIntl();

if (!previousRouter?.asPath.startsWith('/search')) {
return null;
}

return (
<div className={cn('custo-go-back-button', className)}>
<ToolTip toolTipText={intl.formatMessage({ id: 'details.goBack' })} invertPosition>
<button
type="button"
className={cn(
'w-max inline-flex justify-start items-center gap-2 p-2 rounded-full shadow-sm text-primary1 bg-white hover:bg-primary2 transition-colors',
)}
onClick={router.back}
>
<ArrowLeft size={16} aria-hidden />
<span className="sr-only">{intl.formatMessage({ id: 'details.goBack' })}</span>
</button>
</ToolTip>
</div>
);
};
9 changes: 7 additions & 2 deletions frontend/src/hooks/useBrowserNavigationDetection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useRouter } from 'next/router';
import { NextRouter, useRouter } from 'next/router';
import { useEffect, useRef, useState } from 'react';

// Returns “true” if the page is displayed using the browser's "back" or "forward" buttons
const useBrowserNavigationDetection = () => {
const router = useRouter();
const isNavigatedByBrowserRef = useRef(false);
const [isNavigatedByBrowser, setNavigatedByBrowser] = useState(false);
const [previousRouter, setPreviousRouter] = useState<NextRouter | null>(null);

useEffect(() => {
router.beforePopState(() => {
Expand All @@ -22,6 +23,7 @@ const useBrowserNavigationDetection = () => {
} else {
setNavigatedByBrowser(false);
}
setPreviousRouter(router);
};

router.events.on('routeChangeStart', handleRouteChangeStart);
Expand All @@ -32,7 +34,10 @@ const useBrowserNavigationDetection = () => {
};
}, [router]);

return isNavigatedByBrowser;
return {
isNavigatedByBrowser,
previousRouter,
};
};

export default useBrowserNavigationDetection;
6 changes: 5 additions & 1 deletion frontend/src/modules/map/ListAndMapContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, useContext, useState } from 'react';
import { LatLngBounds } from 'leaflet';
import useBrowserNavigationDetection from 'hooks/useBrowserNavigationDetection';
import { NextRouter } from 'next/router';
import { MapResults } from '../mapResults/interface';

export interface ListAndMapContext {
Expand All @@ -11,6 +12,7 @@ export interface ListAndMapContext {
setHoveredCardId: (hoveredCardId: string | null) => void;
setSearchBbox: (bbox: LatLngBounds | null) => void;
isNavigatedByBrowser: boolean;
previousRouter: NextRouter | null;
}

const listAndMapContext = createContext<ListAndMapContext>({
Expand All @@ -21,6 +23,7 @@ const listAndMapContext = createContext<ListAndMapContext>({
setHoveredCardId: (_: string | null) => _,
setSearchBbox: (_: LatLngBounds | null) => _,
isNavigatedByBrowser: false,
previousRouter: null,
});

export const useListAndMapContext = () => useContext(listAndMapContext);
Expand All @@ -30,7 +33,7 @@ export const ListAndMapProvider: React.FC<React.PropsWithChildren> = ({ children
const [points, setPoints] = useState<MapResults>([]);
const [searchBbox, setSearchBbox] = useState<LatLngBounds | null>(null);

const isNavigatedByBrowser = useBrowserNavigationDetection();
const { isNavigatedByBrowser, previousRouter } = useBrowserNavigationDetection();

return (
<listAndMapContext.Provider
Expand All @@ -42,6 +45,7 @@ export const ListAndMapProvider: React.FC<React.PropsWithChildren> = ({ children
searchBbox,
setSearchBbox,
isNavigatedByBrowser,
previousRouter,
}}
>
{children}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"centerOnMap": "Center on map",
"openPictureInFullScreen": "View picture in full screen",
"closeFullScreen": "Close full screen mode",
"contact": "Contacte"
"contact": "Contacte",
"goBack": "Tornar enrere"
},
"touristicContent": {
"email": "Correu electrònic",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"centerOnMap": "Center on map",
"openPictureInFullScreen": "View picture in full screen",
"closeFullScreen": "Close full screen mode",
"contact": "Kontakt"
"contact": "Kontakt",
"goBack": "Zurückgehen"
},
"touristicContent": {
"email": "Email",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
"centerOnMap": "Center on map",
"openPictureInFullScreen": "View picture in full screen",
"closeFullScreen": "Close full screen mode",
"contact": "Contact"
"contact": "Contact",
"goBack": "Go back"
},
"touristicContent": {
"email": "Email",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"centerOnMap": "Center on map",
"openPictureInFullScreen": "View picture in full screen",
"closeFullScreen": "Close full screen mode",
"contact": "Contacto"
"contact": "Contacto",
"goBack": "Volver atrás"
},
"touristicContent": {
"email": "Correo electrónico",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
"centerOnMap": "Centrer sur la carte",
"openPictureInFullScreen": "Voir l'image en plein écran",
"closeFullScreen": "Fermer le mode plein écran",
"contact": "Contact"
"contact": "Contact",
"goBack": "Retour"
},
"touristicContent": {
"email": "Courriel",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
"centerOnMap": "Center on map",
"openPictureInFullScreen": "View picture in full screen",
"closeFullScreen": "Close full screen mode",
"contact": "Contatto"
"contact": "Contatto",
"goBack": "Torna indietro"
},
"touristicContent": {
"email": "email",
Expand Down
2 changes: 1 addition & 1 deletion frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ module.exports = {
20: 20,
leafletSvg: 200,
text: 200,
loader: 300,
floatingButton: 300,
header: 500,
subHeader: 450,
loader: 460,
headerDetails: 300,
sliderMenu: 900,
map: 1000,
Expand Down
Loading