Add year-1 civics lessons on life in a community and keep later years locked.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
pepaskopec-blip 2026-10-02 11:44:21 +02:00
commit 515abdc6ce
28 changed files with 2665 additions and 12 deletions

View file

@ -128,6 +128,11 @@ final class AppModel: ObservableObject {
refresh()
}
func markOn(_ id: Int) {
progress.markOn(id)
refresh()
}
func markMluv(_ n: Int) {
progress.markMluv(n)
refresh()

View file

@ -31,6 +31,7 @@ final class Content {
let netTasks: [J]
let netAnswers: [[J]]
let hw: [J]
let on: [J]
let mluvnice: [J]
let books: [J]
let changelog: [J]
@ -62,6 +63,7 @@ final class Content {
netAnswers = []
}
hw = raw.arr("hw")
on = raw.arr("on")
mluvnice = raw.arr("mluvnice")
books = raw.arr("books")
changelog = raw.arr("changelog")
@ -70,6 +72,7 @@ final class Content {
func germanUnit(_ id: Int) -> J? { german.first { $0.int("id") == id } }
func netLesson(_ id: Int) -> J? { netLessons.first { $0.int("id") == id } }
func hwLesson(_ id: Int) -> J? { hw.first { $0.int("id") == id } }
func onLesson(_ id: Int) -> J? { on.first { $0.int("id") == id } }
func mluv(_ n: Int) -> J? { mluvnice.first { $0.int("id") == n } }
func book(_ id: String) -> J? { books.first { $0.str("id") == id } }

View file

@ -34,6 +34,9 @@ final class ProgressStore {
func hwDone(_ id: Int) -> Bool { defaults.bool(forKey: "hw.\(id)") }
func markHw(_ id: Int) { defaults.set(true, forKey: "hw.\(id)") }
func onDone(_ id: Int) -> Bool { defaults.bool(forKey: "on.\(id)") }
func markOn(_ id: Int) { defaults.set(true, forKey: "on.\(id)") }
func mluvDone(_ n: Int) -> Bool { defaults.bool(forKey: "mluv.\(n)") }
func markMluv(_ n: Int) { defaults.set(true, forKey: "mluv.\(n)") }
@ -77,6 +80,14 @@ func summarize(_ content: Content, _ p: ProgressStore) -> ProgressSum {
sum.doneUnits += 1
}
}
for l in content.on {
sum.totalEx += 1
sum.openUnits += 1
if p.onDone(l.int("id")) {
sum.doneEx += 1
sum.doneUnits += 1
}
}
sum.totalEx += content.mluvnice.count
sum.openUnits += 1
let md = content.mluvnice.filter { p.mluvDone($0.int("id")) }.count

View file

@ -23,6 +23,10 @@ enum Route: Hashable {
case hwMap
case hwLesson(Int)
case hwEx(Int)
case onYears
case onMap
case onLesson(Int)
case onEx(Int)
case czechMap
case mluvnice
case mluvEx(Int)
@ -48,6 +52,10 @@ enum Route: Hashable {
case .hwMap: return "hwmap"
case .hwLesson(let id): return "hwunit\(id)"
case .hwEx(let id): return "hwex\(id)"
case .onYears: return "onyears"
case .onMap: return "onmap"
case .onLesson(let id): return "onunit\(id)"
case .onEx(let id): return "onex\(id)"
case .czechMap: return "czechmap"
case .mluvnice: return "mluvnice"
case .mluvEx(let n): return "mluve\(n)"
@ -96,6 +104,14 @@ enum Route: Hashable {
return [.hwYears, .hwMap, .hwLesson(id)]
case .hwEx(let id):
return [.hwYears, .hwMap, .hwLesson(id), .hwEx(id)]
case .onYears:
return [.onYears]
case .onMap:
return [.onYears, .onMap]
case .onLesson(let id):
return [.onYears, .onMap, .onLesson(id)]
case .onEx(let id):
return [.onYears, .onMap, .onLesson(id), .onEx(id)]
case .czechMap:
return [.czechMap]
case .mluvnice:
@ -124,6 +140,8 @@ func routeFromPage(_ page: String) -> Route? {
case "netmap": return .netMap
case "hwyears": return .hwYears
case "hwmap": return .hwMap
case "onyears": return .onYears
case "onmap": return .onMap
case "czechmap": return .czechMap
case "mluvnice": return .mluvnice
case "readinglist": return .readingList
@ -167,6 +185,12 @@ func routeFromPage(_ page: String) -> Route? {
if let m = page.wholeMatch(of: /hwex(\d+)/), let n = Int(m.1) {
return .hwEx(n)
}
if let m = page.wholeMatch(of: /onunit(\d+)/), let n = Int(m.1) {
return .onLesson(n)
}
if let m = page.wholeMatch(of: /onex(\d+)/), let n = Int(m.1) {
return .onEx(n)
}
if let m = page.wholeMatch(of: /mluve(\d+)/), let n = Int(m.1) {
return .mluvEx(n)
}

View file

@ -465,6 +465,7 @@ func subjectSymbol(_ icon: String) -> String {
case "wifi": return "wifi"
case "chip": return "cpu"
case "cz": return "text.book.closed.fill"
case "people": return "person.2.fill"
default: return "lock.fill"
}
}

View file

@ -625,6 +625,25 @@ struct NetQuizScreen: View {
}
}
struct OnQuizScreen: View {
@ObservedObject var vm: AppModel
let id: Int
var body: some View {
if let lesson = vm.content.onLesson(id) {
let spec = J([
"type": "choice",
"title": vm.tr(lesson.str("exTitleKey")),
"sub": lesson.str("quizHeadKey"),
"questions": lesson.rawArray("quiz"),
])
DispatchExercise(vm: vm, spec: spec, titleFallback: vm.tr(lesson.str("exTitleKey"))) {
vm.markOn(id)
}
}
}
}
struct HwQuizScreen: View {
@ObservedObject var vm: AppModel
let id: Int

View file

@ -423,6 +423,9 @@ private func subjectSum(_ vm: AppModel, _ s: J) -> ProgressSum {
case "hwyears", "hwmap":
sum.totalEx = vm.content.hw.count
sum.doneEx = vm.content.hw.filter { vm.progress.hwDone($0.int("id")) }.count
case "onyears", "onmap":
sum.totalEx = vm.content.on.count
sum.doneEx = vm.content.on.filter { vm.progress.onDone($0.int("id")) }.count
case "czechmap":
sum.totalEx = vm.content.mluvnice.count
sum.doneEx = vm.content.mluvnice.filter { vm.progress.mluvDone($0.int("id")) }.count
@ -561,6 +564,14 @@ private func buildSearch(_ vm: AppModel) -> [Hit] {
add(vm.tr(l.str("titleKey")), vm.tr("search_lesson"), "hwunit\(l.int("id"))", extra: "hardware")
add(vm.tr(l.str("titleKey")), vm.tr("search_exercise"), "hwex\(l.int("id"))")
}
add(vm.tr("on_year1"), vm.tr("search_lesson"), "onmap", extra: "rocnik")
add(vm.tr("on_year2"), vm.tr("search_lesson"), "onyears", locked: true, extra: "rocnik")
add(vm.tr("on_year3"), vm.tr("search_lesson"), "onyears", locked: true, extra: "rocnik")
add(vm.tr("on_year4"), vm.tr("search_lesson"), "onyears", locked: true, extra: "rocnik")
for l in vm.content.on {
add(vm.tr(l.str("titleKey")), vm.tr("search_lesson"), "onunit\(l.int("id"))", extra: "obcanka")
add(vm.tr(l.str("titleKey")), vm.tr("search_exercise"), "onex\(l.int("id"))")
}
add(vm.tr("Mluvnice"), vm.tr("search_lesson"), "mluvnice")
add(vm.tr("Maturitní četba"), vm.tr("search_book"), "readinglist")
for b in vm.content.books {
@ -777,6 +788,29 @@ struct HwYearsScreen: View {
}
}
struct OnYearsScreen: View {
@ObservedObject var vm: AppModel
var body: some View {
List {
NavigationLink(value: Route.onMap) {
ListRowLabel(title: vm.tr("on_year1"), subtitle: vm.tr("on_sub"))
}
ForEach(["on_year2", "on_year3", "on_year4"], id: \.self) { key in
Label {
ListRowLabel(title: vm.tr(key), subtitle: vm.tr("on_year_locked_sub"))
} icon: {
Image(systemName: "lock.fill")
}
.foregroundStyle(.secondary)
}
}
.navigationTitle(vm.tr("Občanská nauka"))
.navigationSubtitle(vm.tr("on_years_sub"))
.appListStyle()
}
}
struct LessonRow: Identifiable {
let id: String
let title: String
@ -1345,6 +1379,29 @@ struct RouteDestination: View {
}
case .hwEx(let id):
HwQuizScreen(vm: vm, id: id)
case .onYears:
OnYearsScreen(vm: vm)
case .onMap:
LessonListScreen(
vm: vm,
title: vm.tr("on_year1"),
subtitle: vm.tr("on_sub"),
rows: vm.content.on.map { l in
let id = l.int("id")
return LessonRow(
id: "o\(id)",
title: vm.tr(l.str("titleKey")),
done: vm.progress.onDone(id),
destination: .onLesson(id)
)
}
)
case .onLesson(let id):
if let l = vm.content.onLesson(id) {
SlidesScreen(vm: vm, title: vm.tr(l.str("titleKey")), subtitle: vm.tr(l.str("subKey")), slides: l.arr("slides"), next: .onEx(id))
}
case .onEx(let id):
OnQuizScreen(vm: vm, id: id)
case .czechMap:
CzechMapScreen(vm: vm)
case .mluvnice: