Skip to main content

The book page

The book page is /book/[libraryId]?connection=&path=&tab=. The route file (src/app/(app)/(home,library,search,offline,me)/book/[libraryId].tsx) only names BookScreen. Everything else lives in src/components/book/. Its rules sit in two pure, tested modules (book-page-model.ts, book-details-model.ts), so the components only draw. The user-facing tour is A book's page.

Module map​

FileWhat it is
book-page.tsxBookScreen, useCanonicalBookPath, useRefreshPendingListing and BookPage (described under the table)
book-page-model.tsPure: bookPageLayout, titleScale, heroSubtitle, primaryAction / primaryLabel, chapterList, rowAt, timelineStarts, placeLine, heroEyebrow, bookFacts, startedAt, listeningFigures
book-tab-panel.tsxBookTabPanel: the active tab's panel (the tab row is the page's)
book-hero.tsxBookHero: the CoverWash, crumbs slot, eyebrow, title, subtitle, byline, facts, the place (or the finished badge and the stars), then the actions and footer slots
hero-actions.tsxHeroActions: the primary button, DownloadControl, Read the ebook (canRead), the Up next menu, favourite, Add to collection (in the menu when stacked), and BookActionsMenu with omit
book-crumbs.tsxBookCrumbs: the library, each folder above the book (links), the book's own folder or file name
book-chapters-tab.tsxBookChaptersTab: "The whole book" (BookTimeline + legend + axis) and the rows
book-details-tab.tsx + book-details-model.tsBookDetailsTab: the playback notice, the files table, the path; fileRows, visibleFiles, playbackMode, and the About card's aboutContent, labelGroups and languageName
book-about.tsxBookAbout: the About card, its genre and tag chips, and openLabelBooks
book-aside.tsxBookAside: BookAbout, Other versions (BookVersions), Other recordings in your library (OtherRecordings), Your listening
other-recordings.tsxOtherRecordings: the card of the item's other_recordings (server#241), each a RecordingRow
book-skeleton.tsxThe loading layout

book-page.tsx holds four pieces:

  • BookScreen wraps the page in ContentScope, so it reads the route's own ?connection=.
  • useCanonicalBookPath handles a route given a track file or disc folder inside a book, which /item resolves to the book. Before the page renders, it moves the route to the book's own rel_path. It uses setParams, so it adds no history entry, and it seeds the book path's item query. The page asks for progress, plays and casts by the book path only.
  • useRefreshPendingListing handles a book opened from a browse row flagged pending_book. The page's read indexes that book, so the hook marks the cached listing stale, and going back shows the book, not "Not scanned yet".
  • BookPage holds the data (useBook, useChapters, useBookMeta, useBookProgress, useBookAnnotations, the history query), the tab row, the play calls and the layout.

Shared pieces it uses from elsewhere:

  • Notice (src/components/ui/notice.tsx), the icon, title and body notice with an info / success / warning tone. The Downloads page uses it too.
  • useBookRating (src/components/player/use-book-rating.ts), the hero's stars and the end credits'.
  • usePlayBook, the one play path (see The primary action and the action row).

The tabs' list is src/components/library/book-tabs.ts. The per-tab sections BookmarksSection, NotesSection and HistorySection are in src/components/library/, built from the shared rows in src/components/annotations/. The community blocks are in book-meta.tsx.

Layout by the measured width​

bookPageLayout(useLayout(), width) reads the page's measured width (the root ScrollView's onLayout). It does not use the window, because the desktop Up next drawer takes 300-480 px and can leave a desktop page phone-narrow. Before the first measure it trusts the window class.

Measured widthHeroBody
phone class, or under 600 (HERO_SIDE_MIN)cover above the text (min(230, 64%)), title smone column: aside, then tabs
600 to 827cover beside the text: 220, level with the text's top (heroAlign: 'start'), title mdone column
828 (BODY_COLUMNS_MIN) to 1099as abovetabs, with the aside as a right-hand column (300)
1100 and upcover beside the text: 300, with the text resting on its foot ('end'), title lgtabs, with the aside as a right-hand column (300, or 340 from 1200)

