|
|
|
@ -9,17 +9,20 @@ import SwiftUI |
|
|
|
import LeStorage |
|
|
|
import LeStorage |
|
|
|
|
|
|
|
|
|
|
|
struct ClubDetailView: View { |
|
|
|
struct ClubDetailView: View { |
|
|
|
@Bindable var club: Club |
|
|
|
|
|
|
|
var displayContext: DisplayContext |
|
|
|
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
|
|
|
@Environment(\.dismiss) var dismiss |
|
|
|
@FocusState var focusedField: Club.CodingKeys? |
|
|
|
@FocusState var focusedField: Club.CodingKeys? |
|
|
|
@State private var acronymMode: Club.AcronymMode = .automatic |
|
|
|
@State private var acronymMode: Club.AcronymMode = .automatic |
|
|
|
@State private var city: String |
|
|
|
@State private var city: String |
|
|
|
@State private var zipCode: String |
|
|
|
@State private var zipCode: String |
|
|
|
|
|
|
|
@Bindable var club: Club |
|
|
|
|
|
|
|
var displayContext: DisplayContext |
|
|
|
|
|
|
|
var selection: ((Club) -> ())? = nil |
|
|
|
|
|
|
|
|
|
|
|
init(club: Club, displayContext: DisplayContext) { |
|
|
|
init(club: Club, displayContext: DisplayContext, selection: ((Club) -> ())? = nil) { |
|
|
|
_club = Bindable(club) |
|
|
|
_club = Bindable(club) |
|
|
|
self.displayContext = displayContext |
|
|
|
self.displayContext = displayContext |
|
|
|
|
|
|
|
self.selection = selection |
|
|
|
_acronymMode = State(wrappedValue: club.shortNameMode()) |
|
|
|
_acronymMode = State(wrappedValue: club.shortNameMode()) |
|
|
|
_city = State(wrappedValue: club.city ?? "") |
|
|
|
_city = State(wrappedValue: club.city ?? "") |
|
|
|
_zipCode = State(wrappedValue: club.zipCode ?? "") |
|
|
|
_zipCode = State(wrappedValue: club.zipCode ?? "") |
|
|
|
@ -27,23 +30,10 @@ struct ClubDetailView: View { |
|
|
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
var body: some View { |
|
|
|
Form { |
|
|
|
Form { |
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
Section { |
|
|
|
NavigationLink { |
|
|
|
|
|
|
|
ClubSearchView(displayContext: .edition, club: club) |
|
|
|
|
|
|
|
} label: { |
|
|
|
|
|
|
|
Label("Chercher dans la base fédérale", systemImage: "magnifyingglass") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
Text("Vous pouvez chercher un club dans la base fédérale et importer les informations directement.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
LabeledContent { |
|
|
|
|
|
|
|
TextField("Nom du club", text: $club.name) |
|
|
|
TextField("Nom du club", text: $club.name) |
|
|
|
.autocorrectionDisabled() |
|
|
|
.autocorrectionDisabled() |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.focused($focusedField, equals: ._name) |
|
|
|
.focused($focusedField, equals: ._name) |
|
|
|
.submitLabel( displayContext == .addition ? .next : .done) |
|
|
|
.submitLabel( displayContext == .addition ? .next : .done) |
|
|
|
@ -56,12 +46,6 @@ struct ClubDetailView: View { |
|
|
|
focusedField = ._acronym |
|
|
|
focusedField = ._acronym |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} label: { |
|
|
|
|
|
|
|
Text("Nom du club") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.onTapGesture { |
|
|
|
|
|
|
|
focusedField = ._name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LabeledContent { |
|
|
|
LabeledContent { |
|
|
|
if acronymMode == .automatic { |
|
|
|
if acronymMode == .automatic { |
|
|
|
Text(club.acronym) |
|
|
|
Text(club.acronym) |
|
|
|
@ -106,8 +90,16 @@ struct ClubDetailView: View { |
|
|
|
club.acronym = "" |
|
|
|
club.acronym = "" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
if displayContext == .lockedForEditing { |
|
|
|
|
|
|
|
Text("Édition impossible, vous n'êtes pas le créateur de ce club.").foregroundStyle(.logoRed) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Text("Vous pouvez personaliser le nom court ou laisser celui généré par défaut.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if club.code == nil { |
|
|
|
if club.code == nil { |
|
|
|
|
|
|
|
Section { |
|
|
|
LabeledContent { |
|
|
|
LabeledContent { |
|
|
|
TextField("Ville", text: $city) |
|
|
|
TextField("Ville", text: $city) |
|
|
|
.autocorrectionDisabled() |
|
|
|
.autocorrectionDisabled() |
|
|
|
@ -146,16 +138,13 @@ struct ClubDetailView: View { |
|
|
|
.onTapGesture { |
|
|
|
.onTapGesture { |
|
|
|
focusedField = ._zipCode |
|
|
|
focusedField = ._zipCode |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} footer: { |
|
|
|
} footer: { |
|
|
|
if displayContext == .lockedForEditing { |
|
|
|
if displayContext == .lockedForEditing { |
|
|
|
Text("Édition impossible, vous n'êtes pas le créateur de ce club.").foregroundStyle(.logoRed) |
|
|
|
Text("Édition impossible, vous n'êtes pas le créateur de ce club.").foregroundStyle(.logoRed) |
|
|
|
} else { |
|
|
|
|
|
|
|
Text("Vous pouvez personaliser le nom court ou laisser celui généré par défaut.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.disabled(displayContext == .lockedForEditing) |
|
|
|
.disabled(displayContext == .lockedForEditing) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let federalLink = club.federalLink() { |
|
|
|
if let federalLink = club.federalLink() { |
|
|
|
@ -172,6 +161,31 @@ struct ClubDetailView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if displayContext == .addition { |
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
} header: { |
|
|
|
|
|
|
|
HStack { |
|
|
|
|
|
|
|
VStack { |
|
|
|
|
|
|
|
Divider() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Text("ou") |
|
|
|
|
|
|
|
VStack { |
|
|
|
|
|
|
|
Divider() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
NavigationLink { |
|
|
|
|
|
|
|
ClubSearchView(displayContext: .edition, club: club) |
|
|
|
|
|
|
|
} label: { |
|
|
|
|
|
|
|
Label("Chercher dans la base fédérale", systemImage: "magnifyingglass") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
Text("Vous pouvez chercher un club dans la base fédérale et importer les informations directement.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if displayContext == .edition { |
|
|
|
if displayContext == .edition { |
|
|
|
Section { |
|
|
|
Section { |
|
|
|
RowButtonView("Supprimer ce club", role: .destructive) { |
|
|
|
RowButtonView("Supprimer ce club", role: .destructive) { |
|
|
|
|