Skip to content
Merged

fix #33

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions SportApp/Tournirs/View/TournirsDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,10 @@ struct TournirsDetail: View {
.frame(height: 1)
.padding(.horizontal, 12)

if coordinator.user.isAdmin == false {
List {
HStack {
Text("Участники")
.padding(.leading)

Spacer()
}
ScrollView {
ForEach(viewModel.participants, id: \.id) { participant in
Text(participant.phio)
.padding()
}
}
}
} else {
if coordinator.currentTournir!.tournirInstanteState != .openedRegistrationTournaments {
scale
} else {
participantsView
}

if coordinator.user.isAdmin == false {
Expand All @@ -105,24 +92,12 @@ struct TournirsDetail: View {
.padding()
}
} else {
if coordinator.currentTournir!.tournirInstanteState == .endedTournaments {
if coordinator.currentTournir!.tournirInstanteState == .ongoingTournaments || coordinator.currentTournir!.tournirInstanteState == .endedTournaments {
Text(coordinator.currentTournir!.tournirInstanteState.rawValue)
.padding()
} else {
Button(action: {
// сохранять в нормальное место
guard var currentTournir = coordinator.currentTournir else {
return
}

let newState = TournirInstaseState.nextState(currentTournir.tournirInstanteState)

if let index = viewModel2.tournirs.firstIndex(of: currentTournir) {
viewModel2.tournirs[index].tournirInstanteState = newState
}

currentTournir.tournirInstanteState = newState
coordinator.currentTournir = currentTournir
updateInstanceState()
}, label: {
Text(coordinator.currentTournir!.tournirInstanteState.rawValue)
.padding()
Expand All @@ -140,6 +115,21 @@ struct TournirsDetail: View {
}
}

private func updateInstanceState() {
guard var currentTournir = coordinator.currentTournir else {
return
}

let newState = TournirInstaseState.nextState(currentTournir.tournirInstanteState)

if let index = viewModel2.tournirs.firstIndex(of: currentTournir) {
viewModel2.tournirs[index].tournirInstanteState = newState
}

currentTournir.tournirInstanteState = newState
coordinator.currentTournir = currentTournir
}

var scale: some View {
Group {
if coordinator.currentTournir!.currentMatch <= matchs {
Expand Down Expand Up @@ -177,6 +167,7 @@ struct TournirsDetail: View {
Image(systemName: "square")
}
}
.disabled(!coordinator.user.isAdmin || coordinator.currentTournir!.tournirInstanteState == .closedRegistrationTournaments)
}

Rectangle()
Expand All @@ -200,6 +191,7 @@ struct TournirsDetail: View {
Image(systemName: "square")
}
}
.disabled(!coordinator.user.isAdmin || coordinator.currentTournir!.tournirInstanteState == .closedRegistrationTournaments)
}
}
.padding(.horizontal, 16)
Expand All @@ -210,7 +202,7 @@ struct TournirsDetail: View {
.padding(.vertical, 8)
}

Button("FFFFFFFFF мне за труд ибо я зaебался это писать") {
Button("FFFFFFFFF мне за труд ибо я устал это писать") {
var c = 0
for i in viewModel.axoroms {
if i.isFirstWinner != nil {
Expand All @@ -232,6 +224,9 @@ struct TournirsDetail: View {
Text("Победитель Влад")
}
}
.onAppear() {
updateInstanceState()
}
}
}
}
Expand All @@ -244,4 +239,21 @@ struct TournirsDetail: View {
return "1/\(number)"
}
}

var participantsView: some View {
List {
HStack {
Text("Участники")
.padding(.leading)

Spacer()
}
ScrollView {
ForEach(viewModel.participants, id: \.id) { participant in
Text(participant.phio)
.padding()
}
}
}
}
}
Loading