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>
This commit is contained in:
Trey T
2026-05-11 10:18:04 -05:00
parent 05a367fdbe
commit 51067e23fd
2 changed files with 6 additions and 8 deletions
@@ -19,7 +19,9 @@ struct BookChapterListView: View {
var body: some View { var body: some View {
List { List {
ForEach(allChapters) { chapter in ForEach(allChapters) { chapter in
NavigationLink(value: chapter) { NavigationLink {
BookReaderView(chapter: chapter)
} label: {
HStack(spacing: 12) { HStack(spacing: 12) {
Text("\(chapter.number)") Text("\(chapter.number)")
.font(.subheadline.weight(.bold).monospacedDigit()) .font(.subheadline.weight(.bold).monospacedDigit())
@@ -17,7 +17,9 @@ struct BookLibraryView: View {
ScrollView { ScrollView {
LazyVStack(spacing: 12) { LazyVStack(spacing: 12) {
ForEach(books) { book in ForEach(books) { book in
NavigationLink(value: book) { NavigationLink {
BookChapterListView(book: book)
} label: {
BookCard(book: book) BookCard(book: book)
} }
.tint(.primary) .tint(.primary)
@@ -29,12 +31,6 @@ struct BookLibraryView: View {
} }
.navigationTitle("Books") .navigationTitle("Books")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.navigationDestination(for: Book.self) { book in
BookChapterListView(book: book)
}
.navigationDestination(for: BookChapter.self) { chapter in
BookReaderView(chapter: chapter)
}
} }
} }