From 818d9a0c5c6eac0aabc5fa14a3aa9249f3a80b02 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Sat, 13 Sep 2025 21:39:26 +0200 Subject: [PATCH] bidirectional direction --- .../Profile/Subcomponents/RelationsView.tsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/src/Components/Profile/Subcomponents/RelationsView.tsx b/lib/src/Components/Profile/Subcomponents/RelationsView.tsx index 47ef365a..058f9e40 100644 --- a/lib/src/Components/Profile/Subcomponents/RelationsView.tsx +++ b/lib/src/Components/Profile/Subcomponents/RelationsView.tsx @@ -9,7 +9,7 @@ interface Props { item: Item relation: string heading: string - direction?: 'outgoing' | 'ingoing' + direction?: 'outgoing' | 'ingoing' | 'bidirectional' hideWhenEmpty?: boolean } @@ -27,12 +27,30 @@ export const RelationsView = ({ const relationsOfRightType = item.relations.filter((r) => r.type === relation) - 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 relatedItems = (() => { + const outgoingItems = items.filter((i) => + relationsOfRightType.some((r) => r.related_items_id === i.id), + ) + + const ingoingItems = items.filter((i) => + i.relations?.some((r) => r.type === relation && r.related_items_id === item.id), + ) + + switch (direction) { + case 'outgoing': + return outgoingItems + case 'ingoing': + return ingoingItems + case 'bidirectional': + // Combine both arrays and remove duplicates + const allItems = [...outgoingItems, ...ingoingItems] + return allItems.filter((item, index, self) => + index === self.findIndex(i => i.id === item.id) ) + default: + return outgoingItems + } + })() const hasRelatedItems = relatedItems.length > 0