mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-27 15:14:35 +00:00
Fix Mac crash when opening a book from search.
Defer NavigationStack path updates until after the practice tab is active so SwiftUI does not trap in boundPathChange. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e5e8967187
commit
b6fa222659
3 changed files with 37 additions and 12 deletions
|
|
@ -51,13 +51,7 @@ final class AppModel: ObservableObject {
|
||||||
tab = .practice
|
tab = .practice
|
||||||
practicePath = []
|
practicePath = []
|
||||||
default:
|
default:
|
||||||
tab = .practice
|
applyPracticeRoute(r, replace: practicePath.isEmpty)
|
||||||
if practicePath.last == r { return }
|
|
||||||
if practicePath.isEmpty {
|
|
||||||
practicePath = r.stack
|
|
||||||
} else {
|
|
||||||
practicePath.append(r)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,8 +69,25 @@ final class AppModel: ObservableObject {
|
||||||
tab = .practice
|
tab = .practice
|
||||||
practicePath = []
|
practicePath = []
|
||||||
default:
|
default:
|
||||||
tab = .practice
|
// Switching tabs and assigning a deep NavigationStack path in the
|
||||||
practicePath = r.stack
|
// same turn crashes SwiftUI on macOS (boundPathChange / unexpectedError).
|
||||||
|
applyPracticeRoute(r, replace: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the practice tab path safely, especially when jumping from Search.
|
||||||
|
private func applyPracticeRoute(_ r: Route, replace: Bool) {
|
||||||
|
let stack = replace ? r.stack : (practicePath + [r])
|
||||||
|
if !replace, practicePath.last == r { return }
|
||||||
|
let switching = tab != .practice
|
||||||
|
tab = .practice
|
||||||
|
if switching || replace {
|
||||||
|
practicePath = []
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
self?.practicePath = stack
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
practicePath = stack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,14 @@ enum Route: Hashable {
|
||||||
if id == "1984" { return "cetba1984" }
|
if id == "1984" { return "cetba1984" }
|
||||||
if id == "fuks" { return "cetbaFuks" }
|
if id == "fuks" { return "cetbaFuks" }
|
||||||
return "cetba_" + id.replacingOccurrences(of: "-", with: "_")
|
return "cetba_" + id.replacingOccurrences(of: "-", with: "_")
|
||||||
case .bookQuiz(let id): return id == "1984" ? "cetba1984quiz" : "cetbaFuksQuiz"
|
case .bookQuiz(let id):
|
||||||
case .bookPlot(let id): return id == "1984" ? "cetba1984dej" : "cetbaFuksDej"
|
if id == "1984" { return "cetba1984quiz" }
|
||||||
|
if id == "fuks" { return "cetbaFuksQuiz" }
|
||||||
|
return "cetba_" + id.replacingOccurrences(of: "-", with: "_") + "_quiz"
|
||||||
|
case .bookPlot(let id):
|
||||||
|
if id == "1984" { return "cetba1984dej" }
|
||||||
|
if id == "fuks" { return "cetbaFuksDej" }
|
||||||
|
return "cetba_" + id.replacingOccurrences(of: "-", with: "_") + "_dej"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,6 +129,14 @@ func routeFromPage(_ page: String) -> Route? {
|
||||||
case "cetbaFuksQuiz": return .bookQuiz("fuks")
|
case "cetbaFuksQuiz": return .bookQuiz("fuks")
|
||||||
case "cetbaFuksDej": return .bookPlot("fuks")
|
case "cetbaFuksDej": return .bookPlot("fuks")
|
||||||
default:
|
default:
|
||||||
|
if page.hasPrefix("cetba_"), page.hasSuffix("_quiz") {
|
||||||
|
let slug = String(page.dropFirst(6).dropLast(5)).replacingOccurrences(of: "_", with: "-")
|
||||||
|
return .bookQuiz(slug)
|
||||||
|
}
|
||||||
|
if page.hasPrefix("cetba_"), page.hasSuffix("_dej") {
|
||||||
|
let slug = String(page.dropFirst(6).dropLast(4)).replacingOccurrences(of: "_", with: "-")
|
||||||
|
return .bookPlot(slug)
|
||||||
|
}
|
||||||
if page.hasPrefix("cetba_") {
|
if page.hasPrefix("cetba_") {
|
||||||
let slug = String(page.dropFirst(6)).replacingOccurrences(of: "_", with: "-")
|
let slug = String(page.dropFirst(6)).replacingOccurrences(of: "_", with: "-")
|
||||||
return .book(slug)
|
return .book(slug)
|
||||||
|
|
|
||||||
|
|
@ -939,7 +939,7 @@ struct BookScreen: View {
|
||||||
}
|
}
|
||||||
ForEach(Array(b.arr("notes").enumerated()), id: \.offset) { _, note in
|
ForEach(Array(b.arr("notes").enumerated()), id: \.offset) { _, note in
|
||||||
Section(note.str("title")) {
|
Section(note.str("title")) {
|
||||||
ForEach(note.strs("lines"), id: \.self) { line in
|
ForEach(Array(note.strs("lines").enumerated()), id: \.offset) { _, line in
|
||||||
Text(line)
|
Text(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue