Skip to content

Commit

Permalink
disabled prediction button after user predict
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaiyan committed Oct 23, 2023
1 parent 5d97e2b commit 413387c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,34 @@ struct FixtureDetailView: View {
struct PredictionView: View {
@State private var homeTeamPrediction = ""
@State private var awayTeamPrediction = ""
@State private var isPredicted = false

var gameFixture: GameFixture
var onSubmitPredict: (Prediction) -> Void

var body: some View {
let isNotPredicted = !gameFixture.isPredicted
let isNotPredicted = !isPredicted //TODO remove after testing

VStack(spacing: 16) {
LinearGradientText(isNotPredicted: isNotPredicted)

HStack {
ScoreTextField(value: $homeTeamPrediction)
ScoreTextField(value: $homeTeamPrediction, isPredicted: $isPredicted)
Spacer().frame(width: 16)
ScoreTextField(value: $awayTeamPrediction)
ScoreTextField(value: $awayTeamPrediction, isPredicted: $isPredicted)
}

if isNotPredicted {
SubmitButton(onSubmit: {
onSubmitPredict(Prediction(id: nil,fixtureId: gameFixture.id, homeScores: homeTeamPrediction, awayScores: awayTeamPrediction))
isPredicted = true
onSubmitPredict(
Prediction(
id: nil,
fixtureId: gameFixture.id,
homeScores: homeTeamPrediction,
awayScores: awayTeamPrediction
)
)
})
} else {
Text(gameFixture.getPredictionMessage())
Expand Down Expand Up @@ -96,6 +105,7 @@ struct LinearGradientText: View {

struct ScoreTextField: View {
@Binding var value: String
@Binding var isPredicted: Bool

var body: some View {
TextField("", text: $value)
Expand All @@ -108,6 +118,7 @@ struct ScoreTextField: View {
.clipShape(RoundedRectangle(cornerRadius: 10))
.frame(width: 120, height: 60)
.padding(.horizontal, 16)
.disabled(isPredicted)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ struct FixtureListView: View {
}
}
List(viewModel.gameWeekFixtures[viewModel.gameWeek] ?? []) { fixture in
NavigationLink(destination: FixtureDetailView(fixture: fixture, onSubmitPredict: { prediction in viewModel.onSubmitPredict(prediction: prediction) })) {
NavigationLink(
destination: FixtureDetailView(
fixture: fixture,
onSubmitPredict: { prediction in viewModel.onSubmitPredict(prediction: prediction) }
)) {
FixtureView(fixture: fixture)
}
}
Expand Down

0 comments on commit 413387c

Please sign in to comment.