BODY_COLUMNS_MIN is computed, not picked. It adds up the body's padding on both sides (24 each), the narrowest tab column worth having (440, a chapter row with its start time and length), the column gap (40) and the narrowest aside (300). An 834 portrait tablet takes the two columns.

roomy (600 and up) adds the chapter rows' start time and the files table's columns. titleScale steps the title down once past 48 characters. The tab panel renders inside the page's own ScrollView, never a nested vertical scroller.

The hero​

  • Wash: CoverWash from the book's cover_color, or a neutral wash from mutedForeground without one. Text never sits on raw cover colour.
  • Eyebrow (heroEyebrow): "Series · Book N" (a link through useOpen().openSeries), else "library · server".
  • Subtitle (heroSubtitle): the server's subtitle under the title, unless the title already holds it, ignoring case ("Dune: The Desert Planet" over "The Desert Planet"). Nothing shows on an older server.
  • Byline: author and narrator as links (openAuthor / openNarrator). The narrator is plain text where browse_people is false.
  • Facts (bookFacts): length; chapters, or "N parts of M min"; the audio (codec, "N FORMAT files" or the format, size); the published year; the publisher (the server's publisher, else the community recording's); and "server › library". A fact the book doesn't have is left out.
  • The place of a book that is loaded or in progress: percentHeard, placeLine ("Chapter 23 of 81" or "Part 3 of 12", nothing for files) on the row rowAt finds, useBookTimeLeft, and the progress bar, which is the page's one pink thing.
  • Finished: a finished book that is not loaded gets the finish badge instead, dated from listeningFigures. With ratings on, it also gets RatingStars through useBookRating. The hook waits (ready: false) until the saved rating is known, and sends its note back with the new value, since a PUT replaces the whole rating.

The primary action and the action row​

primaryAction({ status, loaded, live, chapter }) picks the primary button:

ButtonWhen
Pausethis book is loaded and its transport is live
Resume chapter N (or Resume)the book is loaded or in progress. N is the real chapter the place is in, shown only for a chapters list of more than one
Listen againthe book is finished
Start listeninga new book
Listenthe saved progress is still unknown (progressQuery.isPending)

Both ways to play go through the app's one play path, usePlayBook (src/components/player/use-play-book.ts). Its route is the pure playRoute (play-route.ts).

  • The primary calls it with { toggle: true }. A loaded book pauses or plays in place on every layout; it never restarts.
  • A chapter row calls it with { at: jump }. A Jump is a BookPlace. For a chapter it carries the corrected whole-book position and, when known, file: { path, pos } with the library-relative path and the chapter's start in that file. A file row carries track. A timeline tap supplies whole-book seconds.
    • On a phone it opens the full player there, unless the player is already on top. The route applies the jump once, also to the loaded book.
    • On a tablet or desktop it jumps the loaded book there or starts it in place (startBookInPlace). Both look the chapter's file up in the queue that plays, as the player does.

usePlayBook rejects when the book can't start. The error is a PlaybackStartError when the engine couldn't start it (see The player store), or the fetch's own error when the book couldn't be fetched. The page then toasts library.bookActions.playFailed through playFailedToast, with the reason as the description when there is one.

Another device's place (Sync v2, listening_sync). When offerOf finds a place for the book (see Offering another device's place), ListeningOfferLine (listening-offer.tsx) shows On {device}: {chapter, time} · Play from there under the actions, in the hero's footer. The place is measured from where the primary would play from (resumePosition). The line says "On another device" when the server has no name. Play from there answers the offer (answerOffer) and plays the book there ({ at: { position } }). Answering acknowledges the row's version and notes the place, so it isn't offered again. Nor is a place whose toast timed out (settledOffers), and the line never repeats a held offer (the throttles). Nothing shows on a server without the flag.

