Repository navigation
Description
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:
- 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. - 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. MediaDetailsPageModelcan 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 PageStatetransitions and the error-state population, including theApiErrorKind.NotFound→
CanRetry = falserule that currently appears in each fileRetryLoadre-invoking with the last requested id- the favourite toggle over
FavouriteToggleRunner OpenSiteUrlthroughIExternalBrowser
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:ErrorDetailson Character/Staff/Studio carries anErrorReportServicereport id, as
MediaDetails already did, instead of a rawex.Message.- All four favourites counts render through the models' existing
MetricFormat.Compact, replacing
the two shadowingFormatFavouritescopies and MediaDetails'N0/--. This also fixes a latent
bug: the shadowing copies have no M tier, so 1.2M favourites renders1200ktoday 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
- Add unit test suite for PageModels, Services, and Converters #52 — Phase 1 remainder depends on this landing first to be worth writing.
- Extract AniSprinkles.Core class library to unblock PageModel/Services unit tests #62 — put all four page models in
AniSprinkles.Core, which is what makes the shared spine
testable at all.
Activity
zhollis21 commentedon Aug 22, 2026
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.
LoadAsyncCancelInFlightOpenSiteUrlNotifyFavouriteChangedRetryLoadNavigateToMediaDescribeErrorShowErrorShowErroris byte-identical in all three.DescribeErrordiffers only in its fallback subtitle string ("Failed to load character/staff/studio details.").LoadAsyncis the same twelve-step shape in all three; what differs is the fetch call, the sectionsseeded, the entity name in the NAVTRACE lines, the two copy strings, and — Character/Staff only — the
spoiler / description-expanded reset.
MediaDetailsPageModelshares 6 of the 8, not 8. It has noShowError, noDescribeError, noOpenSiteUrl, and noIExternalBrowserdependency (the "view on AniList" binding appears only inCharacterDetailsLoadedContentView.xaml,StaffDetailsLoadedContentView.xamlandStudioDetailsLoadedContentView.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:
MediaDetailsPageModel.cs:665puts_errorReportService.Record(ex, "Load details")— a Sentry reportid — into
ErrorDetails. Character/Staff/Studio put rawex.Messagethere instead.CharacterDetailsPageModel.cs:567andStaffDetailsPageModel.cs:569hold a byte-identical private
FormatFavouritesproducing1.2kwith""for none;MediaDetailsPageModel.cs:345formatsN0(1,234) with--for none.NotifyFavouriteChangedlegitimately differs. Character and Staff raiseIsFavourite/FavouritesDisplay/HasFavourites; Studio raisesStudioandIsFavouriteinstead, because theStudio view binds through
Studio.*.All four entity models implement
IFavouritable(Character.cs:6,Staff.cs:6,Studio.cs:5,Media.cs:5), soFavouriteToggleRunneralready works against a single interface.The four page code-behinds also write the error properties directly, five assignments each, in the
DeferredContentLoaderonRenderErrorcallback —CharacterDetailsPage.xaml.cs:36,MediaDetailsPage.xaml.cs:41,StaffDetailsPage.xaml.cs:36,StudioDetailsPage.xaml.cs:36. Whatever thespine 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)atCharacterDetailsPageModel.cs:275(andStaffDetailsPageModel.cs:239) is always true. Both files also carry a stray double blank line after_scope.Begin(), andMediaDetailsPageModel.csindents its class body four spaces under a file-scopednamespace 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.
zhollis21 commentedon Aug 22, 2026
Updated during planning:
DetailsPageModelBase<TEntity>with the entity reached through an abstract accessor; theDetailsLoadScopecollaborator alternative is out, and the nine hooks it takes to fit all four are now written down.ErrorDetailson the other three, one favourites format across all four via the existingMetricFormat.Compact, and a cancellable auth fetch on Media.Scope agreed: all four page models, plus the details page-model tests and
MediaDetailsPageModel.RetryLoadfrom #52 Phase 1.MediaBrowsePageModelandMyAnimePageModelstay their own #52 pass;SettingsPageModelremains blocked on #121.zhollis21 commentedon Aug 23, 2026
Device pass done against the CI-stub build: all four details pages load, the favourites format is consistent (media reads
90.5kwhere it previously showed90,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:
-p:ErrorSim=trueswaps inFailingAniListClient, 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.Extract the shared spine from the four details page models (#120) (#126)
Extract the shared spine from the four details page models (#120) (#126)