mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-12 23:36:00 +00:00
adjust UserControl for external profiles and small item edits (#363)
This commit is contained in:
parent
659efc0d5e
commit
a49590243a
@ -1,9 +1,11 @@
|
|||||||
import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon'
|
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 { toast } from 'react-toastify'
|
||||||
|
|
||||||
import { useAuth } from '#components/Auth/useAuth'
|
import { useAuth } from '#components/Auth/useAuth'
|
||||||
import { useMyProfile } from '#components/Map/hooks/useMyProfile'
|
import { useMyProfile } from '#components/Map/hooks/useMyProfile'
|
||||||
|
import { usePopupForm } from '#components/Map/hooks/usePopupForm'
|
||||||
|
|
||||||
import { useAppState } from './hooks/useAppState'
|
import { useAppState } from './hooks/useAppState'
|
||||||
|
|
||||||
@ -13,6 +15,8 @@ export const UserControl = () => {
|
|||||||
const { isAuthenticated, user, logout } = useAuth()
|
const { isAuthenticated, user, logout } = useAuth()
|
||||||
const appState = useAppState()
|
const appState = useAppState()
|
||||||
const { myProfile } = useMyProfile()
|
const { myProfile } = useMyProfile()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const { setPopupForm } = usePopupForm()
|
||||||
|
|
||||||
// Use myProfile or create a fallback object for display
|
// Use myProfile or create a fallback object for display
|
||||||
const userProfile: Partial<Item> = myProfile ?? {
|
const userProfile: Partial<Item> = myProfile ?? {
|
||||||
@ -38,6 +42,32 @@ export const UserControl = () => {
|
|||||||
pending: 'logging out ..',
|
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 =
|
const avatar: string | undefined =
|
||||||
userProfile.image && appState.assetsApi.url
|
userProfile.image && appState.assetsApi.url
|
||||||
? appState.assetsApi.url + userProfile.image
|
? appState.assetsApi.url + userProfile.image
|
||||||
@ -48,7 +78,13 @@ export const UserControl = () => {
|
|||||||
{isAuthenticated ? (
|
{isAuthenticated ? (
|
||||||
<div className='tw:flex tw:mr-2'>
|
<div className='tw:flex tw:mr-2'>
|
||||||
<Link
|
<Link
|
||||||
to={userProfile.id ? `/item/${userProfile.id}` : '#'}
|
to={
|
||||||
|
userProfile.id
|
||||||
|
? myProfile?.layer?.itemType.custom_profile_url
|
||||||
|
? `/${userProfile.id}`
|
||||||
|
: `/item/${userProfile.id}`
|
||||||
|
: '#'
|
||||||
|
}
|
||||||
className='tw:flex tw:items-center'
|
className='tw:flex tw:items-center'
|
||||||
>
|
>
|
||||||
{avatar && (
|
{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!'
|
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!'
|
||||||
>
|
>
|
||||||
<li>
|
<li>
|
||||||
<Link to={userProfile.id ? `/edit-item/${userProfile.id}` : '#'}>Profile</Link>
|
<a
|
||||||
|
onClick={() => {
|
||||||
|
handleEdit()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Profile
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<Link to={'/user-settings'}>Settings</Link>
|
<Link to={'/user-settings'}>Settings</Link>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user