HeroActions lays the row out after the primary:

ControlGateNotes
DownloadControl-an outline button per state: Download for offline, "N% · Cancel" with a ProgressRing, Downloaded (a menu with the size and Remove download), Retry download. Disabled where this device can't keep the book
Read the ebookcanRead (see Read on the book page)an outline button after the download (its own row when stacked) that pushes readerHref to the /read modal; see The ebook reader
Up next menuqueuePlay next (at position 0, with an Undo that puts it back where it was); Add to the end / Remove from Up next (useQueueActions)
Favourite-ink, never pink
Add to collectioncollections, not stackedthe book menu's dialog. When stacked it is the menu's own item instead
BookActionsMenuits items' ownomit (MENU_OMIT, ['play', 'queue', 'collect', 'download']) leaves Mark as finished / not finished and More in this series. Stacked, it also keeps Add to collection (MENU_OMIT_PHONE is the same list without 'collect'). It renders nothing when that leaves no item. For an admin whose book has generated characters or recaps it adds Regenerate characters, recaps and the description (extra), then each active player module's bookActions (none yet)
Generate characters and recapsuseGenerate's offer === 'generate'an outline button after the others (its own row when stacked), for an admin a Bridge can generate for (see Generating characters and recaps)

When the hero is stacked (under 600 measured), the primary takes its own row and the rest stay on one row. Add to collection moves into the menu, so the download slot (flex-1) takes the room the icon buttons leave, enough for its word on a phone. The download control gets short: "Download", and just "Cancel" while it runs, with its words ending in "..." rather than wrapping. The menu opens as a sheet. The footer holds DownloadProgress, GenerateStatus, GenerateCovered (only while covered) and TranscodeNote.

Generating characters and recaps​

Generating characters and recaps (src/components/bridge/) is the player's first admin-only UI.

Who sees it​

mayGenerate(user, server) (bridge-model.ts, pure and tested) allows it for an admin who isn't a demo account, a household member or a kid. The server must have capabilities.bridge and capabilities.metadata on, and its bridge.features must hold sidecars.

useGenerate reads generateOffer, the offer rule the console shares (see Who sees the action). communityCoverage says what the community has. useGenerate gives the page one of two answers:

  • offer: generate or regenerate.
  • covered, when the community has both characters and recaps. It is a boolean, and offer is then null.

covered mounts GenerateCovered in the hero's footer: "The community already has characters and recaps for this book" with See characters. That button selects the Characters tab and scrolls the page to the tabs (openCharacters, not animated under reduced motion). generateOffer never gives covered without mayGenerate, so a listener never sees the line.

No offer shows until the book's /meta and its jobs are known (metaAnswered; a failed lookup is no answer). No offer shows while a job shows its status either.

The dialog​

GenerateDialog reads GET /admin/bridge/estimate. It shows what the run reads, the transcription and the agent cost (for every book it queues), "On this server", and the earlier books of the series (ticked, and queued first).

The dialog blocks the submit when:

  • the library isn't writable;
  • the estimate's open_job is a chapters.detect job. The book's chapters are still being found, which the server refuses with 409 detect_open (bridge.generate.detectOpen);
  • the estimate's open_job is a sidecars.contribute job. The console's "Share with the community" is filing the book's characters and recaps, which the server refuses with 409 contribute_open (bridge.generate.contributeOpen, kind SIDECARS_CONTRIBUTE in src/lib/bridge-jobs.ts). An older server sends neither.

It also holds the submit back when the agent is known not to be ready (blockedReason), which it can tell only when the estimate carries the Bridge's figures.

The console hides its action while either job is queued or working. A parked job gives way, and so does a share held while the contributions module is off. The player keeps the button and says why in the dialog instead. A 409 detect_open or 409 contribute_open from the queue (a job queued after the estimate) toasts the same words (bridgeRefusalKey). When the refused book is an earlier one of the series (otherBook), it toasts the plain failure.

