From 54f89bcd1a7fb0b92b65d8c0ea3847d635e11133 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Sun, 6 Jul 2025 12:45:37 +0200 Subject: Allow adding and removing templates --- Map/Business/Stage.swift | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'Map/Business/Stage.swift') diff --git a/Map/Business/Stage.swift b/Map/Business/Stage.swift index fcbdb62..4b98ecc 100644 --- a/Map/Business/Stage.swift +++ b/Map/Business/Stage.swift @@ -20,7 +20,6 @@ struct Stage: Codable { var iii: String var iv: String - static func stages(_ type: StageType) -> Stage { switch type { case .general: @@ -127,15 +126,15 @@ struct Stage: Codable { iv: "Known / common usage") case .custom(let uuid): if let customStagesData = UserDefaults.standard.data(forKey: "customStages"), - let customStagesList = try? JSONDecoder().decode([CustomStage].self, from: customStagesData), - let customStage = customStagesList.first(where: { $0.id == uuid }) { + let customStagesList = try? JSONDecoder().decode( + [CustomStage].self, from: customStagesData), + let customStage = customStagesList.first(where: { $0.id == uuid }) + { return customStage.stage } - return stages(.behavior) // fallback + return stages(.behavior) // fallback } } - - static func title(_ type: StageType) -> String { switch type { @@ -181,11 +180,13 @@ struct Stage: Codable { return String(localized: "stage_type.behavior") case .custom(let uuid): if let customStagesData = UserDefaults.standard.data(forKey: "customStages"), - let customStagesList = try? JSONDecoder().decode([CustomStage].self, from: customStagesData), - let customStage = customStagesList.first(where: { $0.id == uuid }) { + let customStagesList = try? JSONDecoder().decode( + [CustomStage].self, from: customStagesData), + let customStage = customStagesList.first(where: { $0.id == uuid }) + { return customStage.name } - return String(localized: "stage_type.behavior") // fallback + return String(localized: "stage_type.behavior") // fallback } } } @@ -216,7 +217,7 @@ enum StageType: Identifiable, Equatable { case behavior case custom(UUID) - var id: String { + var id: String { switch self { case .general: return "general" case .practice: return "practice" @@ -249,10 +250,11 @@ enum StageType: Identifiable, Equatable { .perceptionInIndustry, .focusOfValue, .understanding, .comparison, .failure, .marketAction, .efficiency, .decisionDrivers, ] - + static var customStages: [StageType] { if let customStagesData = UserDefaults.standard.data(forKey: "customStages"), - let customStagesList = try? JSONDecoder().decode([CustomStage].self, from: customStagesData) { + let customStagesList = try? JSONDecoder().decode([CustomStage].self, from: customStagesData) + { return customStagesList.map { .custom($0.id) } } return [] -- cgit