@@ -20,6 +20,10 @@ struct AlbumListView: View {
20
20
21
21
@State private var selectedAlbum : DFAlbum ? = nil
22
22
@State private var navigationPath = NavigationPath ( )
23
+ @State private var isDeleting = false
24
+ @State private var showDeleteConfirmation = false
25
+ @State private var albumToDelete : DFAlbum ? = nil
26
+ @State private var showingAlbumCreator : Bool = false
23
27
24
28
var body : some View {
25
29
ZStack {
@@ -66,6 +70,13 @@ struct AlbumListView: View {
66
70
} ) {
67
71
Label ( " Copy Link " , systemImage: " link " )
68
72
}
73
+
74
+ Button ( role: . destructive, action: {
75
+ albumToDelete = album
76
+ showDeleteConfirmation = true
77
+ } ) {
78
+ Label ( " Delete Album " , systemImage: " trash " )
79
+ }
69
80
}
70
81
}
71
82
. id ( album. id)
@@ -86,7 +97,8 @@ struct AlbumListView: View {
86
97
}
87
98
}
88
99
. navigationDestination ( for: DFAlbum . self) { album in
89
- FileListView ( server: server, albumID: album. id, navigationPath: $navigationPath)
100
+ FileListView ( server: server, albumID: album. id, navigationPath: $navigationPath, albumName: album. name)
101
+ . navigationTitle ( " test " )
90
102
}
91
103
. listStyle ( . plain)
92
104
. refreshable {
@@ -98,24 +110,42 @@ struct AlbumListView: View {
98
110
. navigationTitle ( server. wrappedValue != nil ? " Albums ( \( URL ( string: server. wrappedValue!. url) ? . host ?? " unknown " ) ) " : " Albums " )
99
111
. toolbar {
100
112
ToolbarItem ( placement: . navigationBarTrailing) {
101
- Menu {
102
- Button ( action: {
103
- // Create album action
104
- } ) {
105
- Label ( " Create Album " , systemImage: " plus " )
106
- }
107
- } label: {
108
- Image ( systemName: " ellipsis.circle " )
113
+ Button ( action: {
114
+ showingAlbumCreator = true
115
+ } ) {
116
+ Label ( " Create Album " , systemImage: " plus " )
109
117
}
110
118
}
111
119
}
112
120
}
121
+ . sheet ( isPresented: $showingAlbumCreator) {
122
+ if let serverInstance = server. wrappedValue {
123
+ CreateAlbumView ( server: serverInstance)
124
+ . onDisappear {
125
+ showingAlbumCreator = false
126
+ }
127
+ }
128
+ }
113
129
. onChange ( of: selectedAlbum) { oldValue, newValue in
114
130
if let album = newValue {
115
131
navigationPath. append ( album)
116
132
selectedAlbum = nil // Reset after navigation
117
133
}
118
134
}
135
+ . alert ( " Delete Album " , isPresented: $showDeleteConfirmation) {
136
+ Button ( " Cancel " , role: . cancel) {
137
+ albumToDelete = nil
138
+ }
139
+ Button ( " Delete " , role: . destructive) {
140
+ if let album = albumToDelete {
141
+ Task {
142
+ await deleteAlbum ( album)
143
+ }
144
+ }
145
+ }
146
+ } message: {
147
+ Text ( " Are you sure you want to delete this album? This action cannot be undone. " )
148
+ }
119
149
}
120
150
}
121
151
. onAppear {
@@ -181,6 +211,26 @@ struct AlbumListView: View {
181
211
isLoading = false
182
212
}
183
213
}
214
+
215
+ @MainActor
216
+ private func deleteAlbum( _ album: DFAlbum ) async {
217
+ guard let serverInstance = server. wrappedValue else { return }
218
+
219
+ isDeleting = true
220
+ let api = DFAPI ( url: URL ( string: serverInstance. url) !, token: serverInstance. token)
221
+
222
+ if await api. deleteAlbum ( albumId: album. id) {
223
+ // Remove just the specific album from the list
224
+ if let index = albums. firstIndex ( where: { $0. id == album. id } ) {
225
+ albums. remove ( at: index)
226
+ }
227
+ } else {
228
+ ToastManager . shared. showToast ( message: " Failed to delete album " )
229
+ }
230
+
231
+ isDeleting = false
232
+ albumToDelete = nil
233
+ }
184
234
}
185
235
186
236
struct AlbumRowView : View {
0 commit comments