|
|
|
@ -1,10 +1,3 @@
|
|
|
|
|
//
|
|
|
|
|
// ScoreboardView.swift
|
|
|
|
|
// App
|
|
|
|
|
//
|
|
|
|
|
// Created by etudiant2 on 28/05/2025.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
struct ScoreboardView: View {
|
|
|
|
@ -14,13 +7,19 @@ struct ScoreboardView: View {
|
|
|
|
|
private let playerRelatedColumnKey: LocalizedStringKey
|
|
|
|
|
private let localizedKeyProvider: (GameEntryVM) -> LocalizedStringKey
|
|
|
|
|
|
|
|
|
|
@State
|
|
|
|
|
private var selection: GameEntryVM.ID? = nil
|
|
|
|
|
|
|
|
|
|
@Binding
|
|
|
|
|
private var results: [GameEntryVM]
|
|
|
|
|
|
|
|
|
|
@Binding
|
|
|
|
|
private var currentGame: IngameVM?
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
if horizontalSizeClass == .compact {
|
|
|
|
|
List(self.results) { result in
|
|
|
|
|
VStack(alignment: .center) {
|
|
|
|
|
let entry = VStack(alignment: .center) {
|
|
|
|
|
Text(localizedKeyProvider(result))
|
|
|
|
|
HStack {
|
|
|
|
|
Text("generic.datetime \(Text(result.date, style: .date)) \(Text(result.date, style: .time))")
|
|
|
|
@ -28,9 +27,19 @@ struct ScoreboardView: View {
|
|
|
|
|
Text(result.rules.baseTranslationKey)
|
|
|
|
|
}.foregroundStyle(.secondary)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let game = result.game {
|
|
|
|
|
Button {
|
|
|
|
|
currentGame = IngameVM(game: game)
|
|
|
|
|
} label: {
|
|
|
|
|
entry
|
|
|
|
|
}.buttonRepeatBehavior(.disabled)
|
|
|
|
|
} else {
|
|
|
|
|
entry
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else{
|
|
|
|
|
Table(self.results) {
|
|
|
|
|
} else {
|
|
|
|
|
Table(self.results, selection: $selection) {
|
|
|
|
|
TableColumn("scoreboard.table.column.date") { result in
|
|
|
|
|
Text("generic.datetime \(Text(result.date, style: .date)) \(Text(result.date, style: .time))")
|
|
|
|
|
}
|
|
|
|
@ -40,18 +49,25 @@ struct ScoreboardView: View {
|
|
|
|
|
TableColumn("scoreboard.table.column.rules", content: { result in
|
|
|
|
|
Text(result.rules.baseTranslationKey)
|
|
|
|
|
})
|
|
|
|
|
}.contextMenu(forSelectionType: GameEntryVM.ID.self) { _ in } primaryAction: { items in
|
|
|
|
|
guard !items.isEmpty,
|
|
|
|
|
let selection,
|
|
|
|
|
let game = results.first(where: { $0.date == selection && $0.game != nil })?.game
|
|
|
|
|
else { return }
|
|
|
|
|
|
|
|
|
|
currentGame = IngameVM(game: game)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public init(results: Binding<[GameEntryVM]>, _ playerRelatedColumnKey: LocalizedStringKey, localizedKeyProvider: @escaping (GameEntryVM) -> LocalizedStringKey) {
|
|
|
|
|
public init(results: Binding<[GameEntryVM]>, currentGame: Binding<IngameVM?>, _ playerRelatedColumnKey: LocalizedStringKey, localizedKeyProvider: @escaping (GameEntryVM) -> LocalizedStringKey) {
|
|
|
|
|
self._results = results
|
|
|
|
|
self._currentGame = currentGame
|
|
|
|
|
self.playerRelatedColumnKey = playerRelatedColumnKey
|
|
|
|
|
self.localizedKeyProvider = localizedKeyProvider
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
// #Preview {
|
|
|
|
|
// ScoreboardView("scoreboard.table.column.players") { result in
|
|
|
|
|
// "\(result.player1) savedGames.section.unfinished.entry \(result.player2)"
|
|
|
|
|