From 6fcdef043371dcd3e860427f3ec97108c9044211 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 20 Aug 2025 18:55:02 +0200 Subject: [PATCH] fix(lib): ensure user_created is preserved in all item operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add user_created field to all item update operations to maintain proper user association - Update useMyProfile hook to use direct computation instead of useMemo to avoid React hook queue issues - Refactor UserControl to use useMyProfile hook for consistency - Fix user_created handling in LocateControl, ItemFormPopup, useSelectPosition, and itemFunctions - Add user parameter to linkItem, unlinkItem, and related functions with proper TypeScript signatures - Update all function calls and tests to include user parameter - Ensure proper null safety with user ?? undefined pattern 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/src/Components/AppShell/UserControl.tsx | 26 ++++++++----------- .../Subcomponents/Controls/LocateControl.tsx | 2 +- .../Map/Subcomponents/ItemFormPopup.tsx | 14 +++++++--- lib/src/Components/Map/hooks/useMyProfile.ts | 9 +++---- .../Map/hooks/useSelectPosition.tsx | 9 ++++--- .../Components/Profile/ItemFunctions.spec.tsx | 10 +++++-- lib/src/Components/Profile/ProfileForm.tsx | 4 +-- lib/src/Components/Profile/ProfileView.tsx | 6 +++-- lib/src/Components/Profile/itemFunctions.ts | 17 ++++++++---- 9 files changed, 59 insertions(+), 38 deletions(-) diff --git a/lib/src/Components/AppShell/UserControl.tsx b/lib/src/Components/AppShell/UserControl.tsx index 7c2902ae..c951d372 100644 --- a/lib/src/Components/AppShell/UserControl.tsx +++ b/lib/src/Components/AppShell/UserControl.tsx @@ -1,10 +1,9 @@ import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon' -import { useState, useEffect } from 'react' import { Link } from 'react-router-dom' import { toast } from 'react-toastify' import { useAuth } from '#components/Auth/useAuth' -import { useItems } from '#components/Map/hooks/useItems' +import { useMyProfile } from '#components/Map/hooks/useMyProfile' import { useAppState } from './hooks/useAppState' @@ -13,17 +12,14 @@ import type { Item } from '#types/Item' export const UserControl = () => { const { isAuthenticated, user, logout } = useAuth() const appState = useAppState() + const { myProfile } = useMyProfile() - const [userProfile, setUserProfile] = useState({} as Item) - const items = useItems() - - useEffect(() => { - const profile = - user && items.find((i) => i.user_created?.id === user.id && i.layer?.userProfileLayer) - profile - ? setUserProfile(profile) - : setUserProfile({ id: 'new', name: user?.first_name ?? '', text: '' }) - }, [user, items]) + // Use myProfile or create a fallback object for display + const userProfile: Partial = myProfile ?? { + id: 'new', + name: user?.first_name ?? '', + text: '', + } const onLogout = async () => { await toast.promise(logout(), { @@ -52,7 +48,7 @@ export const UserControl = () => { {isAuthenticated ? (
{avatar && ( @@ -62,7 +58,7 @@ export const UserControl = () => {
)} -
{userProfile.name || user?.first_name}
+
{userProfile.name ?? user?.first_name}