diff --git a/lib/src/Components/Profile/Subcomponents/RelationsView.tsx b/lib/src/Components/Profile/Subcomponents/RelationsView.tsx index caffba3e..47ef365a 100644 --- a/lib/src/Components/Profile/Subcomponents/RelationsView.tsx +++ b/lib/src/Components/Profile/Subcomponents/RelationsView.tsx @@ -1,40 +1,67 @@ -import { useEffect } from 'react' +import { Link } from 'react-router-dom' +import { useAppState } from '#components/AppShell/hooks/useAppState' import { useItems } from '#components/Map/hooks/useItems' import type { Item } from '#types/Item' -import { Link } from 'react-router-dom' interface Props { item: Item relation: string + heading: string + direction?: 'outgoing' | 'ingoing' + hideWhenEmpty?: boolean } -export const RelationsView = ({ item, relation }: Props) => { +export const RelationsView = ({ + item, + relation, + heading, + direction = 'outgoing', + hideWhenEmpty = true, +}: Props) => { const items = useItems() - - useEffect(() => { - console.log(relatedItems) - }, []) + const appState = useAppState() if (!item.relations) return const relationsOfRightType = item.relations.filter((r) => r.type === relation) - const relatedItems = items.filter((i) => - relationsOfRightType.some((r) => r.related_items_id === i.id), - ) + const relatedItems = + direction === 'outgoing' + ? items.filter((i) => relationsOfRightType.some((r) => r.related_items_id === i.id)) + : items.filter((i) => + i.relations?.some((r) => r.type === relation && r.related_items_id === item.id), + ) const hasRelatedItems = relatedItems.length > 0 + if (hideWhenEmpty && !hasRelatedItems) { + return null + } + return (
-

{relation}

+

{heading}

{hasRelatedItems ? (