From e78105f294e6ed242904be736ecf36a838258197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 23 Sep 2026 07:53:56 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20seek=20waits=20for=20unlo?= =?UTF-8?q?aded=20audio,=20resizable=20rail,=20clearer=20errors=20-=20a=20?= =?UTF-8?q?seek=20is=20instant=20only=20inside=20the=20buffered=20range=20?= =?UTF-8?q?or=20the=20local=20copy;=20=20=20elsewhere=20playback=20pauses,?= =?UTF-8?q?=20the=20thumb=20spins=20at=20the=20target=20with=20"Bu=20k?= =?UTF-8?q?=C4=B1s=C4=B1m=20=20=20y=C3=BCkleniyor=E2=80=A6",=20and=20it=20?= =?UTF-8?q?resumes=20from=20there=20once=20loaded=20(seekable=20was=20not?= =?UTF-8?q?=20=20=20trusted=20=E2=80=94=20Safari=20reports=20it=20for=20a?= =?UTF-8?q?=20stream=20that=20ignores=20Range=20and=20keeps=20=20=20playin?= =?UTF-8?q?g=20from=20the=20old=20spot);=20skips=20stack=20on=20a=20pendin?= =?UTF-8?q?g=20target=20-=20the=20studio's=20audio=20rail=20is=20resizable?= =?UTF-8?q?=20from=20its=20left=20edge=20(drag,=20arrow=20=20=20keys,=20do?= =?UTF-8?q?uble-click=20to=20reset),=20280=E2=80=93720px,=20remembered=20o?= =?UTF-8?q?n=20this=20device=20-=20study=20history=20docks=20on=20the=20ri?= =?UTF-8?q?ght=20on=20desktop=20so=20it=20no=20longer=20sits=20flush=20=20?= =?UTF-8?q?=20against=20the=20app=20sidebar;=20the=20phone=20drawer=20stay?= =?UTF-8?q?s=20on=20the=20left=20-=20pagination=20without=20a=20row=20coun?= =?UTF-8?q?t=20centres=20its=20buttons=20instead=20of=20pushing=20=20=20th?= =?UTF-8?q?em=20to=20the=20right=20edge=20-=20unmapped=20API=20errors=20na?= =?UTF-8?q?me=20the=20kind=20of=20failure=20by=20status=20(invalid=20reque?= =?UTF-8?q?st,=20=20=20conflict,=20missing=20or=20wrong=20field,=20timeout?= =?UTF-8?q?)=20and=20quote=20the=20server's=20reason;=20=20=20serde=20body?= =?UTF-8?q?=20errors=20become=20"=E2=80=9CBa=C5=9Fl=C4=B1k=E2=80=9D=20alan?= =?UTF-8?q?=C4=B1=20eksik",=20invalid=20option=20and=20=20=20wrong-format?= =?UTF-8?q?=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/__tests__/client/client.test.ts | 28 ++++++-- src/api/client/client.ts | 71 ++++++++++++++++--- src/components/ai/note-studio-panel.tsx | 67 ++++++++++++++++- .../events/event-roll-call.test.tsx | 2 +- src/components/notes/podcast-player.test.tsx | 4 +- src/components/rag/rag-study-panel.tsx | 50 +++++++------ src/components/ui/audio-player.tsx | 26 +++++-- src/components/ui/table-pagination.tsx | 13 ++-- src/i18n/locales/en.ts | 2 + src/i18n/locales/tr.ts | 2 + src/i18n/messages.ts | 2 + 11 files changed, 215 insertions(+), 52 deletions(-) diff --git a/src/api/__tests__/client/client.test.ts b/src/api/__tests__/client/client.test.ts index dead7a6..40ca333 100644 --- a/src/api/__tests__/client/client.test.ts +++ b/src/api/__tests__/client/client.test.ts @@ -278,13 +278,31 @@ describe("client", () => { ).toBe("Bu sınava yalnızca dersin öğretmenleri veya bir müdür soru ekleyebilir."); }); - it("falls back to a clean localized message for unmapped errors (no raw leak)", () => { + it("names the failure and quotes the server's reason for unmapped errors", () => { expect(formatApiErrorMessage("custom error occurred", "en")).toBe( - "Something went wrong. Please check your input and try again.", + "The action could not be completed. Server said: “custom error occurred”.", ); expect(formatApiErrorMessage("custom error occurred", "tr")).toBe( - "İşlem tamamlanamadı. Lütfen bilgileri kontrol edip tekrar dene.", + "İşlem tamamlanamadı. Sunucu yanıtı: “custom error occurred”.", ); + expect(formatApiError(new ApiError(409, "slot taken by a later edit"), "tr")).toBe( + "İşlem kaydın şu anki durumuyla çakışıyor. Sunucu yanıtı: “slot taken by a later edit”.", + ); + expect(formatApiError(new ApiError(400, ""), "tr")).toBe( + "Sunucu isteği geçersiz buldu. Bilgileri kontrol edip tekrar dene.", + ); + }); + + it("translates request bodies the backend could not decode", () => { + expect( + formatApiError(new ApiError(422, "Failed to deserialize the JSON body into the target type: missing field `title` at line 1 column 2"), "tr"), + ).toBe("“Başlık” alanı eksik. Doldurup tekrar dene."); + expect( + formatApiError(new ApiError(422, "Failed to deserialize the JSON body into the target type: format: unknown variant `kisa`, expected `duz_okuma` or `tek_ogretici` at line 1 column 20"), "tr"), + ).toBe("“kisa” geçerli bir seçenek değil. Geçerli değerler: duz_okuma or tek_ogretici."); + expect( + formatApiError(new ApiError(422, "Failed to deserialize the JSON body into the target type: ders_saati: invalid type: string \"3\", expected u32 at line 1 column 18"), "tr"), + ).toBe("“Ders saati” alanının biçimi hatalı: u32 bekleniyordu, string \"3\" geldi."); }); it("localizes backend max-length validation messages", () => { @@ -370,8 +388,8 @@ describe("client", () => { }); it("formats generic Error", () => { - expect(formatApiError(new Error("generic"), "en")).toBe("Something went wrong. Please check your input and try again."); - expect(formatApiError(new Error("generic"), "tr")).toBe("İşlem tamamlanamadı. Lütfen bilgileri kontrol edip tekrar dene."); + expect(formatApiError(new Error("generic"), "en")).toBe("The action could not be completed. Server said: “generic”."); + expect(formatApiError(new Error("generic"), "tr")).toBe("İşlem tamamlanamadı. Sunucu yanıtı: “generic”."); }); it("does not expose network, runtime, or provider errors to users", () => { diff --git a/src/api/client/client.ts b/src/api/client/client.ts index cc6716c..566560a 100644 --- a/src/api/client/client.ts +++ b/src/api/client/client.ts @@ -539,7 +539,62 @@ export async function blobClient(path: string, signal?: AbortSignal): Promise= 500) return locale === "tr" ? "Sunucuda bir sorun oluştu. Lütfen tekrar dene." : "Server error. Please try again."; - return formatApiErrorMessage(err.message, locale); + return formatApiErrorMessage(err.message, locale, err.status); } if (err instanceof TypeError) { return formatRuntimeErrorMessage(err.message, locale) ?? diff --git a/src/components/ai/note-studio-panel.tsx b/src/components/ai/note-studio-panel.tsx index d6ab7b3..1a3d1bd 100644 --- a/src/components/ai/note-studio-panel.tsx +++ b/src/components/ai/note-studio-panel.tsx @@ -1,4 +1,4 @@ -import { Show, Suspense, createMemo } from "solid-js"; +import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; import { Link, useNavigate } from "@tanstack/solid-router"; import { createResource } from "@/lib/create-resource"; import { getCourseNotes } from "@/api/course-notes"; @@ -22,6 +22,17 @@ import { cn } from "@/lib/cn"; import { courseNoteFiles } from "@/lib/note-source"; import { hasMinRole } from "@/lib/roles"; +const RAIL_KEY = "hezarfen.studio.railWidth"; +const RAIL_MIN = 280; +const RAIL_MAX = 720; +const RAIL_DEFAULT = 352; + +function readRailWidth(): number { + if (typeof localStorage === "undefined") return RAIL_DEFAULT; + const value = Number(localStorage.getItem(RAIL_KEY)); + return Number.isFinite(value) && value >= RAIL_MIN && value <= RAIL_MAX ? value : RAIL_DEFAULT; +} + type StudioNote = CourseNote & { courseTitle: string; courseCreatorId: string }; /** Every lesson note the account can produce from, with its course. */ @@ -117,6 +128,32 @@ export function NoteStudioDetail(props: { noteId: string; episode?: string }) { const auth = useAuth(); const [notes, { refetch }] = useStudioNotes(); const note = createMemo(() => (notes() ?? []).find((row) => row.id === props.noteId) ?? null); + // The audio rail is resizable from its left edge, remembered on this device. + const [railWidth, setRailWidth] = createSignal(readRailWidth()); + const clampRail = (value: number) => Math.round(Math.min(RAIL_MAX, Math.max(RAIL_MIN, value))); + createEffect(() => { + if (typeof localStorage !== "undefined") localStorage.setItem(RAIL_KEY, String(railWidth())); + }); + const startResize = (event: PointerEvent) => { + event.preventDefault(); + const handle = event.currentTarget as HTMLElement; + handle.setPointerCapture(event.pointerId); + const startX = event.clientX; + const startWidth = railWidth(); + const move = (next: PointerEvent) => setRailWidth(clampRail(startWidth + (startX - next.clientX))); + const stop = () => { + handle.removeEventListener("pointermove", move); + handle.removeEventListener("pointerup", stop); + handle.removeEventListener("pointercancel", stop); + document.body.style.removeProperty("cursor"); + document.body.style.removeProperty("user-select"); + }; + document.body.style.cursor = "col-resize"; + document.body.style.userSelect = "none"; + handle.addEventListener("pointermove", move); + handle.addEventListener("pointerup", stop); + handle.addEventListener("pointercancel", stop); + }; const canManage = () => { const current = note(); const user = auth.user(); @@ -147,7 +184,10 @@ export function NoteStudioDetail(props: { noteId: string; episode?: string }) {

{current().title}

{current().courseTitle} -
+
-
diff --git a/src/components/events/event-roll-call.test.tsx b/src/components/events/event-roll-call.test.tsx index 842f28f..8d50cb7 100644 --- a/src/components/events/event-roll-call.test.tsx +++ b/src/components/events/event-roll-call.test.tsx @@ -55,7 +55,7 @@ test("saves only changed rows and reports a failed row on that row", async () => expect(postEventAttendance).toHaveBeenNthCalledWith(1, "event-1", { user_id: "s-2", status: "absent" }); expect(postEventAttendance).toHaveBeenNthCalledWith(2, "event-1", { user_id: "s-3", status: "late" }); // The failed row keeps its pick and carries its own error line. - expect(await screen.findByText(/İşlem tamamlanamadı|Something went wrong/)).toBeTruthy(); + expect(await screen.findByText(/İşlem tamamlanamadı|could not be completed/)).toBeTruthy(); expect(screen.getByText(/1 of 2 rows|2 satırdan 1/)).toBeTruthy(); expect(onSaved).toHaveBeenCalledTimes(1); }); diff --git a/src/components/notes/podcast-player.test.tsx b/src/components/notes/podcast-player.test.tsx index 974f69b..99c5c36 100644 --- a/src/components/notes/podcast-player.test.tsx +++ b/src/components/notes/podcast-player.test.tsx @@ -33,8 +33,8 @@ describe("PodcastPlayer", () => { vi.spyOn(HTMLMediaElement.prototype, "pause").mockImplementation(() => {}); // Nor element scrolling, which the transcript's follow uses. Element.prototype.scrollTo ??= () => {}; - // A stream the server lets the browser seek in, so no local copy is loaded. - vi.spyOn(HTMLMediaElement.prototype, "seekable", "get").mockReturnValue({ + // Audio already buffered this far, so the seek needs no local copy. + vi.spyOn(HTMLMediaElement.prototype, "buffered", "get").mockReturnValue({ length: 1, start: () => 0, end: () => 754, diff --git a/src/components/rag/rag-study-panel.tsx b/src/components/rag/rag-study-panel.tsx index 575e766..37f67d9 100644 --- a/src/components/rag/rag-study-panel.tsx +++ b/src/components/rag/rag-study-panel.tsx @@ -299,7 +299,9 @@ export function RagStudyPanel() { class={cn( "grid h-[calc(var(--app-viewport)-5.5rem-max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] gap-4 max-lg:-mt-2", "lg:-mx-10 lg:-my-6 lg:h-[calc(100dvh-49px-env(safe-area-inset-top))] lg:gap-0", - historyCollapsed() ? "lg:grid-cols-[minmax(0,1fr)]" : "lg:grid-cols-[260px_minmax(0,1fr)]", + // The history docks on the RIGHT on desktop: on the left it sat flush + // against the app's own sidebar and the two read as one tangled nav. + historyCollapsed() ? "lg:grid-cols-[minmax(0,1fr)]" : "lg:grid-cols-[minmax(0,1fr)_260px]", )} > - - {(thread) => (
@@ -451,6 +433,28 @@ export function RagStudyPanel() {
)}
+ +
+ + +
+
diff --git a/src/components/ui/audio-player.tsx b/src/components/ui/audio-player.tsx index 5581d9e..a4f9a48 100644 --- a/src/components/ui/audio-player.tsx +++ b/src/components/ui/audio-player.tsx @@ -130,10 +130,15 @@ export function AudioPlayer(props: AudioPlayerProps) { } return localLoad; }; + // A seek is instant only where the audio is actually here: the local copy, + // or a range the stream has already buffered. `seekable` is not trusted — + // Safari reports the whole file as seekable on a stream that ignores Range, + // then keeps playing from the old spot. const canSeekTo = (secs: number) => { - const ranges = audio.seekable; + if (objectUrl && source() === objectUrl) return true; + const ranges = audio.buffered; for (let i = 0; i < ranges.length; i += 1) { - if (ranges.end(i) > 0 && secs >= ranges.start(i) && secs <= ranges.end(i)) return true; + if (secs >= ranges.start(i) && secs <= ranges.end(i) - 0.5) return true; } return false; }; @@ -203,7 +208,8 @@ export function AudioPlayer(props: AudioPlayerProps) { else if (audio.paused) play(); else audio.pause(); }; - const skip = (delta: number) => seek(audio.currentTime + delta); + // Skips stack on a pending seek's target, not on the stalled stream. + const skip = (delta: number) => seek((pendingSeek ?? audio.currentTime) + delta); const cycleRate = () => { const index = RATES.indexOf(rate() as (typeof RATES)[number]); setRate(RATES[(index + 1) % RATES.length]); @@ -400,14 +406,22 @@ export function AudioPlayer(props: AudioPlayerProps) {
- {formatDurationClock(current() * 1000)} + + {formatDurationClock(current() * 1000)} + + {t("audio.loadingPosition")} + + {formatDurationClock(duration() == null ? null : duration()! * 1000)}
diff --git a/src/components/ui/table-pagination.tsx b/src/components/ui/table-pagination.tsx index f1b6759..b497135 100644 --- a/src/components/ui/table-pagination.tsx +++ b/src/components/ui/table-pagination.tsx @@ -34,13 +34,18 @@ export function TablePagination(props: TablePaginationProps) { 1}>
- - {t("common.pageRange", { start: start(), end: end(), total: props.total ?? 0 })} - + + + {t("common.pageRange", { start: start(), end: end(), total: props.total ?? 0 })} + + 1}>