just open profile when item exist and loaded

This commit is contained in:
Anton Tranelis 2024-07-31 21:29:52 +02:00
parent 216dbc1b79
commit 0a3f752ab1

View File

@ -19,7 +19,7 @@ import { useTags } from '../Map/hooks/useTags';
export function ProfileView({ userType }: { userType: string }) {
const [item, setItem] = useState<Item>({} as Item)
const [item, setItem] = useState<Item>()
const [updatePermission, setUpdatePermission] = useState<boolean>(false);
const [relations, setRelations] = useState<Array<Item>>([]);
const [offers, setOffers] = useState<Array<Tag>>([]);
@ -51,15 +51,15 @@ export function ProfileView({ userType }: { userType: string }) {
setNeeds([]);
setRelations([]);
item.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => {
item?.layer?.itemOffersField && getValue(item, item.layer.itemOffersField)?.map(o => {
const tag = tags.find(t => t.id === o.tags_id);
tag && setOffers(current => [...current, tag])
})
item.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => {
item?.layer?.itemNeedsField && getValue(item, item.layer.itemNeedsField)?.map(n => {
const tag = tags.find(t => t.id === n.tags_id);
tag && setNeeds(current => [...current, tag])
})
item.relations?.map(r => {
item?.relations?.map(r => {
const item = items.find(i => i.id == r.related_items_id)
item && setRelations(current => [...current, item])
})
@ -116,7 +116,7 @@ export function ProfileView({ userType }: { userType: string }) {
}, [selectPosition])
useEffect(() => {
setTemplate(item.layer?.itemType.template || userType);
setTemplate(item?.layer?.itemType.template || userType);
}, [userType, item])
const [urlParams, setUrlParams] = useState(new URLSearchParams(location.search));
@ -124,7 +124,7 @@ export function ProfileView({ userType }: { userType: string }) {
return (
<>
{item &&
{item &&
<MapOverlayPage key={item.id} className={`!tw-p-0 tw-mx-4 tw-mt-4 tw-mb-4 md:tw-w-[calc(50%-32px)] tw-w-[calc(100%-32px)] tw-min-w-80 tw-max-w-3xl !tw-left-0 sm:!tw-left-auto tw-top-0 tw-bottom-0 tw-transition-opacity tw-duration-500 ${!selectPosition ? 'tw-opacity-100 tw-pointer-events-auto' : 'tw-opacity-0 tw-pointer-events-none'}`}>
<>
<div className={`tw-px-6 tw-pt-6`}>