A refused queue reads the estimate again. While its open_job is a share, the dialog reads it again every 10 seconds while the share is claimed or running, and every minute while it is queued (estimatePollInterval, foreground only), so the hold lifts once the share ends. A detection is not waited for. A share held while the contributions module is off is not the open_job, so it holds nothing back; the generate job cancels it.

The dialog always queues {source: "auto", contribute: "local"} (GENERATE_PARAMS). The player never contributes.

Status and refresh​

GenerateStatus sits under the actions while a job is open or failed:

  • Open: the stage (bridge.stage.*, including chapter_detecting, "Finding the chapters in the narration"), "12 of 40", the time left and Cancel. The early chapters save sends its writing and rescanning steps with an engine stage before ready; stageOf reads them as that stage.
  • Parked: the park in the player's own words (bridge.park.*, by parkReason; chapters_not_detected is "The Bridge couldn't find the chapters in the narration."), and when it tries again by itself. A book waiting for an ASR worker or for confirmation that it can share (share_unconfirmed) says "It carries on by itself" (parkEndsByItself); any other park says "Open the console to fix it".
  • Failed: the error and Try again.

useBridgeJobs polls the book's jobs every 10 seconds while one is claimed or running, and every minute while one is parked. It polls only while the surface is focused and the app is in the foreground. When an answer sees a job that wrote the book's files reach done (latestDone: sidecars.generate, sidecars.describe or chapters.detect), it reads the book's /meta, item and chapters again (refreshAfterFinish). The tabs, and any chapters found in the narration, then appear.

The companion's empty Who's who and Story so far mount GenerateOffer, the same button and status.

The tabs​

bookTabs(input) (src/components/library/book-tabs.ts, pure and tested) decides which tabs exist, in this order:

TabShown when
chapters (labelled Chapters, Parts or Files)the list has rows, or the chapters are still loading
recapsthe work has recaps, a visible whole-book summary, or earlier books in its series
charactersthe work has characters, or earlier books in its series
bookmarks, history, notesalways (user-creatable, so reachable from empty)
seriesat least one non-empty series rail
detailsalways

The selected tab is held as an intent (useState, seeded by parseBookTab(?tab=)). Render falls back to the first existing tab (tabs.includes(tab) ? tab : tabs[0]), so a tab that disappears when data settles never renders blank. Labels come from TAB_LABEL_KEY, which reuses the section strings (library.{bookmarks,history,notes}.title, book.meta.characters, book.details.title). Counts show where the data is already in hand, never fetched for a count:

  • the list's rows;
  • useBookAnnotations' bookmarks and notes (ANNOTATIONS_STALE_MS, 60 s, since every write invalidates them anyway);
  • the characters met (splitCharacters(...).visible).

A one-tap or sleep bookmark queued on this device appears as Waiting to sync with a seek pin and Delete/Undo. Each book sends its oldest pending bookmark first. See Annotations for the replay and expiry rules.

A summary counts as visible only when it will actually render (summaryIsVisible: an in_short, or an ending on a finished book). The page computes it once and passes it to both bookTabs and BookMetaRecapsTab, so the tab and its panel can't disagree. The page holds the spoiler reveal (showSpoilers), shared by Recaps and Characters. The gate is listeningProgressFor over the corrected chapter starts and useListeningPosition (see Spoiler gating).

BookTabPanel renders the active tab:

  • BookChaptersTab, or five skeleton rows while the list is empty.
  • The community tabs, with their Attribution (communityCredit; none for a dimension generated on this server). A tab whose content came from the server's own files gets a GeneratedMark ("Generated on this server") at its head. The Recaps tab places its chips and credit by recapMarks (see Enriched book metadata).
  • BookmarksSection and NotesSection, both AnnotationSection (see Bookmarks and notes).
  • HistorySection, BookMetaSeriesTab and BookDetailsTab.

