You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.8 KiB
111 lines
3.8 KiB
//
|
|
// ClubsView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 20/03/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import TipKit
|
|
import LeStorage
|
|
|
|
struct ClubsView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var presentClubCreationView: Bool = false
|
|
@State private var presentClubSearchView: Bool = false
|
|
let tip = SlideToDeleteTip()
|
|
var selection: ((Club) -> ())? = nil
|
|
|
|
var body: some View {
|
|
List {
|
|
//
|
|
// if dataStore.clubs.isEmpty == false && selection == nil {
|
|
// Section {
|
|
// TipView(tip)
|
|
// .tipStyle(tint: nil)
|
|
// }
|
|
// }
|
|
let clubs : [Club] = (dataStore.user?.clubsObjects(includeCreated: true)) ?? []
|
|
ForEach(clubs) { club in
|
|
if let selection {
|
|
Button {
|
|
selection(club)
|
|
dismiss()
|
|
} label: {
|
|
ClubRowView(club: club)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.contentShape(Rectangle())
|
|
.buttonStyle(.plain)
|
|
} else {
|
|
NavigationLink {
|
|
ClubDetailView(club: club, displayContext: club.hasBeenCreated(by: dataStore.user?.id) ? .edition : .lockedForEditing)
|
|
} label: {
|
|
ClubRowView(club: club)
|
|
}
|
|
// .swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
|
// Button(role: .destructive) {
|
|
// try? dataStore.clubs.delete(instance: club)
|
|
// } label: {
|
|
// LabelDelete()
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
.overlay {
|
|
if dataStore.user == nil || dataStore.user?.hasClubs() == true {
|
|
ContentUnavailableView {
|
|
Label("Aucun club", systemImage: "house.and.flag.fill")
|
|
} description: {
|
|
Text("Texte décrivant l'utilité d'un club et les features que cela apporte")
|
|
} actions: {
|
|
RowButtonView("Créer un nouveau club", systemImage: "plus.circle.fill") {
|
|
presentClubCreationView = true
|
|
}
|
|
RowButtonView("Chercher un club", systemImage: "magnifyingglass.circle.fill") {
|
|
presentClubSearchView = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle(selection == nil ? "Mes clubs" : "Choisir un club")
|
|
.sheet(isPresented: $presentClubCreationView) {
|
|
CreateClubView()
|
|
.tint(.master)
|
|
}
|
|
.sheet(isPresented: $presentClubSearchView) {
|
|
ClubImportView()
|
|
.tint(.master)
|
|
}
|
|
.toolbar {
|
|
ToolbarItemGroup(placement: .topBarTrailing) {
|
|
Button {
|
|
presentClubSearchView = true
|
|
} label: {
|
|
Image(systemName: "magnifyingglass.circle.fill")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(minHeight: 28)
|
|
}
|
|
|
|
Button {
|
|
presentClubCreationView = true
|
|
} label: {
|
|
Image(systemName: "plus.circle.fill")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(minHeight: 28)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationStack {
|
|
ClubsView()
|
|
.environmentObject(DataStore.shared)
|
|
}
|
|
}
|
|
|