Skip to content

Commit a225fe3

Browse files
skeptrunedevdensumesh
authored andcommitted
feature: yt previews in search component
1 parent a07437b commit a225fe3

File tree

4 files changed

+71
-26
lines changed

4 files changed

+71
-26
lines changed

clients/search-component/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"import": "./dist/vanilla/index.js"
2020
}
2121
},
22-
"version": "0.2.39",
22+
"version": "0.2.40",
2323
"license": "MIT",
2424
"homepage": "https://github.com/devflowinc/trieve/tree/main/clients/search-component",
2525
"scripts": {

clients/search-component/src/TrieveModal/Chat/ChatMessage.tsx

+25-16
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const Message = ({
8787
const [positive, setPositive] = React.useState<boolean | null>(null);
8888
const [copied, setCopied] = React.useState<boolean>(false);
8989
const { props } = useModalState();
90-
90+
9191
const ecommerceItems = message.additional
9292
?.filter(
9393
(chunk) =>
@@ -184,25 +184,34 @@ export const Message = ({
184184
chunk.metadata.page_title) &&
185185
chunk.link
186186
)
187-
.map((chunk) => [
188-
chunk.metadata.heading ||
189-
chunk.metadata.title ||
190-
chunk.metadata.page_title,
191-
chunk.link,
192-
])
193-
.filter(
194-
(link, index, array) =>
195-
array.findIndex((item) => item[0] === link[0]) ===
196-
index && link[0]
197-
)
198-
.map((link, index) => (
187+
.map((chunk) => {
188+
return {
189+
title:
190+
chunk.metadata.heading ||
191+
chunk.metadata.title ||
192+
chunk.metadata.page_title,
193+
link: chunk.link,
194+
metadata: chunk.metadata,
195+
};
196+
})
197+
.map((item, index) => (
199198
<a
200-
className="source-anchor"
199+
className={`source-anchor${
200+
item.metadata?.yt_preview_src ? " yt-anchor" : ""
201+
}`}
201202
key={index}
202-
href={link[1] as string}
203+
href={item.link as string}
203204
target="_blank"
204205
>
205-
{link[0]}
206+
{item.metadata?.yt_preview_src ? (
207+
<img
208+
className="yt-preview"
209+
src={item.metadata?.yt_preview_src}
210+
/>
211+
) : (
212+
<></>
213+
)}
214+
{item.title}
206215
</a>
207216
))}
208217
</div>

clients/search-component/src/TrieveModal/Search/DocsItem.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,24 @@ export const DocsItem = ({ item, requestID, index, className }: Props) => {
170170
}
171171
: {})}
172172
>
173-
<div>
173+
<div className="docs-item-container">
174+
{item.chunk.metadata?.yt_preview_src ? (
175+
<img
176+
className="yt-preview"
177+
src={item.chunk.metadata?.yt_preview_src}
178+
/>
179+
) : (
180+
<></>
181+
)}
174182
{title ? (
175-
<div>
183+
<div className="docs-chunk-html">
176184
{props.type === "docs" ? (
177185
<h6 className="chunk-path">{getChunkPath()}</h6>
178186
) : null}
179187
<h4
180-
className={`chunk-title ${props.type}`}
188+
className={`chunk-title ${props.type}${
189+
item.chunk.metadata?.yt_preview_src ? " yt-item" : ""
190+
}`}
181191
dangerouslySetInnerHTML={{
182192
__html: title,
183193
}}

clients/search-component/src/TrieveModal/index.css

+32-6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ body {
130130
.mode-switch-wrapper {
131131
@apply flex items-center justify-end mt-2 absolute top-2.5 right-4 z-30 font-medium;
132132

133+
&.docs.chat {
134+
@apply top-0;
135+
136+
right: calc(max(calc(50% - 39.85rem), 4rem) + 0.25rem);
137+
}
138+
133139
&.search.has-query {
134140
@apply hidden;
135141
}
@@ -306,6 +312,14 @@ body {
306312
@apply rounded px-2 text-xs py-1 bg-zinc-200/50;
307313
color: var(--tv-zinc-950);
308314

315+
&.yt-anchor {
316+
@apply max-w-44 text-center pt-3;
317+
}
318+
319+
.yt-preview {
320+
@apply h-16 w-28 block mx-auto;
321+
}
322+
309323
&:hover {
310324
background-color: var(--tv-zinc-200);
311325
}
@@ -641,11 +655,7 @@ body {
641655
}
642656
}
643657

644-
.close-modal-button:not(.ecommerce) {
645-
@apply hidden;
646-
}
647-
648-
.close-modal-button.ecommerce {
658+
.close-modal-button {
649659
@apply w-full flex justify-end text-xs items-center absolute top-1 right-1.5 p-2 gap-0.5 cursor-pointer;
650660
}
651661

@@ -753,6 +763,18 @@ body {
753763
}
754764
}
755765

766+
.docs-item-container {
767+
@apply flex gap-x-4 w-full justify-start;
768+
769+
.docs-chunk-html {
770+
@apply w-full;
771+
}
772+
}
773+
774+
.yt-preview {
775+
@apply h-16 w-28 block;
776+
}
777+
756778
.chunk-path {
757779
color: var(--tv-zinc-600);
758780
@apply text-xs line-clamp-1 overflow-ellipsis;
@@ -791,7 +813,11 @@ body {
791813
}
792814

793815
h4 {
794-
@apply overflow-hidden whitespace-nowrap text-ellipsis max-w-[calc(90vw-45px)] sm:max-w-[450px];
816+
@apply overflow-hidden whitespace-nowrap text-ellipsis max-w-[calc(90vw-45px)] sm:max-w-[590px];
817+
818+
&.yt-item {
819+
@apply max-w-[calc(90vw-45px-7rem)] sm:max-w-[590px];
820+
}
795821
}
796822

797823
svg {

0 commit comments

Comments
 (0)