Skip to content

Commit 28f474c

Browse files
committed
show document icon and make it a link in reusable components
1 parent 553fcf0 commit 28f474c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

apps/web/src/components/ReusableComponents.tsx

+18-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import type {
1616
} from '@briefer/database'
1717
import { addComponentToDocument, decodeComponentState } from '@briefer/editor'
1818
import ScrollBar from './ScrollBar'
19+
import Link from 'next/link'
20+
import allLucideIcons from '@/utils/lucideIcons'
21+
import * as allOutlineIcons from '@heroicons/react/24/outline'
22+
23+
const icons: Record<string, React.ComponentType<React.ComponentProps<any>>> = {
24+
...allOutlineIcons,
25+
...allLucideIcons,
26+
}
1927

2028
interface Props {
2129
workspaceId: string
@@ -24,7 +32,6 @@ interface Props {
2432
onHide: () => void
2533
yDoc?: Y.Doc
2634
}
27-
2835
export default function ReusableComponents(props: Props) {
2936
const [{ data, isLoading }, api] = useReusableComponents(props.workspaceId)
3037

@@ -152,6 +159,9 @@ function ReusableComponentItem(props: ReusableComponentItemProps) {
152159
props.onRemove(props.component)
153160
}, [props.onRemove, props.component])
154161

162+
const Icon =
163+
icons[props.component.document.icon ?? 'DocumentIcon'] || (() => null)
164+
155165
return (
156166
<div className="px-4 py-3 font-sans block w-full">
157167
<div className="flex flex-col">
@@ -178,7 +188,13 @@ function ReusableComponentItem(props: ReusableComponentItemProps) {
178188
<svg viewBox="0 0 2 2" className="h-0.5 w-0.5 fill-current">
179189
<circle cx={1} cy={1} r={1} />
180190
</svg>
181-
{props.component.document.title || 'Untitled'}
191+
<Link
192+
href={`/workspaces/${props.workspaceId}/documents/${props.component.document.id}`}
193+
className="flex items-center gap-x-1 text-gray-400 hover:text-gray-500"
194+
>
195+
<Icon className="h-3.5 w-3.5 shrink-0" aria-hidden="true" />
196+
{props.component.document.title || 'Untitled'}
197+
</Link>
182198
</div>
183199
<div className="flex items-center gap-x-2 font-medium text-gray-400 text-xs">
184200
Saved at{' '}

packages/database/src/components.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type APIReusableComponent = Omit<
1515
document: {
1616
id: string
1717
title: string
18+
icon: string
1819
}
1920
}
2021

@@ -28,6 +29,7 @@ export async function listReusableComponents(
2829
select: {
2930
id: true,
3031
title: true,
32+
icon: true,
3133
},
3234
},
3335
},

0 commit comments

Comments
 (0)