Files
Spanish/Conjuga/Conjuga/Views/Practice/Books/BookChapterListView.swift
T
Trey T 51067e23fd Fix Books navigation — tapping a book no longer re-pushes the library
BookLibraryView is itself pushed from PracticeView's NavigationStack,
so the .navigationDestination(for: Book.self) it declared was a
non-root registration. Combined with NavigationLink(value: book), that
resolved the push to *both* the destination handler and the closure
that produced BookLibraryView originally — pushing the chapter list
underneath, then re-pushing the library on top. Hitting back popped
the library and revealed the chapter list, in the wrong order.

Switched both Library→ChapterList and ChapterList→Reader to closure-
based NavigationLinks. Destinations attach directly to the link, no
type-keyed registry involved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 10:18:04 -05:00

46 lines
1.5 KiB
Swift

import SwiftUI
import SharedModels
import SwiftData
struct BookChapterListView: View {
let book: Book
@Query private var allChapters: [BookChapter]
init(book: Book) {
self.book = book
let slug = book.slug
_allChapters = Query(
filter: #Predicate<BookChapter> { $0.bookSlug == slug },
sort: \BookChapter.number
)
}
var body: some View {
List {
ForEach(allChapters) { chapter in
NavigationLink {
BookReaderView(chapter: chapter)
} label: {
HStack(spacing: 12) {
Text("\(chapter.number)")
.font(.subheadline.weight(.bold).monospacedDigit())
.foregroundStyle(.secondary)
.frame(width: 32, alignment: .trailing)
VStack(alignment: .leading, spacing: 2) {
Text(chapter.title)
.font(.subheadline.weight(.medium))
Text("\(chapter.paragraphsES().count) paragraph\(chapter.paragraphsES().count == 1 ? "" : "s")")
.font(.caption2)
.foregroundStyle(.tertiary)
}
}
}
}
}
.navigationTitle(book.title.prefix(while: { $0 != ":" }).description)
.navigationBarTitleDisplayMode(.inline)
}
}