@ -38,46 +38,15 @@ struct MatchSetupView: View {
if let teamScore , teamScore . luckyLoser != nil {
Text ( " Repêchée " ) . italic ( ) . font ( . caption )
}
Menu {
_removeTeam ( team : team , teamPosition : teamPosition )
} label : {
TeamRowView ( team : team , teamPosition : teamPosition )
. swipeActions ( edge : . trailing , allowsFullSwipe : false ) {
Button ( role : . cancel ) {
// t o d o
if match . isSeededBy ( team : team , inTeamPosition : teamPosition ) {
team . bracketPosition = nil
do {
try tournamentStore . teamRegistrations . addOrUpdate ( instance : team )
} catch {
Logger . error ( error )
}
match . updateTeamScores ( )
match . previousMatches ( ) . forEach { previousMatch in
if previousMatch . disabled {
previousMatch . enableMatch ( )
do {
try tournamentStore . matches . addOrUpdate ( instance : previousMatch )
} catch {
Logger . error ( error )
}
}
}
do {
try tournamentStore . matches . addOrUpdate ( instance : match )
} catch {
Logger . error ( error )
}
} else {
match . teamWillBeWalkOut ( team )
do {
try tournamentStore . matches . addOrUpdate ( instance : match )
} catch {
Logger . error ( error )
}
}
} label : {
Label ( " retirer " , systemImage : " xmark " )
_removeTeam ( team : team , teamPosition : teamPosition )
}
}
. buttonStyle ( . plain )
}
} else {
VStack ( alignment : . leading ) {
@ -207,6 +176,46 @@ struct MatchSetupView: View {
}
}
}
func _removeTeam ( team : TeamRegistration , teamPosition : TeamPosition ) -> some View {
Button ( role : . cancel ) {
// t o d o
if match . isSeededBy ( team : team , inTeamPosition : teamPosition ) {
team . bracketPosition = nil
do {
try tournamentStore . teamRegistrations . addOrUpdate ( instance : team )
} catch {
Logger . error ( error )
}
match . updateTeamScores ( )
match . previousMatches ( ) . forEach { previousMatch in
if previousMatch . disabled {
previousMatch . enableMatch ( )
do {
try tournamentStore . matches . addOrUpdate ( instance : previousMatch )
} catch {
Logger . error ( error )
}
}
}
do {
try tournamentStore . matches . addOrUpdate ( instance : match )
} catch {
Logger . error ( error )
}
} else {
match . teamWillBeWalkOut ( team )
do {
try tournamentStore . matches . addOrUpdate ( instance : match )
} catch {
Logger . error ( error )
}
}
} label : {
Label ( " retirer " , systemImage : " xmark " )
}
}
}
// # P r e v i e w {