fix issues with Area Inset and Tool Bar

This commit is contained in:
Giovanni committed 2026-09-03 19:12:56 +02:00
1 parent 2e4dfa48cd
commit 85259446b1
3 files changed
+23 -12

No files matched your search

@@ -9,7 +9,7 @@ import SwiftUI
import SwiftData import SwiftData
struct WorldListAreaInsetModifier : ViewModifier { struct WorldListAreaInsetModifier : ViewModifier {
let isSelecting : Bool @Binding var isSelecting : Bool
@Binding var selectedWorlds : Set<World.ID> @Binding var selectedWorlds : Set<World.ID>
let worlds : [World] let worlds : [World]
@@ -36,9 +36,16 @@ struct WorldListAreaInsetModifier : ViewModifier {
Spacer() Spacer()
Button(role: .destructive){ Button(role: .destructive){
let shouldExitSelection = worldsToAction.count == worlds.count
for world in worldsToAction { for world in worldsToAction {
context.delete(world) context.delete(world)
} }
selectedWorlds.removeAll()
if shouldExitSelection {
isSelecting = false
}
}label : { }label : {
Label("Supprimer", systemImage: "trash") Label("Supprimer", systemImage: "trash")
} }
@@ -10,19 +10,22 @@ import SwiftUI
struct WorldListToolbarModifier : ViewModifier { struct WorldListToolbarModifier : ViewModifier {
@Binding var isSelecting : Bool @Binding var isSelecting : Bool
@Binding var selectedWorlds : Set<World.ID> @Binding var selectedWorlds : Set<World.ID>
let worldsIsEmpty : Bool
func body(content: Content) -> some View { func body(content: Content) -> some View {
content content
.toolbar{ .toolbar{
ToolbarItem(placement: .topBarLeading) { if !worldsIsEmpty {
if isSelecting { ToolbarItem(placement: .topBarLeading) {
Button("Annuler") { if isSelecting {
selectedWorlds.removeAll() Button("Annuler") {
isSelecting = false selectedWorlds.removeAll()
} isSelecting = false
} else { }
Button("Sélectionner") { } else {
isSelecting = true Button("Sélectionner") {
isSelecting = true
}
} }
} }
} }
@@ -69,7 +69,7 @@ struct WorldListView: View {
.frame(maxHeight: .infinity, alignment: .topLeading) .frame(maxHeight: .infinity, alignment: .topLeading)
.modifier( .modifier(
WorldListAreaInsetModifier( WorldListAreaInsetModifier(
isSelecting: isSelecting, isSelecting: $isSelecting,
selectedWorlds: $selectedWorlds, selectedWorlds: $selectedWorlds,
worlds: worlds worlds: worlds
) )
@@ -78,7 +78,8 @@ struct WorldListView: View {
.modifier( .modifier(
WorldListToolbarModifier( WorldListToolbarModifier(
isSelecting: $isSelecting, isSelecting: $isSelecting,
selectedWorlds: $selectedWorlds selectedWorlds: $selectedWorlds,
worldsIsEmpty: worlds.isEmpty
) )
) )
} }