Skip to content

Extract the shared spine from the four details page models #120

Closed

Description

@zhollis21

Problem

CharacterDetailsPageModel (581 lines), StaffDetailsPageModel (585) and StudioDetailsPageModel
(344) are three variations on one page. They share 8 members:

LoadAsync · RetryLoad · ShowError · CancelInFlight · ToggleFavourite ·
NotifyFavouriteChanged · OpenSiteUrl · NavigateToMedia

That is more than half of StudioDetailsPageModel's entire surface. The shared spine is the same
every time: a load with a PageLoadScope, a PageState transition, an error state with a
retryability rule, a favourite toggle through FavouriteToggleRunner, an external-link command, and
a navigate-to-media command.

MediaDetailsPageModel (1,719 lines) shares six of the eight, not all eight: it has no ShowError,
no DescribeError, no OpenSiteUrl and no IExternalBrowser, and populates the error properties
inline at three sites instead. It has the rest of the spine plus a great deal that is genuinely its own.

Why now

Three reasons, in order of weight:

  1. It is the prerequisite for the last of Add unit test suite for PageModels, Services, and Converters #52's Phase 1. Testing these means three near-identical
    harnesses, which bakes the duplication into the test suite as well as the production code.
    Extracting the spine means testing it once and leaving each page model with only what is
    actually specific to it.
  2. Fixes land in one of three places. Extract AniSprinkles.Core class library to unblock PageModel/Services unit tests #62 found four separate copies of the same
    toast/snackbar helper across page models, and a 4s/5s inconsistency that had crept between two of
    them. That is the same failure mode one level up.
  3. MediaDetailsPageModel can adopt the spine too, which is where the payoff is largest.

Shape

Decided during planning: a generic DetailsPageModelBase<TEntity> where TEntity : class, IFavouritable.
Each page model keeps its own [ObservableProperty] entity field — so every binding and every
NotifyPropertyChangedFor list survives untouched — and satisfies a
protected abstract TEntity? Entity { get; set; } that the base reads through. The DetailsLoadScope
collaborator alternative was rejected: the views bind the error and state properties directly on the page
model, so a collaborator would still need five forwarding properties per page and would remove almost
none of the duplication. The base owns:

  • the load/cancel lifecycle over PageLoadScope
  • PageState transitions and the error-state population, including the ApiErrorKind.NotFound →
    CanRetry = false rule that currently appears in each file
  • RetryLoad re-invoking with the last requested id
  • the favourite toggle over FavouriteToggleRunner
  • OpenSiteUrl through IExternalBrowser

Each page model then supplies its fetch and its own sections. Fitting all four takes nine hooks —
FetchAsync, SeedSections, ResetForNewEntity, EntityName, the invalid-id and not-found copy,
ShouldSkipLoad (Media's IsBusy guard), OnEntityReused (Media's ListEntry merge),
NullResultIsRetryable (Media true, the other three false) and OnLoadStarting (Media's Sentry
breadcrumb). Media keeps its own two-arg LoadAsync(int, MediaListEntry?) as the public entry, which
stashes the entry and calls the template. ShowError is public so the four page code-behinds can call
it from onRenderError instead of assigning five properties each.

Acceptance

  • The 8 shared members exist once; Media adopts the 6 of them it has.
  • Each of the four details page models is measurably smaller. Three behaviour changes are deliberate
    rather than incidental:
    • ErrorDetails on Character/Staff/Studio carries an ErrorReportService report id, as
      MediaDetails already did, instead of a raw ex.Message.
    • All four favourites counts render through the models' existing MetricFormat.Compact, replacing
      the two shadowing FormatFavourites copies and MediaDetails' N0/--. This also fixes a latent
      bug: the shadowing copies have no M tier, so 1.2M favourites renders 1200k today on the
      character and staff pages.
    • Media's auth fetch becomes cancellable — it passes the page token, as the other three already do.
  • One shared test class covers the spine; per-page tests cover only what is specific.
  • /run-anisprinkles: load each of the four details pages, force an error state and retry, toggle a
    favourite, and open the AniList link — the spine is exactly the code every one of those paths runs.
    Confirm a favourites count reads identically on a character page and a media page.

Related

