Skip to content

Commit

Permalink
#379 Add parentId args to keep the context
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylchauf committed Jun 24, 2021
1 parent 5438225 commit 0eee4da
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions frontend/src/components/Map/DetailsMap/DetailsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type PropsType = {
bbox: { corner1: Coordinate2D; corner2: Coordinate2D };
trekChildrenGeometry?: TrekChildGeometry[];
sensitiveAreas?: SensitiveAreaGeometry[];
trekId: number
};

export const DetailsMap: React.FC<PropsType> = props => {
Expand Down Expand Up @@ -93,6 +94,7 @@ export const DetailsMap: React.FC<PropsType> = props => {
trekGeometry={props.trekGeometry}
/>
<MapChildren
parentId={props.trekId}
poiPoints={props.poiPoints}
touristicContentPoints={props.touristicContentPoints}
pointsReference={props.pointsReference}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Map/DetailsMap/MapChildren.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = {
referencePointsMobileVisibility: Visibility;
poiMobileVisibility: Visibility;
touristicContentMobileVisibility: Visibility;
parentId?: number;
};

export const MapChildren: React.FC<Props> = props => {
Expand All @@ -37,7 +38,7 @@ export const MapChildren: React.FC<Props> = props => {
return (
<>
{(visibleSection === 'children' || props.trekChildrenMobileVisibility === 'DISPLAYED') && (
<TrekChildren trekChildrenGeometry={props.trekChildrenGeometry} />
<TrekChildren trekChildrenGeometry={props.trekChildrenGeometry} parentId={props.parentId} />
)}

{(visibleSection === 'description' ||
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Map/DetailsMap/TrekChildren.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HoverableMarker } from '../components/HoverableMarker';

export type TrekChildrenPropsType = {
trekChildrenGeometry?: TrekChildGeometry[];
parentId?: number;
};

export const TrekChildren: React.FC<TrekChildrenPropsType> = props => {
Expand All @@ -24,7 +25,7 @@ export const TrekChildren: React.FC<TrekChildrenPropsType> = props => {
rank={index + 1}
type="TREK_CHILD"
>
<Popup id={id} type={'TREK'} />
<Popup id={id} type={'TREK'} parentId={props.parentId} />
</HoverableMarker>
);
})}
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/Map/components/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { usePopupResult } from '../../hooks/usePopupResult';

interface Props {
id: number;
parentId?: number;
handleOpen?: () => void;
handleClose?: () => void;
type: 'TREK' | 'TOURISTIC_CONTENT';
Expand All @@ -24,8 +25,9 @@ interface PropsPC {
showButton: boolean;
id: number;
type: 'TREK' | 'TOURISTIC_CONTENT';
parentId?: number;
}
const PopupContent: React.FC<PropsPC> = ({ showButton, id, type }) => {
const PopupContent: React.FC<PropsPC> = ({ showButton, id, type, parentId }) => {
const { isLoading, trekPopupResult } = usePopupResult(id.toString(), true, type);

return (
Expand All @@ -49,7 +51,7 @@ const PopupContent: React.FC<PropsPC> = ({ showButton, id, type }) => {
<Link
href={
type === 'TREK'
? generateResultDetailsUrl(id, trekPopupResult.title)
? generateResultDetailsUrl(id, trekPopupResult.title, parentId)
: generateTouristicContentUrl(id, trekPopupResult.title)
}
>
Expand All @@ -67,7 +69,7 @@ const PopupContent: React.FC<PropsPC> = ({ showButton, id, type }) => {
);
};

export const Popup: React.FC<Props> = ({ id, handleOpen, handleClose, type }) => {
export const Popup: React.FC<Props> = ({ id, parentId, handleOpen, handleClose, type }) => {
const [hideTooltip, setHideTooltip] = useState<boolean>(false);

return (
Expand All @@ -89,7 +91,7 @@ export const Popup: React.FC<Props> = ({ id, handleOpen, handleClose, type }) =>
}}
offset={[0, -12]}
>
<PopupContent type={type} id={id} showButton={true} />
<PopupContent type={type} id={id} showButton={true} parentId={parentId} />
</StyledPopup>
</>
);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/pages/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export const DetailsUIWithoutContext: React.FC<Props> = ({ detailsId, parentId,
geometry,
color,
}))}
trekId={Number(id)}
/>
</div>
)}
Expand Down Expand Up @@ -499,6 +500,7 @@ export const DetailsUIWithoutContext: React.FC<Props> = ({ detailsId, parentId,
id: `${touristicContent.id}`,
}))}
hideMap={hideMobileMap}
trekId={Number(id)}
/>
</MobileMapContainer>
)}
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/components/pages/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ export const formatInfiniteQuery = (
};

/** Generates the details page url related to a result */
export const generateResultDetailsUrl = (id: number | string, title: string): string => {
export const generateResultDetailsUrl = (
id: number | string,
title: string,
parentId?: number,
): string => {
const titleWithNoSpace = convertStringForSitemap(title);
const detailsPageUrl = `${routes.DETAILS}/${id}-${encodeURI(titleWithNoSpace)}`;
const detailsPageUrl = `${routes.DETAILS}/${id}-${encodeURI(titleWithNoSpace)}${
parentId ? `?parentId=${parentId}` : ''
}`;

return detailsPageUrl;
};
Expand Down

0 comments on commit 0eee4da

Please sign in to comment.