Skip to content

Commit 934e3a6

Browse files
skeptrunedevcdxker
authored andcommitted
feature: rearrange images to display horizontally and make the section collapsable
1 parent da86ea4 commit 934e3a6

File tree

3 files changed

+86
-12
lines changed

3 files changed

+86
-12
lines changed

frontends/chat/src/components/ScoreChunk.tsx

+55-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-argument */
22
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
33
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
4-
import { For, Show, createMemo, createSignal, Switch, Match } from "solid-js";
54
import {
5+
For,
6+
Show,
7+
createMemo,
8+
createSignal,
9+
Switch,
10+
Match,
11+
createEffect,
12+
} from "solid-js";
13+
import {
14+
ChunkMetadata,
15+
indirectHasOwnProperty,
616
type ChunkBookmarksDTO,
717
type ChunkCollectionDTO,
8-
type ChunkMetadataWithVotes,
918
} from "../utils/apiTypes";
1019
import { BiRegularChevronDown, BiRegularChevronUp } from "solid-icons/bi";
1120
import sanitizeHtml from "sanitize-html";
1221
import { AiOutlineCopy } from "solid-icons/ai";
13-
import { FiCheck, FiExternalLink } from "solid-icons/fi";
22+
import {
23+
FiCheck,
24+
FiChevronDown,
25+
FiChevronUp,
26+
FiExternalLink,
27+
} from "solid-icons/fi";
1428