Activity

  1. added
    p3-medium
    Tech Debt
    on Aug 22, 2026
  2. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Verified against 490fdd5 (origin/main) before planning.

    Line counts now: Character 581, Staff 585, Studio 344, Media 1,719 (body says 1,755).

    The three small page models genuinely do share the spine.

    member Character Staff Studio
    LoadAsync 247 216 131
    CancelInFlight 338 305 205
    OpenSiteUrl 398 383 240
    NotifyFavouriteChanged 426 411 269
    RetryLoad 435 420 277
    NavigateToMedia 453 438 280
    DescribeError 515 500 330
    ShowError 539 559 335
    • ShowError is byte-identical in all three.
    • DescribeError differs only in its fallback subtitle string ("Failed to load character/staff/studio details.").
    • LoadAsync is the same twelve-step shape in all three; what differs is the fetch call, the sections
      seeded, the entity name in the NAVTRACE lines, the two copy strings, and — Character/Staff only — the
      spoiler / description-expanded reset.

    MediaDetailsPageModel shares 6 of the 8, not 8. It has no ShowError, no DescribeError, no
    OpenSiteUrl, and no IExternalBrowser dependency (the "view on AniList" binding appears only in
    CharacterDetailsLoadedContentView.xaml, StaffDetailsLoadedContentView.xaml and
    StudioDetailsLoadedContentView.xaml). It assigns the five error properties inline at three sites —
    MediaDetailsPageModel.cs:523-528, :603-608, :643-648.

    Two behaviour differences that a shared spine has to decide about rather than absorb silently:

    1. MediaDetailsPageModel.cs:665 puts _errorReportService.Record(ex, "Load details") — a Sentry report
      id — into ErrorDetails. Character/Staff/Studio put raw ex.Message there instead.
    2. Favourites formatting differs. CharacterDetailsPageModel.cs:567 and StaffDetailsPageModel.cs:569
      hold a byte-identical private FormatFavourites producing 1.2k with "" for none;
      MediaDetailsPageModel.cs:345 formats N0 (1,234) with -- for none.

    NotifyFavouriteChanged legitimately differs. Character and Staff raise IsFavourite /
    FavouritesDisplay / HasFavourites; Studio raises Studio and IsFavourite instead, because the
    Studio view binds through Studio.*.

    All four entity models implement IFavouritable (Character.cs:6, Staff.cs:6, Studio.cs:5,
    Media.cs:5), so FavouriteToggleRunner already works against a single interface.

    The four page code-behinds also write the error properties directly, five assignments each, in the
    DeferredContentLoader onRenderError callback — CharacterDetailsPage.xaml.cs:36,
    MediaDetailsPage.xaml.cs:41, StaffDetailsPage.xaml.cs:36, StudioDetailsPage.xaml.cs:36. Whatever the
    spine exposes has to keep those five settable, or give the code-behind a method to call.

    Small things noticed while reading: after the same-id early return, the follow-up
    if (Character is null || Character.Id != characterId) at CharacterDetailsPageModel.cs:275 (and
    StaffDetailsPageModel.cs:239) is always true. Both files also carry a stray double blank line after
    _scope.Begin(), and MediaDetailsPageModel.cs indents its class body four spaces under a file-scoped
    namespace where the other three do not.

    No test coverage exists for Character/Staff/Studio details today — MediaDetailsPageModelTests.cs
    (7 cases) is the only details page-model test file.

  3. zhollis21 commented on Aug 22, 2026

    @zhollis21
    OwnerAuthor

    Updated during planning:

    • Media line count 1,755 → 1,719, and it shares six of the eight members rather than all eight.
    • Shape settled on a generic DetailsPageModelBase<TEntity> with the entity reached through an abstract accessor; the DetailsLoadScope collaborator alternative is out, and the nine hooks it takes to fit all four are now written down.
    • Acceptance no longer claims "no behaviour change". Three changes are deliberate: the Sentry report id in ErrorDetails on the other three, one favourites format across all four via the existing MetricFormat.Compact, and a cancellable auth fetch on Media.

    Scope agreed: all four page models, plus the details page-model tests and MediaDetailsPageModel.RetryLoad from #52 Phase 1. MediaBrowsePageModel and MyAnimePageModel stay their own #52 pass; SettingsPageModel remains blocked on #121.

  4. zhollis21 commented on Aug 23, 2026

    @zhollis21
    OwnerAuthor

    Device pass done against the CI-stub build: all four details pages load, the favourites format is consistent (media reads 90.5k where it previously showed 90,457), back-navigation hits the same-id reuse guard without a refetch, and the NAVTRACE lines keep their documented shape — NAVTRACE StaffDetails fetch+seed in 15ms (staff 95075, 8 voice roles, 4 production roles); UI render follows. MediaDetails now emits that line too; it was the one page without it. No errors or warnings in the app log.

    Two acceptance items were not verified on device:

    • Force an error state and retry. -p:ErrorSim=true swaps in FailingAniListClient, which throws on every method, so My Anime and Discover fail first and there is no list left to navigate through to reach a details page. Covered by 32 unit tests (8 error/retry cases x 4 pages) instead. Filed as Replace ErrorSim with runtime fault injection that composes with the CI fixtures #125.
    • Toggle a favourite. Left for a human pass — it is a mutating gesture. Rollback and the retry snackbar are covered by 8 tests; the heart glyph swap is not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Tech Debtp3-medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions