six-card-golf/Shared/UI/SettingsView.swift
Lukas Schaefer e609ea881f
Allow deleting account
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
2026-09-01 20:35:00 -04:00

100 lines
3.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
struct SettingsView: View {
@ObservedObject var controller: GameController
@State private var showDeleteAccountAlert = false
@State private var deleteConfirmationUsername = ""
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
HStack {
Text("New Game")
.font(.system(.largeTitle, design: .rounded).weight(.bold))
Spacer()
Button("Log out") { controller.logout() }
.font(.footnote)
}
Text("Signed in as \(controller.username)")
.font(.subheadline)
.foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 8) {
Text("Eliminate at").font(.headline)
Stepper(value: $controller.draftPointsToEnd, in: 10...500, step: 10) {
Text("\(controller.draftPointsToEnd) points")
.font(.title3.monospacedDigit())
}
}
VStack(alignment: .leading, spacing: 8) {
Text("Players to start").font(.headline)
Stepper(value: $controller.draftPlayersToStart, in: 1...12) {
Text("\(controller.draftPlayersToStart)")
.font(.title3.monospacedDigit())
}
}
VStack(alignment: .leading, spacing: 8) {
Text("Bots").font(.headline)
Stepper(value: $controller.draftBots, in: 0...10) {
Text("\(controller.draftBots)")
.font(.title3.monospacedDigit())
}
}
VStack(alignment: .leading, spacing: 8) {
Text("Decks").font(.headline)
Stepper(value: $controller.draftDecks, in: 1...20) {
Text("\(controller.draftDecks)")
.font(.title3.monospacedDigit())
}
Text("Last flip scores ×2.")
.font(.footnote)
.foregroundStyle(.secondary)
}
if let error = controller.errorMessage {
Text(error)
.font(.footnote)
.foregroundStyle(.red)
}
Button { controller.startGame() } label: {
Text(controller.isBusy ? "Creating…" : "Start Game")
.font(.headline)
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
}
.buttonStyle(.borderedProminent)
.disabled(controller.isBusy)
Button {
deleteConfirmationUsername = ""
showDeleteAccountAlert = true
} label: {
Text("Delete Account")
.font(.headline)
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
}
.buttonStyle(.bordered)
.tint(.red)
.disabled(controller.isBusy)
}
.padding(20)
}
.alert("Delete Account", isPresented: $showDeleteAccountAlert) {
TextField("Username", text: $deleteConfirmationUsername)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
Button("Delete", role: .destructive) {
controller.deleteAccount(confirmation: deleteConfirmationUsername)
}
Button("Cancel", role: .cancel) {}
} message: {
Text("This permanently deletes your account. Type \"\(controller.username)\" to confirm.")
}
}
}