mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-03-01 12:44:17 +00:00
fix linting and secret loading
This commit is contained in:
parent
33eecedd5d
commit
f8979ed508
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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,
|
||||
},
|
||||
],
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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}
|
||||
|
||||
4
lib/src/types/Item.d.ts
vendored
4
lib/src/types/Item.d.ts
vendored
@ -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
|
||||
|
||||
// {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user