fix linting and secret loading

This commit is contained in:
Anton Tranelis 2025-12-17 09:27:35 +01:00
parent 33eecedd5d
commit f8979ed508
6 changed files with 20 additions and 22 deletions

View File

@ -34,10 +34,10 @@ export const useNavigationUrl = (coordinates?: [number, number]) => {
export const useShareLogic = (item?: Item) => {
const shareUrl = window.location.href
const shareTitle = item?.name ?? 'Utopia Map Item'
const inviteLink =
item?.secrets && item.secrets.length > 0
? `${window.location.origin}/invite/${item.secrets[0].secret}`
: shareUrl
const firstSecret = item?.secrets?.[0]
// Support both string secrets and object secrets with { secret: string }
const secretValue = typeof firstSecret === 'string' ? firstSecret : firstSecret?.secret
const inviteLink = secretValue ? `${window.location.origin}/invite/${secretValue}` : shareUrl
const copyLink = () => {
navigator.clipboard

View File

@ -32,6 +32,7 @@ export const useMyProfile = () => {
const retryDelay = 500 // ms
for (let i = 0; i < maxRetries; i++) {
// eslint-disable-next-line promise/avoid-new
await new Promise((resolve) => setTimeout(resolve, retryDelay))
const reloaded = await layer.api?.getItem?.(itemId)
if (reloaded?.secrets && reloaded.secrets.length > 0) {
@ -45,19 +46,16 @@ export const useMyProfile = () => {
}
// Automatically reload profile if secrets are missing (e.g., after signup)
const hasSecrets = myProfile?.secrets && myProfile.secrets.length > 0
useEffect(() => {
if (
myProfile?.layer?.api?.getItem &&
(!myProfile.secrets || myProfile.secrets.length === 0) &&
!isReloadingSecretRef.current
) {
if (myProfile?.layer?.api?.getItem && !hasSecrets && !isReloadingSecretRef.current) {
isReloadingSecretRef.current = true
void reloadItemWithSecret(myProfile.id, myProfile.layer, myProfile).finally(() => {
isReloadingSecretRef.current = false
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [myProfile?.id, myProfile?.secrets?.length])
}, [myProfile?.id, hasSecrets])
const createEmptyProfile = async () => {
if (!user) return
@ -76,9 +74,9 @@ export const useMyProfile = () => {
const newItem = {
...serverResponse,
user_created: user,
user_created: user, // eslint-disable-line camelcase
layer: userLayer,
public_edit: false,
public_edit: false, // eslint-disable-line camelcase
}
// Add item immediately (without secret)

View File

@ -76,6 +76,7 @@ export function InvitePage({ inviteApi, itemsApi }: Props) {
{
type: 'is_following',
direction: 'outgoing',
// eslint-disable-next-line camelcase
related_items_id: invitingProfile.id,
},
],

View File

@ -8,7 +8,12 @@ export const InviteLinkView = ({ item }: { item: Item }) => {
// Only show if user has permission to view secrets.
if (!item.secrets || item.secrets.length === 0) return
const link = `${window.location.origin}/invite/${item.secrets[0].secret}`
const firstSecret = item.secrets[0]
// Support both string secrets and object secrets with { secret: string }
const secretValue = typeof firstSecret === 'string' ? firstSecret : firstSecret.secret
if (!secretValue) return
const link = `${window.location.origin}/invite/${secretValue}`
const copyToClipboard = () => {
void navigator.clipboard

View File

@ -1,9 +1,7 @@
import { MapPinIcon } from '@heroicons/react/24/solid'
import { Link } from 'react-router-dom'
import { useAppState } from '#components/AppShell/hooks/useAppState'
import { useItems } from '#components/Map/hooks/useItems'
import { useReverseGeocode } from '#components/Map/hooks/useReverseGeocode'
import type { Item } from '#types/Item'
@ -19,12 +17,6 @@ function RelationCard({ item }: { item: Item }) {
const appState = useAppState()
const avatar = item.image ? appState.assetsApi.url + item.image : null
const { address } = useReverseGeocode(
item.position?.coordinates as [number, number] | undefined,
true,
'municipality',
)
return (
<Link
to={item.id}

View File

@ -22,6 +22,8 @@ interface ItemSecret {
secret: string
}
type ItemSecretValue = ItemSecret | string
/**
* @category Types
*/
@ -60,7 +62,7 @@ export interface Item {
next_appointment?: string
gallery?: GalleryItem[]
openCollectiveSlug?: string
secrets?: ItemSecret[]
secrets?: ItemSecretValue[]
extended?: JSON
// {