1529
export const sanitzerOptions = {
1630
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
@@ -40,7 +54,7 @@ export interface ScoreChunkProps {
4054
chunkCollections: ChunkCollectionDTO[];
4155
totalCollectionPages: number;
4256
collection?: boolean;
43-
chunk: ChunkMetadataWithVotes;
57+
chunk: ChunkMetadata;
4458
counter: string;
4559
order?: string;
4660
initialExpanded?: boolean;
@@ -70,6 +84,8 @@ const ScoreChunk = (props: ScoreChunkProps) => {
7084
const [expanded, setExpanded] = createSignal(props.initialExpanded ?? false);
7185
const [copied, setCopied] = createSignal(false);
7286
const [expandMetadata, setExpandMetadata] = createSignal(false);
87+
const [showImages, setShowImages] = createSignal(true);
88+
const [imageLinks, setImageLinks] = createSignal<string[] | null>(null);
7389

7490
const copyChunk = () => {
7591
try {
@@ -98,6 +114,17 @@ const ScoreChunk = (props: ScoreChunkProps) => {
98114
}
99115
};
100116

117+
createEffect(() => {
118+
if (
119+
!props.chunk.metadata ||
120+
!indirectHasOwnProperty(props.chunk, "image_urls")
121+
) {
122+
return null;
123+
}
124+
125+
setImageLinks(props.chunk.image_urls);
126+
});
127+
101128
const useExpand = createMemo(() => {
102129
if (!props.chunk.chunk_html) return false;
103130
return props.chunk.chunk_html.split(" ").length > 20 * linesBeforeShowMore;
@@ -202,6 +229,30 @@ const ScoreChunk = (props: ScoreChunkProps) => {
202229
</span>
203230
</div>
204231
</Show>
232+
<Show when={imageLinks() != null}>
233+
<button
234+
class="mt-2 flex w-fit items-center space-x-1 rounded-md border bg-neutral-200/50 px-2 py-1 font-semibold text-magenta-500 hover:bg-neutral-200/90 dark:bg-neutral-700/60 dark:text-magenta-400"
235+
onClick={() => setShowImages((prev) => !prev)}
236+
>
237+
<Switch>
238+
<Match when={showImages()}>
239+
Collapse Images <FiChevronUp class="h-5 w-5" />
240+
</Match>
241+
<Match when={!showImages()}>
242+
Expand Images <FiChevronDown class="h-5 w-5" />
243+
</Match>
244+
</Switch>
245+
</button>
246+
<Show when={showImages()}>
247+
<div class="my-2 flex space-x-2 overflow-x-auto rounded-md pl-2">
248+
<For each={imageLinks() ?? []}>
249+
{(link) => (
250+
<img class="w-40 rounded-md" src={link ?? ""} alt={link} />
251+
)}
252+
</For>
253+
</div>
254+
</Show>
255+
</Show>
205256
<Show when={Object.keys(props.chunk.metadata ?? {}).length > 0}>
206257
<button
207258
class="mt-2 flex w-fit items-center space-x-1 rounded-md border bg-neutral-200/50 px-2 py-1 font-semibold text-magenta-500 hover:bg-neutral-200/90 dark:bg-neutral-700/60 dark:text-magenta-400"

frontends/chat/src/utils/apiTypes.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ export interface ChunkMetadata {
88
tag_set: string[] | null;
99
tracking_id: string | null;
1010
time_stamp: string | null;
11-
file_id: string | null;
12-
file_name: string | null;
1311
metadata: Record<string, never> | null;
14-
weight: number | null;
12+
dataset_id: string;
13+
weight: number;
1514
location: {
1615
lat: number;
1716
lon: number;
1817
} | null;
1918
num_value: number | null;
20-
dataset_id: string;
19+
image_urls: string[] | null;
2120
}
2221

2322
export const indirectHasOwnProperty = (obj: unknown, prop: string): boolean => {

frontends/search/src/components/ScoreChunk.tsx

+28-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "../utils/apiTypes";
2525
import { BiRegularChevronDown, BiRegularChevronUp } from "solid-icons/bi";
2626
import BookmarkPopover from "./BookmarkPopover";
27-
import { FiEye } from "solid-icons/fi";
27+
import { FiChevronDown, FiChevronUp, FiEye } from "solid-icons/fi";
2828
import sanitizeHtml from "sanitize-html";
2929
import { FiEdit, FiTrash } from "solid-icons/fi";
3030
import { Tooltip } from "shared/ui";
@@ -94,6 +94,7 @@ const ScoreChunk = (props: ScoreChunkProps) => {
9494
const [expandMetadata, setExpandMetadata] = createSignal(
9595
props.defaultShowMetadata ?? false,
9696
);
97+
const [showImages, setShowImages] = createSignal(true);
9798
const [imageLinks, setImageLinks] = createSignal<string[] | null>(null);
9899

99100
createEffect(() => {
@@ -406,9 +407,32 @@ const ScoreChunk = (props: ScoreChunkProps) => {
406407
</div>
407408
</Show>
408409
<Show when={imageLinks() != null}>
409-
<For each={imageLinks() ?? []}>
410-
{(link) => <img class="w-40" src={link ?? ""} alt={link} />}
411-
</For>
410+
<button
411+
class="mt-2 flex w-fit items-center space-x-1 rounded-md border bg-neutral-200/50 px-2 py-1 font-semibold text-magenta-500 hover:bg-neutral-200/90 dark:bg-neutral-700/60 dark:text-magenta-400"
412+
onClick={() => setShowImages((prev) => !prev)}
413+
>
414+
<Switch>
415+
<Match when={showImages()}>
416+
Collapse Images <FiChevronUp class="h-5 w-5" />
417+
</Match>
418+
<Match when={!showImages()}>
419+
Expand Images <FiChevronDown class="h-5 w-5" />
420+
</Match>
421+
</Switch>
422+
</button>
423+
<Show when={showImages()}>
424+
<div class="my-2 flex space-x-2 overflow-x-auto rounded-md pl-2">
425+
<For each={imageLinks() ?? []}>
426+
{(link) => (
427+
<img
428+
class="w-40 rounded-md"
429+
src={link ?? ""}
430+
alt={link}
431+
/>
432+
)}
433+
</For>
434+
</div>
435+
</Show>
412436
</Show>
413437
<Show when={Object.keys(props.chunk.metadata ?? {}).length > 0}>
414438
<button

0 commit comments

Comments
 (0)