@ -16,9 +16,11 @@ struct GroupStageView: View {
@ State private var confirmRemoveAll : Bool = false
@ State private var confirmRemoveAll : Bool = false
@ State private var confirmResetMatch : Bool = false
@ State private var confirmResetMatch : Bool = false
@ State private var groupStageName : String = " "
@ State private var groupStageName : String = " "
let playedMatches : [ Match ]
init ( groupStage : GroupStage ) {
init ( groupStage : GroupStage ) {
self . groupStage = groupStage
self . groupStage = groupStage
self . playedMatches = groupStage . playedMatches ( )
_groupStageName = State ( wrappedValue : groupStage . groupStageTitle ( ) )
_groupStageName = State ( wrappedValue : groupStage . groupStageTitle ( ) )
}
}
@ -44,21 +46,18 @@ struct GroupStageView: View {
}
}
. headerProminence ( . increased )
. headerProminence ( . increased )
MatchListView ( section : " disponible " , matches : groupStage . availableToStart ( ) ) . id ( UUID ( ) )
let runningMatches = groupStage . runningMatches ( playedMatches : playedMatches )
MatchListView ( section : " en cours " , matches : groupStage . runningMatches ( ) ) . id ( UUID ( ) )
MatchListView ( section : " disponible " , matches : groupStage . availableToStart ( playedMatches : playedMatches , in : runningMatches ) )
MatchListView ( section : " à lancer " , matches : groupStage . readyMatches ( ) ) . id ( UUID ( ) )
MatchListView ( section : " en cours " , matches : runningMatches )
MatchListView ( section : " terminés " , matches : groupStage . finishedMatches ( ) , isExpanded : false ) . id ( UUID ( ) )
MatchListView ( section : " à lancer " , matches : groupStage . readyMatches ( playedMatches : playedMatches ) )
}
MatchListView ( section : " terminés " , matches : groupStage . finishedMatches ( playedMatches : playedMatches ) , isExpanded : false )
. onChange ( of : groupStageName ) {
groupStage . name = groupStageName
_save ( )
}
}
. toolbar {
. toolbar {
ToolbarItem ( placement : . topBarTrailing ) {
ToolbarItem ( placement : . topBarTrailing ) {
_groupStageMenuView ( )
_groupStageMenuView ( )
}
}
}
}
. navigationTitle ( $ groupStageName )
. navigationTitle ( groupStage . groupStageTitle ( ) )
}
}
private enum GroupStageSortingMode {
private enum GroupStageSortingMode {
@ -178,12 +177,10 @@ struct GroupStageView: View {
private func _groupStageMenuView ( ) -> some View {
private func _groupStageMenuView ( ) -> some View {
Menu {
Menu {
if groupStage . name != nil {
NavigationLink {
Button ( " Retirer le nom " ) {
GroupStageNameEditionView ( groupStage : groupStage )
groupStage . name = nil
} label : {
groupStageName = groupStage . groupStageTitle ( )
Label ( " Renommer " , systemImage : " pencil " )
_save ( )
}
}
}
Button ( " Retirer tout le monde " , role : . destructive ) {
Button ( " Retirer tout le monde " , role : . destructive ) {
confirmRemoveAll = true
confirmRemoveAll = true
@ -225,3 +222,46 @@ struct GroupStageView: View {
}
}
}
}
}
}
struct GroupStageNameEditionView : View {
@ EnvironmentObject var dataStore : DataStore
let groupStage : GroupStage
@ State private var groupStageName : String = " "
var body : some View {
Form {
Section {
TextField ( " Nom de la poule " , text : $ groupStageName )
. keyboardType ( . alphabet )
. frame ( maxWidth : . infinity )
. onAppear ( perform : {
groupStageName = groupStage . name ? ? " "
} )
. onSubmit {
groupStageName = groupStageName . trimmed
groupStage . name = groupStageName
_save ( )
}
} footer : {
HStack {
Spacer ( )
FooterButtonView ( " retirer le nom " ) {
groupStage . name = nil
groupStageName = groupStage . groupStageTitle ( )
_save ( )
}
}
}
}
. navigationTitle ( groupStage . groupStageTitle ( ) )
. toolbarBackground ( . visible , for : . navigationBar )
}
private func _save ( ) {
do {
try dataStore . groupStages . addOrUpdate ( instance : groupStage )
} catch {
Logger . error ( error )
}
}
}