From f3876fd990d606d88406ba7086e9dea61d342193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Thu, 15 Aug 2024 00:53:16 +0300 Subject: [PATCH] feat: removed subview for nodes with only name prop --- src/components/App/SideBar/index.tsx | 17 ++++++++++++++++- src/components/Universe/Graph/Cubes/index.tsx | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/App/SideBar/index.tsx b/src/components/App/SideBar/index.tsx index e9fdf2bbb..5c756ad9a 100644 --- a/src/components/App/SideBar/index.tsx +++ b/src/components/App/SideBar/index.tsx @@ -43,11 +43,26 @@ const Content = forwardRef(({ subViewOpen }, ref) = const hideSubViewFor = ['topic', 'person', 'guest', 'event', 'organization', 'place', 'project', 'software'] +const hasOnlyNameProperty = (obj: object | null | undefined): boolean => { + if (obj === undefined || obj === null) { + return false + } + + const keys = Object.keys(obj) + const nonEmptyKeys = keys.filter((key) => key !== 'pubkey') + + return nonEmptyKeys.length === 1 && nonEmptyKeys[0] === 'name' +} + export const SideBar = () => { const { sidebarIsOpen } = useAppStore((s) => s) const selectedNode = useSelectedNode() - const subViewIsOpen = !!selectedNode && sidebarIsOpen && !hideSubViewFor.includes(selectedNode.node_type) + const subViewIsOpen = + !!selectedNode && + sidebarIsOpen && + !hideSubViewFor.includes(selectedNode.node_type) && + !hasOnlyNameProperty(selectedNode.properties) return ( <> diff --git a/src/components/Universe/Graph/Cubes/index.tsx b/src/components/Universe/Graph/Cubes/index.tsx index 5aceb5a66..6e221fd88 100644 --- a/src/components/Universe/Graph/Cubes/index.tsx +++ b/src/components/Universe/Graph/Cubes/index.tsx @@ -57,13 +57,14 @@ export const Cubes = memo(() => { (e: ThreeEvent) => { e.stopPropagation() setIsHovering(false) + setHoveredNode(null) if (hoverTimeoutRef.current) { clearTimeout(hoverTimeoutRef.current) hoverTimeoutRef.current = null } }, - [setIsHovering], + [setIsHovering, setHoveredNode], ) const onPointerIn = useCallback(