BookTabPanel also builds the community cover resolver (useCommunityCover) and hands it to the Series, Recaps and Characters tabs as coverFor (see Community covers).

The Chapters tab​

chapterList builds the rows in the units the player navigates (book-queue):

  • the real chapters at their corrected whole-book starts (chapterStartsOf, recomputed from the file durations, because the server's book_offset is unreliable for some books);
  • for one long file with no real chapters (none, or a lone whole-book one), the player's own parts (synthesizeChapters at the listener's virtualChapterInterval), with a Notice saying why;
  • else the files, each jumping by track. A file after one of unknown length has a NaN start, and timelineStarts then gives the timeline nothing.

The chapters answer's chapters_source can end the list with a quiet caption. Each caption is a SOURCE_CAPTION entry drawn by SourceLine:

chapters_sourceMeaningCaptionKey and testID
"community"the server fitted a community recording's chapter list onto the audio (see Community chapters)a globe icon and "Chapters from the AudioSilo community database"book.chapters.community, book-chapters-community
"generated"a Bridge found them in the narration of a book with no chapters of its own (see Generated chapters)the server glyph in the caption's colour and "Chapters found in the narration on this server"book.chapters.generated, book-chapters-generated
"edited"an admin edited the list in the console's chapter editor (see Edited chapters)a pen icon and "Chapters edited on this server"book.chapters.edited, book-chapters-edited

The caption shows only when the rows are real chapters. BookChaptersTab takes the answer's source only while list.kind === 'chapters'. Nothing else changes; the chapters have the same shape either way.

"The whole book" is the player's BookTimeline for any book, with pins from useBookAnnotations (pinsOf):

  • While the book is loaded, its place follows the player (timelinePosition(selectBookPosition)), and a tap or drag calls seekBook.
  • Otherwise it draws the saved place, and a tap jumps through usePlayBook.
  • scrubTarget keeps both kinds of tap short of the book's end.
  • A step key on a loaded book uses the player's stepSegment (the transport). Before the book loads, the keys use whole-book seconds from the saved place (nextSegmentStart and previousSegmentStart).

rowAt(rows, position, file) matches the playing chapter by file path and in-file start, so it finds the right row even when a partial queue orders the files differently. Before playback, it uses the saved file and seconds when available. With only book seconds it follows the player's tie rule (Chapter names).

The timeline uses the current row at the playhead and rowAt(rows, seconds) for other hover positions. It uses a row as the current timeline segment only when every row has a known start. A bookmark marks the row rowAt finds for its book position. Each row is memoised on its state and bookmark glyph, and all rows count as heard once the book is finished.

The Details tab​

  • playbackMode({ downloaded, transcoded }) gives local for a download on this device, and converted when useNeedsWebTranscode says the web player converts it (the same rule playback uses; web only). Anything else is direct.
  • fileRows(book, chapterData) takes the chapters response's files, else the item's, else the book as one file. The codec is the book's (one probe per book). "about N kbps" is bitrateKbps(size, duration) (src/lib/format.ts), which is size × 8 / duration / 1000, rounded, or nothing when either is unknown. visibleFiles folds past FILES_SHOWN (6).
  • The path: "library/" + rel_path, selectable, with the note that progress is keyed on it.

The aside​

