Commit 9a4ad624 authored by Kourser's avatar Kourser
Browse files

Harden podcast episode loading on (re)appearance



Reproduced the report with a real feed: 715 episodes persist correctly in the
DB under the right podcast id, so the issue is view-side reuse, not storage.

- Load episodes via a shared helper from `.task(id: podcast.id)`.
- Reload from the store on every `.onAppear` (non-clobbering: only updates when
  episodes are found) so a reused detail view shows them on return.
- Give the detail an explicit `.id(podcast.id)` so switching podcasts yields a
  fresh view. Remove the temporary -uiSeedReal debug hook.

51 package tests green; iOS + macOS build; verified the detail shows the 715
episodes (and the HTML description renders) in the simulator.

Co-Authored-By: default avatarClaude <claude@anthropic.com>
parent 45606a4c
Loading
Loading
Loading
Loading
Loading
+31 −14
Original line number Diff line number Diff line
@@ -28,22 +28,39 @@ struct PodcastDetailView: View {
        }
        .navigationTitle(podcast.title)
        .inlineNavigationTitle()
        .task(id: podcast.id) {
        // Runs on first appearance and whenever the selected podcast changes.
        .task(id: podcast.id) { await loadEpisodes() }
        // Belt-and-suspenders: reload from the store on every re-appearance
        // (e.g. returning to a reused detail view), without flashing empty.
        .onAppear { reloadFromStore() }
        .refreshable {
            await model.refresh(podcast)
            await loadEpisodes()
        }
    }

    private func loadEpisodes() async {
        loaded = false
            episodes = await model.episodes(for: podcast)
            if episodes.isEmpty {
        var result = await model.episodes(for: podcast)
        if result.isEmpty {
            // Nothing stored yet for this feed — fetch it so episodes show
            // without a manual pull-to-refresh.
            await model.refresh(podcast)
                episodes = await model.episodes(for: podcast)
            result = await model.episodes(for: podcast)
        }
        episodes = result
        await model.loadPlayStates(for: episodes)
        loaded = true
    }
        .refreshable {
            await model.refresh(podcast)
            episodes = await model.episodes(for: podcast)
            await model.loadPlayStates(for: episodes)

    private func reloadFromStore() {
        Task {
            let result = await model.episodes(for: podcast)
            if !result.isEmpty {
                episodes = result
                await model.loadPlayStates(for: result)
                loaded = true
            }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ struct RootView: View {
        case .podcast(let id):
            if let podcast = model.podcasts.first(where: { $0.id == id }) {
                PodcastDetailView(podcast: podcast)
                    .id(id)
            } else {
                placeholder
            }