Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ladislas/feature/contentkit add activity sample #654

Merged
merged 9 commits into from
Feb 15, 2024
24 changes: 18 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,50 @@ repos:
language: script
files: '.*\.xcstrings'

- id: check_yaml_data_professions
- id: check_yaml_definitions_professions
name: Check professions.yml
description: |
This hook checks professions.yml for:
- non unique ids
- jtd schema validation
It also formats the file and sorts the entries
entry: python3 Tools/Hooks/check_yaml_data_professions.py
entry: python3 Tools/Hooks/check_yaml_definitions_professions.py
language: python
additional_dependencies: ["ruamel.yaml"]
files: professions.yml

- id: check_yaml_data_authors
- id: check_yaml_definitions_authors
name: Check authors.yml
description: |
This hook checks authors.yml for:
- non unique ids
- jtd schema validation
It also formats the file and sorts the entries
entry: python3 Tools/Hooks/check_yaml_data_authors.py
entry: python3 Tools/Hooks/check_yaml_definitions_authors.py
language: python
additional_dependencies: ["ruamel.yaml"]
files: authors.yml

- id: check_yaml_data_skills
- id: check_yaml_definitions_skills
name: Check skills.yml
description: |
This hook checks skills.yml for:
- non unique ids
- jtd schema validation
It also formats the file and sorts the entries
entry: python3 Tools/Hooks/check_yaml_data_skills.py
entry: python3 Tools/Hooks/check_yaml_definitions_skills.py
language: python
additional_dependencies: ["ruamel.yaml"]
files: skills.yml

- id: check_yaml_content_activities
name: Check activity.yml files
description: |
This hook checks activity.yml files for:
- uuid and filename consistency
- jtd schema validation
entry: python3 Tools/Hooks/check_yaml_content_activities.py
language: python
additional_dependencies: ["ruamel.yaml"]
files: .*\.activity\.yml
types: [yaml]
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()
}
}
}
}
Loading
Loading