From 0447c438d652887b0edf1c234d7f98bbb9059f07 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 19:07:01 +0000 Subject: [PATCH] fix: show narrators on History too History rows got narrators from the server, but the page's parser for a History row's download keeps only the fields it knows, and narrators wasn't one of them, so the "Narrated by" line never showed there. It does now, for older History entries too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01V88DbAixT45r3AJsyFJchY --- src/frontend/src/hooks/useActivity.ts | 8 +++++++- src/frontend/src/tests/useActivity.test.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/hooks/useActivity.ts b/src/frontend/src/hooks/useActivity.ts index ce8802059..165f7b2d2 100644 --- a/src/frontend/src/hooks/useActivity.ts +++ b/src/frontend/src/hooks/useActivity.ts @@ -66,7 +66,8 @@ const isDeliveryState = (value: unknown): value is RequestRecord['delivery_state ); }; -const parseHistoryBook = (value: unknown): Book | null => { +/** A History row's download, keeping only the fields it shows. */ +export const parseHistoryBook = (value: unknown): Book | null => { if (!isRecord(value) || Array.isArray(value)) { return null; } @@ -106,6 +107,11 @@ const parseHistoryBook = (value: unknown): Book | null => { ...(typeof value.content_type === 'string' ? { content_type: value.content_type } : {}), ...(typeof value.book_key === 'string' ? { book_key: value.book_key } : {}), ...(typeof value.info_url === 'string' ? { info_url: value.info_url } : {}), + ...(Array.isArray(value.narrators) + ? { + narrators: value.narrators.filter((name): name is string => typeof name === 'string'), + } + : {}), }; }; diff --git a/src/frontend/src/tests/useActivity.test.ts b/src/frontend/src/tests/useActivity.test.ts index 6b11e579d..15fd4e084 100644 --- a/src/frontend/src/tests/useActivity.test.ts +++ b/src/frontend/src/tests/useActivity.test.ts @@ -1,5 +1,6 @@ import { describe, it, expect } from 'vitest'; +import { parseHistoryBook } from '../hooks/useActivity'; import { getActivityErrorMessage } from '../hooks/useActivity.helpers'; describe('useActivity helpers', () => { @@ -15,3 +16,13 @@ describe('useActivity helpers', () => { expect(getActivityErrorMessage(null, 'Failed to clear item')).toBe('Failed to clear item'); }); }); + +describe('parseHistoryBook', () => { + it("keeps a download's narrators, to tell audiobooks of one book apart", () => { + const base = { id: 't1', title: 'Good Omens', author: 'Neil Gaiman' }; + expect(parseHistoryBook({ ...base, narrators: ['Martin Jarvis', 7] })?.narrators).toEqual([ + 'Martin Jarvis', + ]); + expect(parseHistoryBook(base)?.narrators).toBeUndefined(); + }); +});