|
1 | 1 | /* eslint-disable @typescript-eslint/no-unsafe-argument */
|
2 | 2 | /* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
3 | 3 | /* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
4 |
| -import { For, Show, createMemo, createSignal, Switch, Match } from "solid-js"; |
5 | 4 | 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, |
6 | 16 | type ChunkBookmarksDTO,
|
7 | 17 | type ChunkCollectionDTO,
|
8 |
| - type ChunkMetadataWithVotes, |
9 | 18 | } from "../utils/apiTypes";
|
10 | 19 | import { BiRegularChevronDown, BiRegularChevronUp } from "solid-icons/bi";
|
11 | 20 | import sanitizeHtml from "sanitize-html";
|
12 | 21 | 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"; |
14 | 28 |
|
15 | 29 | export const sanitzerOptions = {
|
16 | 30 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
@@ -40,7 +54,7 @@ export interface ScoreChunkProps {
|
40 | 54 | chunkCollections: ChunkCollectionDTO[];
|
41 | 55 | totalCollectionPages: number;
|
42 | 56 | collection?: boolean;
|
43 |
| - chunk: ChunkMetadataWithVotes; |
| 57 | + chunk: ChunkMetadata; |
44 | 58 | counter: string;
|
45 | 59 | order?: string;
|
46 | 60 | initialExpanded?: boolean;
|
@@ -70,6 +84,8 @@ const ScoreChunk = (props: ScoreChunkProps) => {
|
70 | 84 | const [expanded, setExpanded] = createSignal(props.initialExpanded ?? false);
|
71 | 85 | const [copied, setCopied] = createSignal(false);
|
72 | 86 | const [expandMetadata, setExpandMetadata] = createSignal(false);
|
| 87 | + const [showImages, setShowImages] = createSignal(true); |
| 88 | + const [imageLinks, setImageLinks] = createSignal<string[] | null>(null); |
73 | 89 |
|
74 | 90 | const copyChunk = () => {
|
75 | 91 | try {
|
@@ -98,6 +114,17 @@ const ScoreChunk = (props: ScoreChunkProps) => {
|
98 | 114 | }
|
99 | 115 | };
|
100 | 116 |
|
| 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 | + |
101 | 128 | const useExpand = createMemo(() => {
|
102 | 129 | if (!props.chunk.chunk_html) return false;
|
103 | 130 | return props.chunk.chunk_html.split(" ").length > 20 * linesBeforeShowMore;
|
@@ -202,6 +229,30 @@ const ScoreChunk = (props: ScoreChunkProps) => {
|
202 | 229 | </span>
|
203 | 230 | </div>
|
204 | 231 | </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> |
205 | 256 | <Show when={Object.keys(props.chunk.metadata ?? {}).length > 0}>
|
206 | 257 | <button
|
207 | 258 | 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"
|
|
0 commit comments