Skip to content

Commit

Permalink
basic search sort of works!
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Aug 3, 2024
1 parent 68c59c9 commit 6035e50
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
8 changes: 1 addition & 7 deletions ui2/src/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,10 +149,3 @@ function RootItem({itemId, onClick}: RootItemArgs) {
</Group>
)
}

function equalUUIDs(id1: string, id2: string): boolean {
const i1 = id1.replace(/\-/g, "")
const i2 = id2.replace(/\-/g, "")

return i1 == i2
}
62 changes: 58 additions & 4 deletions ui2/src/components/SearchResults/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,70 @@
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]>
onClick: (n: NType) => void
}

export default function Path({items, onClick}: Args) {
const links = items.map(i => (
if (items.length == 1) {
return (
<Breadcrumbs>
<RootItem itemId={items[0][0]} onClick={onClick} />
</Breadcrumbs>
)
}
const links = items.slice(1).map(i => (
<Anchor onClick={() => onClick({id: i[0], ctype: "folder"})} key={i[0]}>
{i[1]}
</Anchor>
))
return <Breadcrumbs>{links}</Breadcrumbs>
return (
<Breadcrumbs>
<RootItem itemId={items[0][0]} onClick={onClick} />
{links}
</Breadcrumbs>
)
}

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 <Skeleton>Home</Skeleton>
}

if (equalUUIDs(itemId, user.home_folder_id)) {
return (
<Anchor onClick={() => onLocalClick(user.home_folder_id)}>
<Group>
<IconHome />
Home
</Group>
</Anchor>
)
}

return (
<Anchor onClick={() => onLocalClick(user.inbox_folder_id)}>
<Group>
<IconInbox />
Inbox
</Group>
</Anchor>
)
}
7 changes: 7 additions & 0 deletions ui2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 6035e50

Please sign in to comment.