From a49590243a01a91384a4391eb124fa26142d5f52 Mon Sep 17 00:00:00 2001 From: Anton Tranelis <31516529+antontranelis@users.noreply.github.com> Date: Sun, 7 Sep 2025 13:47:50 +0200 Subject: [PATCH] adjust UserControl for external profiles and small item edits (#363) --- lib/src/Components/AppShell/UserControl.tsx | 48 +++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/src/Components/AppShell/UserControl.tsx b/lib/src/Components/AppShell/UserControl.tsx index ca05f9ee..c108ab2a 100644 --- a/lib/src/Components/AppShell/UserControl.tsx +++ b/lib/src/Components/AppShell/UserControl.tsx @@ -1,9 +1,11 @@ import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon' -import { Link } from 'react-router-dom' +import { LatLng } from 'leaflet' +import { Link, useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' import { useAuth } from '#components/Auth/useAuth' import { useMyProfile } from '#components/Map/hooks/useMyProfile' +import { usePopupForm } from '#components/Map/hooks/usePopupForm' import { useAppState } from './hooks/useAppState' @@ -13,6 +15,8 @@ export const UserControl = () => { const { isAuthenticated, user, logout } = useAuth() const appState = useAppState() const { myProfile } = useMyProfile() + const navigate = useNavigate() + const { setPopupForm } = usePopupForm() // Use myProfile or create a fallback object for display const userProfile: Partial = myProfile ?? { @@ -38,6 +42,32 @@ export const UserControl = () => { pending: 'logging out ..', }) } + + const handleEdit = () => { + if (!myProfile?.layer) { + navigate(userProfile.id ? `/edit-item/${userProfile.id}` : '#') + return + } + + if (myProfile.layer.itemType.small_form_edit && myProfile.position) { + navigate('/') + // Wait for navigation to complete before setting popup + setTimeout(() => { + if (myProfile.position && myProfile.layer) { + setPopupForm({ + position: new LatLng( + myProfile.position.coordinates[1], + myProfile.position.coordinates[0], + ), + layer: myProfile.layer, + item: myProfile, + }) + } + }, 100) + } else { + navigate(userProfile.id ? `/edit-item/${userProfile.id}` : '#') + } + } const avatar: string | undefined = userProfile.image && appState.assetsApi.url ? appState.assetsApi.url + userProfile.image @@ -48,7 +78,13 @@ export const UserControl = () => { {isAuthenticated ? (
{avatar && ( @@ -69,7 +105,13 @@ export const UserControl = () => { className='tw:menu tw:menu-compact tw:dropdown-content tw:mt-4 tw:p-2 tw:shadow tw:bg-base-100 tw:rounded-box tw:w-52 tw:z-10000!' >
  • - Profile + { + handleEdit() + }} + > + Profile +
  • Settings