From 8cac8d72dd8e80e7e0dcc583b2a336084ab8a934 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Fri, 5 Sep 2025 22:22:44 +0200 Subject: [PATCH] item index page is now not opening internal profile if external profile exist --- lib/src/Components/Map/Layer.tsx | 5 +++++ lib/src/Components/Templates/ItemCard.tsx | 27 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/src/Components/Map/Layer.tsx b/lib/src/Components/Map/Layer.tsx index 7239a7b3..c41e715a 100644 --- a/lib/src/Components/Map/Layer.tsx +++ b/lib/src/Components/Map/Layer.tsx @@ -1,8 +1,10 @@ import { useEffect, useState } from 'react' import { useSetItemsApi, useSetItemsData } from './hooks/useItems' +import { usePopupForm } from './hooks/usePopupForm' import { useAddTag } from './hooks/useTags' import LayerContext from './LayerContext' +import { ItemFormPopup } from './Subcomponents/ItemFormPopup' import type { LayerProps } from '#types/LayerProps' import type { Tag } from '#types/Tag' @@ -42,6 +44,7 @@ export const Layer = ({ const addTag = useAddTag() const [newTagsToAdd] = useState([]) const [tagsReady] = useState(false) + const { popupForm } = usePopupForm() useEffect(() => { data && @@ -116,6 +119,8 @@ export const Layer = ({ }} > {children} + {/* Auto-render ItemFormPopup when popupForm matches this layer */} + {popupForm && popupForm.layer.name === name && } ) } diff --git a/lib/src/Components/Templates/ItemCard.tsx b/lib/src/Components/Templates/ItemCard.tsx index e8b5b1f3..9add7b56 100644 --- a/lib/src/Components/Templates/ItemCard.tsx +++ b/lib/src/Components/Templates/ItemCard.tsx @@ -1,6 +1,8 @@ +import { LatLng } from 'leaflet' import { useMap } from 'react-leaflet' import { useNavigate } from 'react-router-dom' +import { usePopupForm } from '#components/Map/hooks/usePopupForm' import { useSetSelectPosition } from '#components/Map/hooks/useSelectPosition' import useWindowDimensions from '#components/Map/hooks/useWindowDimension' import { StartEndView, TextView } from '#components/Map/Subcomponents/ItemPopupComponents' @@ -25,6 +27,29 @@ export const ItemCard = ({ const windowDimensions = useWindowDimensions() const map = useMap() const setSelectPosition = useSetSelectPosition() + const { setPopupForm } = usePopupForm() + + const handleEdit = () => { + if (!i.layer) { + throw new Error('Layer is not defined') + } + + if (i.layer.itemType.custom_profile_url && i.position) { + navigate('/') + // Wait for navigation to complete before setting popup + setTimeout(() => { + if (i.position && i.layer) { + setPopupForm({ + position: new LatLng(i.position.coordinates[1], i.position.coordinates[0]), + layer: i.layer, + item: i, + }) + } + }, 100) + } else { + navigate('/edit-item/' + i.id) + } + } return (
navigate('/edit-item/' + i.id)} + editCallback={() => handleEdit()} setPositionCallback={() => { map.closePopup() setSelectPosition(i)