BookAside stacks up to four cards. From BODY_COLUMNS_MIN they form a right-hand column (see Layout); below it they sit between the hero and the tabs.

  • About - BookAbout (book-about.tsx) draws the pure aboutContent(book, work, recording, t). work is the bookMetaWork value (the matched work, or an unmatched book's generated one). It is the one source of every work-level field, the credit included, and BookAbout takes it as a required prop. recording (the match's, from matchedMeta) gives the recording facts.

    • The text is picked once into source (AboutSource), the first that exists:

      1. 'community': the community's community_description. It is CC BY-SA, so the server's attribution is rendered beside it with Improve this, which opens attribution.source_url or the work's web_url.
      2. 'own': the server's description (from /item only) or the work's core description.
      3. 'generated': the description a Bridge generated on this server (work.generated_description, read only when work.generated.description is set). It wears the "Generated on this server" chip (GeneratedChip, testID about-generated-mark) under the eyebrow, and never the credit or Improve this.
      4. 'fallback': with none of these, a sentence naming the author and narrator.
    • The detail rows:

      • the publisher (bookPublisher: the server's publisher, else the recording's);
      • the release date (bookReleased: the recording's release_date, else the book's published, which a match fills with the year the work was first published, else the recording's release year);
      • the work's first publication, only when it is not the release date, so one date shows as one "Released" row;
      • the server's language, a code named through Intl.DisplayNames in the app's language where the platform has it (languageName), else shown as sent;
      • abridged yes or no (the server's abridged, else the recording's). Absent means unknown, so there is no row.

      Both dates print in the listener's region format at the precision they were given (formatReleaseDate): 2012-06-26 reads "26 Jun 2012" in en-GB and "Jun 26, 2012" in en-US, 2012-06 reads "Jun 2012", and a year stays as it is. A value that is no date shows as it came. The end credits' Publisher and Released rows read the same two functions, so they always match this card.

    • Then labelGroups: the book's genres, then its tags, each once by labelKey, as chips under their names. A chip calls openLabelBooks, which selects the book's library in useLibrarySelection and opens the Library tab's root (openLibraryRoot) on libraryBooksHref({ genre | tag }).

    • A matched book without community text keeps "View on AudioSilo Meta". Long text folds past six lines with Show more.

    • A LibriVox recording adds "Also free on LibriVox" (book.about.librivox) under the other links out. It comes after the credit and Improve this, else after "View on AudioSilo Meta". It opens librivoxUrl(recording) through openExternalUrl. librivoxUrl (book-details-model.ts) reads the matched recording's librivox.url and keeps it only when it is an absolute http(s) URL (httpUrl) on librivox.org or archive.org (or a subdomain) with no user before the host. It lower-cases the scheme, because the in-app browser on iOS (expo-web-browser) refuses HTTPS://. The server checks the URL too. The player checks again because the link leaves the app. With no librivox.url, or on an older server, there is no link.

    • Every link out goes through openExternalUrl (src/lib/support.ts), which opens only an absolute http(s) URL and does nothing for any other (javascript:, file:, intent:).

  • Other versions - BookVersions: every other copy (useBookCopies) with where it lives and its quality, each opening that copy's page. Nothing shows when there is none. Each is an InsetRow.

  • Other recordings in your library - OtherRecordings (other-recordings.tsx, server#241): the item's other_recordings, the listener's other recordings of the book's community work (another narrator, an abridgement), in the server's order. Each is a RecordingRow (src/components/library/recording-row.tsx, shared with the series recordings picker): the cover, "Read by narrator" (recordingLabel, else the title), then the library when it is not the page's, abridged, the length and the listener's own progress in it (useSavedProgress through savedProgressView: "Finished" or "40% listened"), with a progress bar while in progress; a press opens that book. The card shows only when the field is present and non-empty, so an older server, community metadata off or a work held once shows nothing.

  • Your listening - listeningFigures, the figures the records hold, never estimated:

    • listened time from this book's history spans (listeningSummary, the end credits' rule), shown from a minute;
    • the book's speed (useBookSpeed);
    • started (progress.started_at, else the earliest span: startedAt) and finished (finished_at), with dates through formatRecordDate (src/lib/format.ts);
    • smartSpeedSaved, what Smart speed saved on this book on this device (useBookTimeSaved), shown from a whole second (see Time saved).

    listeningFigures is null for a book neither started nor finished. The history is only fetched then, and kept fresh for ten minutes (HISTORY_STALE_MS; a span this device records refreshes it).

  • In the house - InTheHouseCard (src/components/house/), last. It shows only while the listener shares and someone who shares is on this book; see Listening in the house.