forge
Explore
Log in

Don't you dare go Hollow

♻️ note-file-preview Switch/Match replaces nested Show

Browse files at this commit

a00eb23fdf7b1cc15dc918fcffe8e98cbbb3017bBurak BoduroğluParent: 922f954
  • refactor
    • ♻️ note-file-preview Switch/Match replaces nested Show
Show full message
refactor: ♻️ note-file-preview Switch/Match replaces nested Show
src/components/notes/note-file-preview.tsxmodified+17 -15
@@ -1,4 +1,4 @@
1-import { Show, createEffect, createSignal, onCleanup } from "solid-js";1+import { Match, Show, Switch, createEffect, createSignal, onCleanup } from "solid-js";
2 import { formatApiError } from "@/api/client";2 import { formatApiError } from "@/api/client";
3 import { getNoteFileBlob } from "@/api/getNoteFileBlob";3 import { getNoteFileBlob } from "@/api/getNoteFileBlob";
4 import type { NoteFile } from "@/api/types";4 import type { NoteFile } from "@/api/types";
@@ -77,20 +77,22 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
77 fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{t("notes.previewUnsupported")}</p>}77 fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{t("notes.previewUnsupported")}</p>}
78 >78 >
79 <Show when={!previewError()} fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{previewError()}</p>}>79 <Show when={!previewError()} fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{previewError()}</p>}>
80- <Show when={type().startsWith("image/") && previewUrl()} fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>80+ <Switch fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>
81- <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />81+ <Match when={type().startsWith("image/") && previewUrl()}>
82- </Show>82+ <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />
83- <Show when={type().startsWith("video/") && previewUrl()}>83+ </Match>
84- <video src={previewUrl()} controls class="max-h-full max-w-full" />84+ <Match when={type().startsWith("video/") && previewUrl()}>
85- </Show>85+ <video src={previewUrl()} controls class="max-h-full max-w-full" />
86- <Show when={type().startsWith("audio/") && previewUrl()}>86+ </Match>
87- <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">87+ <Match when={type().startsWith("audio/") && previewUrl()}>
88- <audio src={previewUrl()} controls class="w-full" />88+ <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">
89- </div>89+ <audio src={previewUrl()} controls class="w-full" />
90- </Show>90+ </div>
91- <Show when={canFrame(type()) && previewUrl()}>91+ </Match>
92- <iframe title={file().name} src={previewUrl()} class="h-full w-full rounded-md border border-white/10 bg-background" />92+ <Match when={canFrame(type()) && previewUrl()}>
93- </Show>93+ <iframe title={file().name} src={previewUrl()} class="h-full w-full rounded-md border border-white/10 bg-background" />
94+ </Match>
95+ </Switch>
94 </Show>96 </Show>
95 </Show>97 </Show>
96 </div>98 </div>