From d76d4fa62788bf2d5a7a98396d304e7182b62b23 Mon Sep 17 00:00:00 2001 From: Stefan Lipp Date: Sun, 15 Sep 2024 23:59:19 +0200 Subject: [PATCH] #13 Show offered disciplines in event details view --- Athlety.xcodeproj/project.pbxproj | 24 ++++++++- Athlety/Disciplines/Models/Discipline.swift | 14 ++--- .../Events/Clients/LADV/LadvDiscipline.swift | 22 ++++++++ Athlety/Events/Clients/LADV/LadvEvent.swift | 53 +++++++++++++++++++ .../Clients/{ => LADV}/LadvEventsClient.swift | 43 ++------------- .../Views/Details/EventDetailsView.swift | 10 ++++ .../Views/Details/EventDisciplinesView.swift | 26 +++++++++ Athlety/Localizable.xcstrings | 10 ++++ 8 files changed, 154 insertions(+), 48 deletions(-) create mode 100644 Athlety/Events/Clients/LADV/LadvDiscipline.swift create mode 100644 Athlety/Events/Clients/LADV/LadvEvent.swift rename Athlety/Events/Clients/{ => LADV}/LadvEventsClient.swift (81%) create mode 100644 Athlety/Events/Views/Details/EventDisciplinesView.swift diff --git a/Athlety.xcodeproj/project.pbxproj b/Athlety.xcodeproj/project.pbxproj index d7d6c9d..a6bb02c 100644 --- a/Athlety.xcodeproj/project.pbxproj +++ b/Athlety.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + B2325AA92C976138009BD8B4 /* LadvDiscipline.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2325AA82C976138009BD8B4 /* LadvDiscipline.swift */; }; + B2BDC6AF2C96E5D60071F6EC /* EventDisciplinesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BDC6AE2C96E5D60071F6EC /* EventDisciplinesView.swift */; }; + B2BDC6B22C9701940071F6EC /* LadvEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BDC6B12C9701940071F6EC /* LadvEvent.swift */; }; E300059C2ADB21EC0072F10F /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E300059B2ADB21EC0072F10F /* ProfileView.swift */; }; E300059E2ADB235D0072F10F /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = E300059D2ADB235D0072F10F /* Localizable.xcstrings */; }; E30F66072A3354C90066AC01 /* Attachement.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30F66062A3354C90066AC01 /* Attachement.swift */; }; @@ -48,6 +51,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + B2325AA82C976138009BD8B4 /* LadvDiscipline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LadvDiscipline.swift; sourceTree = ""; }; + B2BDC6AE2C96E5D60071F6EC /* EventDisciplinesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDisciplinesView.swift; sourceTree = ""; }; + B2BDC6B12C9701940071F6EC /* LadvEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LadvEvent.swift; sourceTree = ""; }; E300059B2ADB21EC0072F10F /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = ""; }; E300059D2ADB235D0072F10F /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; E30F66062A3354C90066AC01 /* Attachement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attachement.swift; sourceTree = ""; }; @@ -101,6 +107,16 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + B2BDC6B02C97017B0071F6EC /* LADV */ = { + isa = PBXGroup; + children = ( + E3496E472A142BBC00104A0B /* LadvEventsClient.swift */, + B2BDC6B12C9701940071F6EC /* LadvEvent.swift */, + B2325AA82C976138009BD8B4 /* LadvDiscipline.swift */, + ); + path = LADV; + sourceTree = ""; + }; E300059A2ADB21DE0072F10F /* Profile */ = { isa = PBXGroup; children = ( @@ -189,7 +205,7 @@ isa = PBXGroup; children = ( E3496E3C2A13F07200104A0B /* EventsClient.swift */, - E3496E472A142BBC00104A0B /* LadvEventsClient.swift */, + B2BDC6B02C97017B0071F6EC /* LADV */, ); path = Clients; sourceTree = ""; @@ -235,9 +251,10 @@ E3FA60B52BC5CBC80058E89C /* EventHeaderView.swift */, E3F84E7F2BBEF119009EC9D6 /* EventCalendarExportView.swift */, E361DE512AE1F193003BB538 /* EventAttachementsView.swift */, - E3FA60B92BC5D9700058E89C /* EventRegistrationView.swift */, + B2BDC6AE2C96E5D60071F6EC /* EventDisciplinesView.swift */, E361DE4F2AE1EE3A003BB538 /* EventLocationView.swift */, E37EC9D32ADF1F6C00F6F4C6 /* EventMapView.swift */, + E3FA60B92BC5D9700058E89C /* EventRegistrationView.swift */, ); path = Details; sourceTree = ""; @@ -422,6 +439,7 @@ E3F0FC8A2A215D6B00CC7274 /* EventDetailsView.swift in Sources */, E3FA60B62BC5CBC80058E89C /* EventHeaderView.swift in Sources */, E30F66072A3354C90066AC01 /* Attachement.swift in Sources */, + B2BDC6AF2C96E5D60071F6EC /* EventDisciplinesView.swift in Sources */, E35B03B72A1FD5CE00D25FF4 /* EventsFilterToolbar.swift in Sources */, E39859B02A1E94C8007027BA /* EventsFilterViewModel.swift in Sources */, E3496E382A13ECA300104A0B /* EventsViewModel.swift in Sources */, @@ -430,6 +448,7 @@ E3496E342A13EC3F00104A0B /* EventsView.swift in Sources */, E37EC9D62ADF205900F6F4C6 /* EventLocation.swift in Sources */, E361DE522AE1F193003BB538 /* EventAttachementsView.swift in Sources */, + B2BDC6B22C9701940071F6EC /* LadvEvent.swift in Sources */, E3EC56E52A1EAAA400EDAC4D /* EventsFilterRow.swift in Sources */, E330221D2A33E59700A998B2 /* AttachementView.swift in Sources */, E3496E522A17DEA400104A0B /* EventsFilterView.swift in Sources */, @@ -438,6 +457,7 @@ E37EC9D42ADF1F6C00F6F4C6 /* EventMapView.swift in Sources */, E3496E482A142BBC00104A0B /* LadvEventsClient.swift in Sources */, E300059C2ADB21EC0072F10F /* ProfileView.swift in Sources */, + B2325AA92C976138009BD8B4 /* LadvDiscipline.swift in Sources */, E3F84E832BBF0994009EC9D6 /* CalendarEventEditView.swift in Sources */, E376DB142A29137C00C53058 /* EventDetailsViewModel.swift in Sources */, E330221A2A33E10200A998B2 /* EventsListView.swift in Sources */, diff --git a/Athlety/Disciplines/Models/Discipline.swift b/Athlety/Disciplines/Models/Discipline.swift index 3671c1c..e716fa8 100644 --- a/Athlety/Disciplines/Models/Discipline.swift +++ b/Athlety/Disciplines/Models/Discipline.swift @@ -7,11 +7,11 @@ import Foundation -enum Discipline { - case sprint100m - case run800m - case longJump - case highJump - case javelinThrow - case shotPut +enum Discipline: String { + case sprint100m = "100 m" + case run800m = "800 m" + case longJump = "Long Jump" + case highJump = "High Jump" + case javelinThrow = "Javelin Throw" + case shotPut = "Shot Put" } diff --git a/Athlety/Events/Clients/LADV/LadvDiscipline.swift b/Athlety/Events/Clients/LADV/LadvDiscipline.swift new file mode 100644 index 0000000..6b6558e --- /dev/null +++ b/Athlety/Events/Clients/LADV/LadvDiscipline.swift @@ -0,0 +1,22 @@ +// +// LadvDisciplilne.swift +// Athlety +// +// Created by Stefan Lipp on 15.09.24. +// + +import Foundation + +extension Discipline { + + static var disciplineForLadvCode: [String : Discipline] { + [ + "L100" : .sprint100m, + "L800" : .run800m, + "TWEI" : .longJump, + "THOC" : .highJump, + "TSPE" : .javelinThrow, + "TKUG" : .shotPut + ] + } +} diff --git a/Athlety/Events/Clients/LADV/LadvEvent.swift b/Athlety/Events/Clients/LADV/LadvEvent.swift new file mode 100644 index 0000000..4ddf28e --- /dev/null +++ b/Athlety/Events/Clients/LADV/LadvEvent.swift @@ -0,0 +1,53 @@ +// +// LadvEvent.swift +// Athlety +// +// Created by Stefan Lipp on 15.09.24. +// + +import Foundation + +struct LadvEvent: Codable { + let id: Int + let name: String + let ort: String + let datum: Int +} + +struct LadvEventDetails: Codable { + let id: Int + let name: String + let ort: LadvEventLocation + let sportstaette: String + let datum: Int + + let meldEmail: String + let meldDatum: Int + + let attachements: [LadvEventAttachement] + let wettbewerbe: [LadvEventCompetition] +} + +struct LadvEventLocation: Codable { + let id: Int + let name: String + let lat: Double + let lng: Double +} + +struct LadvEventAttachement: Codable { + let name: String + let url: String + let fileExtension: String + + enum CodingKeys: String, CodingKey { + case name + case url + case fileExtension = "extension" + } +} + +struct LadvEventCompetition: Codable { + let disziplinNew: String + let klasseNew: String +} diff --git a/Athlety/Events/Clients/LadvEventsClient.swift b/Athlety/Events/Clients/LADV/LadvEventsClient.swift similarity index 81% rename from Athlety/Events/Clients/LadvEventsClient.swift rename to Athlety/Events/Clients/LADV/LadvEventsClient.swift index 104af42..90df42c 100644 --- a/Athlety/Events/Clients/LadvEventsClient.swift +++ b/Athlety/Events/Clients/LADV/LadvEventsClient.swift @@ -72,7 +72,7 @@ class LadvEventsClient: EventsClient { location: toEventLocation(ladvEvent), registration: toEventRegistration(ladvEvent), attachements: ladvEvent.attachements.compactMap(toAttachement), - disciplines: [] + disciplines: Array(Set(ladvEvent.wettbewerbe.compactMap(toDiscipline))) ) } @@ -104,43 +104,8 @@ class LadvEventsClient: EventsClient { ) } - - private struct LadvEvent: Codable { - let id: Int - let name: String - let ort: String - let datum: Int - } - - private struct LadvEventDetails: Codable { - let id: Int - let name: String - let ort: LadvEventLocation - let sportstaette: String - let datum: Int - - let meldEmail: String - let meldDatum: Int - - let attachements: [LadvEventAttachement] - } - - private struct LadvEventLocation: Codable { - let id: Int - let name: String - let lat: Double - let lng: Double - } - - private struct LadvEventAttachement: Codable { - let name: String - let url: String - let fileExtension: String - - enum CodingKeys: String, CodingKey { - case name - case url - case fileExtension = "extension" - } + private func toDiscipline(_ ladvCompetition: LadvEventCompetition) -> Discipline? { + let ladvDisciplineCode = ladvCompetition.disziplinNew + return Discipline.disciplineForLadvCode[ladvDisciplineCode] } } diff --git a/Athlety/Events/Views/Details/EventDetailsView.swift b/Athlety/Events/Views/Details/EventDetailsView.swift index 02bcc64..f107bc7 100644 --- a/Athlety/Events/Views/Details/EventDetailsView.swift +++ b/Athlety/Events/Views/Details/EventDetailsView.swift @@ -34,6 +34,12 @@ struct EventDetailsView: View { } .listSectionSeparator(.hidden) } + if !disciplines.isEmpty { + Section { + EventDisciplinesView(disciplines: disciplines) + } + .listSectionSeparator(.hidden) + } if let location = viewModel.event?.location { Section { EventLocationView(location: location) @@ -65,6 +71,10 @@ struct EventDetailsView: View { private var attachements: [Attachement] { viewModel.event?.attachements ?? [] } + + private var disciplines: [Discipline] { + viewModel.event?.disciplines ?? [] + } } struct EventDetailsView_Previews: PreviewProvider { diff --git a/Athlety/Events/Views/Details/EventDisciplinesView.swift b/Athlety/Events/Views/Details/EventDisciplinesView.swift new file mode 100644 index 0000000..a1caf46 --- /dev/null +++ b/Athlety/Events/Views/Details/EventDisciplinesView.swift @@ -0,0 +1,26 @@ +// +// EventDisciplinesView.swift +// Athlety +// +// Created by Stefan Lipp on 15.09.24. +// + +import SwiftUI + +struct EventDisciplinesView: View { + + let disciplines: [Discipline] + + var body: some View { + Text("Disciplines") + .fontWeight(.medium) + .font(.title2) + .padding(.top) + .padding(.bottom, 8) + + ForEach(disciplines, id: \.self) { discipline in + Text(discipline.rawValue) + .padding(.vertical, 8) + } + } +} diff --git a/Athlety/Localizable.xcstrings b/Athlety/Localizable.xcstrings index d9bee31..71039a4 100644 --- a/Athlety/Localizable.xcstrings +++ b/Athlety/Localizable.xcstrings @@ -51,6 +51,16 @@ } } }, + "Disciplines" : { + "localizations" : { + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Disziplinen" + } + } + } + }, "Done" : { "localizations" : { "de" : {