diff --git a/Modules/ContentKit/Examples/ContentKitExample/Sources/MainView.swift b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift similarity index 63% rename from Modules/ContentKit/Examples/ContentKitExample/Sources/MainView.swift rename to Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift index db0d522381..8519802a2f 100644 --- a/Modules/ContentKit/Examples/ContentKitExample/Sources/MainView.swift +++ b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityDetailsView.swift @@ -7,13 +7,6 @@ import LocalizationKit import MarkdownUI import SwiftUI -extension Theme { - static let leka: Theme = .gitHub - .text { - BackgroundColor(.clear) - } -} - // MARK: - RowView struct RowView: View { @@ -44,21 +37,23 @@ struct RowView: View { } } -// MARK: - MainView +// MARK: - ActivityDetailsView -struct MainView: View { +struct ActivityDetailsView: View { // MARK: Internal + let activity: Activity + var body: some View { List { Section("Information") { - RowView(label: "UUID", value: self.activity?.id ?? "nil") - RowView(label: "Name", value: self.activity?.name ?? "nil") + RowView(label: "UUID", value: self.activity.id) + RowView(label: "Name", value: self.activity.name) - RowView(label: "Status", value: self.activity?.status == .published ? "published" : "draft") + RowView(label: "Status", value: self.activity.status == .published ? "published" : "draft") DisclosureGroup("**Authors**") { - ForEach(self.activity?.authors ?? [], id: \.self) { author in + ForEach(self.activity.authors, id: \.self) { author in let author = Authors.hmi(id: author)! HStack { Text(author.name) @@ -79,13 +74,13 @@ struct MainView: View { }) DisclosureGroup("**Available languages**") { - ForEach(self.activity?.languages ?? [], id: \.self) { lang in + ForEach(self.activity.languages, id: \.self) { lang in Text(lang.identifier) } } DisclosureGroup("**Skills**") { - ForEach(self.activity?.skills ?? [], id: \.self) { skill in + ForEach(self.activity.skills, id: \.self) { skill in let skill = Skills.skill(id: skill)! HStack { Text(skill.name) @@ -106,7 +101,7 @@ struct MainView: View { }) DisclosureGroup("**HMI**") { - ForEach(self.activity?.hmi ?? [], id: \.self) { hmi in + ForEach(self.activity.hmi, id: \.self) { hmi in let hmi = HMI.hmi(id: hmi)! HStack { Text(hmi.name) @@ -127,51 +122,24 @@ struct MainView: View { }) DisclosureGroup("**Tags**") { - ForEach(self.activity?.tags ?? [], id: \.self) { skill in + ForEach(self.activity.tags, id: \.self) { skill in Text(skill) } } } Section("Details (in: \(l10n.language.identifier))") { - Text(self.activity?.details.title ?? "nil") + Text(self.activity.details.title) .font(.title) - Text(self.activity?.details.subtitle ?? "nil") + Text(self.activity.details.subtitle) .font(.title2) - Markdown(self.activity?.details.description ?? "nil") - .markdownTheme(.leka) - Markdown(self.activity?.details.instructions ?? "nil") - .markdownTheme(.leka) - } - } - .onAppear { - self.activity = ContentKit.decodeActivity("activity") - print(self.activity ?? "not working") - - let skills = Skills.list - for (index, skill) in skills.enumerated() { - print("skill \(index + 1)") - print("id: \(skill.id)") - print("name: \(skill.name)") - print("description: \(skill.description)") - } - - let hmis = HMI.list - for (index, hmi) in hmis.enumerated() { - print("hmi \(index + 1)") - print("id: \(hmi.id)") - print("name: \(hmi.name)") - print("description: \(hmi.description)") - } - - let authors = Authors.list - for (index, author) in authors.enumerated() { - print("author \(index + 1)") - print("id: \(author.id)") - print("name: \(author.name)") - print("description: \(author.description)") + Markdown(self.activity.details.description) + .markdownTheme(.gitHub) + Markdown(self.activity.details.instructions) + .markdownTheme(.gitHub) } } + .navigationTitle(self.activity.name) } // MARK: Private @@ -179,10 +147,10 @@ struct MainView: View { @State private var selectedSkill: Skill? @State private var selectedHMI: HMIDetails? @State private var selectedAuthor: Author? - - @State private var activity: Activity? } #Preview { - MainView() + NavigationStack { + ActivityDetailsView(activity: Activity.mock) + } } diff --git a/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityListView.swift b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityListView.swift new file mode 100644 index 0000000000..1c9425e4cd --- /dev/null +++ b/Modules/ContentKit/Examples/ContentKitExample/Sources/ActivityListView.swift @@ -0,0 +1,55 @@ +// Leka - iOS Monorepo +// Copyright APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +import ContentKit +import MarkdownUI +import SwiftUI + +// MARK: - ActivityListView + +struct ActivityListView: View { + let activities: [Activity] = ContentKit.listSampleActivities() ?? [] + + var body: some View { + List { + ForEach(self.activities) { activity in + NavigationLink(destination: ActivityDetailsView(activity: activity)) { + Text(activity.name) + } + } + } + .navigationTitle("Activities") + .onAppear { + let skills = Skills.list + for (index, skill) in skills.enumerated() { + print("skill \(index + 1)") + print("id: \(skill.id)") + print("name: \(skill.name)") + print("description: \(skill.description)") + } + + let hmis = HMI.list + for (index, hmi) in hmis.enumerated() { + print("hmi \(index + 1)") + print("id: \(hmi.id)") + print("name: \(hmi.name)") + print("description: \(hmi.description)") + } + + let authors = Authors.list + for (index, author) in authors.enumerated() { + print("author \(index + 1)") + print("id: \(author.id)") + print("name: \(author.name)") + print("description: \(author.description)") + } + } + } +} + +#Preview { + NavigationStack { + ActivityListView() + } +} diff --git a/Modules/ContentKit/Examples/ContentKitExample/Sources/MainApp.swift b/Modules/ContentKit/Examples/ContentKitExample/Sources/MainApp.swift index 7f59470fab..31c5ef3e0f 100644 --- a/Modules/ContentKit/Examples/ContentKitExample/Sources/MainApp.swift +++ b/Modules/ContentKit/Examples/ContentKitExample/Sources/MainApp.swift @@ -9,7 +9,9 @@ import SwiftUI struct ContentKitExample: App { var body: some Scene { WindowGroup { - MainView() + NavigationStack { + ActivityListView() + } } } }