mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Fix relations view
This commit is contained in:
parent
f57989a84f
commit
3eb6d8a76b
@ -1,6 +1,9 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
import { useItems } from '#components/Map/hooks/useItems'
|
||||
|
||||
import type { Item } from '#types/Item'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
interface Props {
|
||||
item: Item
|
||||
@ -10,22 +13,28 @@ interface Props {
|
||||
export const RelationsView = ({ item, relation }: Props) => {
|
||||
const items = useItems()
|
||||
|
||||
useEffect(() => {
|
||||
console.log(relatedItems)
|
||||
}, [])
|
||||
|
||||
if (!item.relations) return
|
||||
|
||||
const relationsOfRightType = item.relations.filter((r) => r.type === relation)
|
||||
|
||||
const relatedItems = items.filter((i) => relationsOfRightType.some((r) => r.id === i.id))
|
||||
const relatedItems = items.filter((i) =>
|
||||
relationsOfRightType.some((r) => r.related_items_id === i.id),
|
||||
)
|
||||
|
||||
const hasRelatedItems = relatedItems.length > 0
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>{relation}</h2>
|
||||
<div className='tw:my-10 tw:mt-2 tw:px-6'>
|
||||
<h2 className='tw:text-lg tw:font-bold'>{relation}</h2>
|
||||
{hasRelatedItems ? (
|
||||
<ul>
|
||||
{relatedItems.map((relatedItem) => (
|
||||
<li key={relatedItem.id}>
|
||||
<a href={`/item/${relatedItem.id}`}>{relatedItem.name}</a>
|
||||
<Link to={`/item/${relatedItem.id}`}>{relatedItem.name}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user