utopia-ui/lib/src/Components/Map/hooks/useMyProfile.ts
Anton Tranelis 6fcdef0433 fix(lib): ensure user_created is preserved in all item operations
- 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 <noreply@anthropic.com>
2025-08-20 18:55:02 +02:00

20 lines
588 B
TypeScript

import { useAuth } from '#components/Auth/useAuth'
import { useItems, useAllItemsLoaded } from './useItems'
export const useMyProfile = () => {
const items = useItems()
const allItemsLoaded = useAllItemsLoaded()
const { user } = useAuth()
// Find the user's profile item
const myProfile = items.find(
(item) => item.layer?.userProfileLayer && item.user_created?.id === user?.id,
)
// allItemsLoaded is not reliable, so we check if items.length > 0
const isMyProfileLoaded = allItemsLoaded && items.length > 0 && !!user
return { myProfile, isMyProfileLoaded }
}