From 6035e503d0b36960066e4450dd38c708a3ca6a19 Mon Sep 17 00:00:00 2001 From: Eugen Ciur Date: Sat, 3 Aug 2024 09:10:45 +0200 Subject: [PATCH] basic search sort of works! --- .../components/Breadcrumbs/Breadcrumbs.tsx | 8 +-- .../components/SearchResults/Breadcrumb.tsx | 62 +++++++++++++++++-- ui2/src/utils.ts | 7 +++ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/ui2/src/components/Breadcrumbs/Breadcrumbs.tsx b/ui2/src/components/Breadcrumbs/Breadcrumbs.tsx index d1e552067..e03430546 100644 --- a/ui2/src/components/Breadcrumbs/Breadcrumbs.tsx +++ b/ui2/src/components/Breadcrumbs/Breadcrumbs.tsx @@ -22,6 +22,7 @@ import type {RootState} from "@/app/types" import PanelContext from "@/contexts/PanelContext" import {selectCurrentUser} from "@/slices/currentUser" +import {equalUUIDs} from "@/utils" type Args = { onClick: (node: NType) => void @@ -148,10 +149,3 @@ function RootItem({itemId, onClick}: RootItemArgs) { ) } - -function equalUUIDs(id1: string, id2: string): boolean { - const i1 = id1.replace(/\-/g, "") - const i2 = id2.replace(/\-/g, "") - - return i1 == i2 -} diff --git a/ui2/src/components/SearchResults/Breadcrumb.tsx b/ui2/src/components/SearchResults/Breadcrumb.tsx index e223f17c1..dd385ae07 100644 --- a/ui2/src/components/SearchResults/Breadcrumb.tsx +++ b/ui2/src/components/SearchResults/Breadcrumb.tsx @@ -1,5 +1,10 @@ -import {Breadcrumbs, Anchor} from "@mantine/core" -import type {NType} from "@/types" +import {Breadcrumbs, Anchor, Skeleton, Group} from "@mantine/core" +import {useSelector} from "react-redux" +import {selectCurrentUser} from "@/slices/currentUser" +import {equalUUIDs} from "@/utils" +import {IconHome, IconInbox} from "@tabler/icons-react" + +import type {NType, UserDetails} from "@/types" type Args = { items: Array<[string, string]> @@ -7,10 +12,59 @@ type Args = { } export default function Path({items, onClick}: Args) { - const links = items.map(i => ( + if (items.length == 1) { + return ( + + + + ) + } + const links = items.slice(1).map(i => ( onClick({id: i[0], ctype: "folder"})} key={i[0]}> {i[1]} )) - return {links} + return ( + + + {links} + + ) +} + +type RootItemArgs = { + itemId: string + onClick: (n: NType) => void +} + +function RootItem({itemId, onClick}: RootItemArgs) { + const user = useSelector(selectCurrentUser) as UserDetails | undefined + + const onLocalClick = (id: string) => { + onClick({id: id, ctype: "folder"}) + } + + if (!user) { + return Home + } + + if (equalUUIDs(itemId, user.home_folder_id)) { + return ( + onLocalClick(user.home_folder_id)}> + + + Home + + + ) + } + + return ( + onLocalClick(user.inbox_folder_id)}> + + + Inbox + + + ) } diff --git a/ui2/src/utils.ts b/ui2/src/utils.ts index 77e6c91ef..be977192a 100644 --- a/ui2/src/utils.ts +++ b/ui2/src/utils.ts @@ -129,3 +129,10 @@ export function makeRandomString(length: number): string { } return result } + +export function equalUUIDs(id1: string, id2: string): boolean { + const i1 = id1.replace(/\-/g, "") + const i2 = id2.replace(/\-/g, "") + + return i1 == i2 +}