Skip to content

Commit

Permalink
⚗️ (ContentKitExample): List sample activities, show details
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 15, 2024
1 parent 885be4a commit c1d2ac4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import LocalizationKit
import MarkdownUI
import SwiftUI

extension Theme {
static let leka: Theme = .gitHub
.text {
BackgroundColor(.clear)
}
}

// MARK: - RowView

struct RowView<T: StringProtocol>: View {
Expand Down Expand Up @@ -44,21 +37,23 @@ struct RowView<T: StringProtocol>: 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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -127,62 +122,35 @@ 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

@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)
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import SwiftUI
struct ContentKitExample: App {
var body: some Scene {
WindowGroup {
MainView()
NavigationStack {
ActivityListView()
}
}
}
}

0 comments on commit c1d2ac4

Please sign in to comment.