From d1afadd5714e281b6ecd72f81d173471dc627c1c Mon Sep 17 00:00:00 2001 From: Mathieu GROUSSEAU Date: Wed, 11 Jun 2025 09:40:41 +0200 Subject: [PATCH] Scoreboard reusable view column fix --- App/App/Localizable.xcstrings | 20 ++++++++++++++++++-- App/App/View/NewGameView.swift | 12 ++++++------ App/App/View/PlayerVSPage.swift | 6 ++++-- App/App/View/SavedGamesView.swift | 10 +++++++--- App/App/View/ScoreboardView.swift | 20 +++++++++++++++----- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/App/App/Localizable.xcstrings b/App/App/Localizable.xcstrings index d85f283..0421885 100644 --- a/App/App/Localizable.xcstrings +++ b/App/App/Localizable.xcstrings @@ -1,7 +1,23 @@ { "sourceLanguage" : "en", "strings" : { - "%@ scoreboard.column.players.entry %@" : { + "%@ savedGames.section.finished.entry %@" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "%1$@ won against %2$@" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "%1$@ bat %2$@" + } + } + } + }, + "%@ savedGames.section.unfinished.entry %@" : { "localizations" : { "en" : { "stringUnit" : { @@ -584,4 +600,4 @@ } }, "version" : "1.0" -} +} \ No newline at end of file diff --git a/App/App/View/NewGameView.swift b/App/App/View/NewGameView.swift index 159af77..3b5d168 100644 --- a/App/App/View/NewGameView.swift +++ b/App/App/View/NewGameView.swift @@ -82,12 +82,12 @@ private struct PlayerSectionView: View { // //} - // TODO: actual photo support - Image(systemName: "camera.viewfinder").overlay { - PhotosPicker(selection: $photo) { - Text("newGame.player.photo.picker") - } - } + // // TODO: actual photo support + // Image(systemName: "camera.viewfinder").overlay { + // PhotosPicker(selection: $photo) { + // Text("newGame.player.photo.picker") + // } + // } } init(settings: PlayerSettingsVM) { diff --git a/App/App/View/PlayerVSPage.swift b/App/App/View/PlayerVSPage.swift index 888452f..9680f05 100644 --- a/App/App/View/PlayerVSPage.swift +++ b/App/App/View/PlayerVSPage.swift @@ -36,8 +36,10 @@ struct PlayerVSPage: View { PlayerPicker() } - - ScoreboardView() + + ScoreboardView("scoreboard.table.column.players") { result in + "\(result.player1) savedGames.section.finished.entry \(result.player2)" + } } } } diff --git a/App/App/View/SavedGamesView.swift b/App/App/View/SavedGamesView.swift index 69be640..f6cae40 100644 --- a/App/App/View/SavedGamesView.swift +++ b/App/App/View/SavedGamesView.swift @@ -11,10 +11,14 @@ struct SavedGamesView: View { var body: some View { // TODO: use the same collection view with headers instead? Or use collapsible sections? Section("savedGames.section.unfinished") { - ScoreboardView() + ScoreboardView("scoreboard.table.column.players") { result in + "\(result.player1) savedGames.section.unfinished.entry \(result.player2)" + } } - Section("savedGames.section.finished"){ - ScoreboardView() + Section("savedGames.section.finished") { + ScoreboardView("scoreboard.table.column.players") { result in + "\(result.player1) savedGames.section.finished.entry \(result.player2)" + } } } } diff --git a/App/App/View/ScoreboardView.swift b/App/App/View/ScoreboardView.swift index d622749..a4c9bbd 100644 --- a/App/App/View/ScoreboardView.swift +++ b/App/App/View/ScoreboardView.swift @@ -9,7 +9,10 @@ import SwiftUI struct ScoreboardView: View { @Environment(\.horizontalSizeClass) - private var horizontalSizeClass + private var horizontalSizeClass: UserInterfaceSizeClass? + + private let playerRelatedColumnKey: LocalizedStringKey + private let localizedKeyProvider: (Result) -> LocalizedStringKey @State private var unsinished = [ Result(date: Date.now, player1: "P1", player2: "P2", rules: "Rule1"), @@ -24,7 +27,7 @@ struct ScoreboardView: View { if horizontalSizeClass == .compact { List(self.unsinished) { result in VStack(alignment: .center) { - Text("\(result.player1) scoreboard.column.players.entry \(result.player2)") + Text(localizedKeyProvider(result)) HStack { Text(result.date, style: .date) Spacer() @@ -37,15 +40,22 @@ struct ScoreboardView: View { TableColumn("scoreboard.table.column.date") { result in Text(result.date, style: .date) } - TableColumn("scoreboard.table.column.players") { result in - Text("\(result.player1) scoreboard.column.players.entry \(result.player2)") + TableColumn(playerRelatedColumnKey) { result in + Text(localizedKeyProvider(result)) } TableColumn("scoreboard.table.column.rules", value: \.rules) } } } + + public init(_ playerRelatedColumnKey: LocalizedStringKey, localizedKeyProvider: @escaping (Result) -> LocalizedStringKey) { + self.playerRelatedColumnKey = playerRelatedColumnKey + self.localizedKeyProvider = localizedKeyProvider + } } #Preview { - ScoreboardView() + ScoreboardView("scoreboard.table.column.players") { result in + "\(result.player1) savedGames.section.unfinished.entry \(result.player2)" + } }