@@ -4,6 +4,8 @@ import SwiftUI
44struct AlbumHistoryView : View {
55 @ Environment ( AlbumHistoryViewModel . self ) private var vm
66
7+ @ Environment ( \. navigation ) private var navigation
8+
79 @ Namespace private var namespace
810
911 @ State private var path = NavigationPath ( )
@@ -57,7 +59,11 @@ struct AlbumHistoryView: View {
5759 ThemeContentUnavailableView . empty (
5860 . History . stateEmptyTitle ,
5961 description : . History . stateEmptyDesc ,
60- )
62+ ) {
63+ if let navigation {
64+ EmptyStateButton ( navigation : navigation )
65+ }
66+ }
6167 } else {
6268 ThemeContentUnavailableView . search ( text : vm . searchText )
6369 }
@@ -81,7 +87,7 @@ struct AlbumHistoryView: View {
8187 )
8288 )
8389 . toolbar {
84- AlbumHistoryToolbar ( vm : vm ) {
90+ albumHistoryToolbar {
8591 let count = vm . selectedIds . count
8692 alert = AlertDestination (
8793 title : . alertsHistoryDeleteTitle ( count : count ) ,
@@ -108,41 +114,39 @@ struct AlbumHistoryView: View {
108114 }
109115 }
110116 }
111- }
112117
113- private struct AlbumSearchSuggestions : View {
114- @ Query ( sort : \Album . title ) private var albums : [ Album ]
115-
116- let maxResults : Int
117-
118- init ( maxResults : Int = 3 ) {
119- self . maxResults = maxResults
120- }
121-
122- var titles : [ String ] {
123- Array ( albums . map ( \. title ) . prefix ( min ( albums . count , maxResults ) ) )
124- }
125-
126- var body : some View {
127- ForEach ( titles , id : \. self ) { title in
128- Text ( title )
129- . searchCompletion ( title )
130- }
131- }
132- }
133-
134- private struct AlbumHistoryToolbar : ToolbarContent {
135- @ Bindable var vm : AlbumHistoryViewModel
136-
137- let deleteAction : ( ) -> Void
138-
139- var body : some ToolbarContent {
118+ @ ToolbarContentBuilder
119+ private func albumHistoryToolbar (
120+ deleteAction : @escaping ( ) -> Void
121+ ) -> some ToolbarContent {
140122 // ToolbarTitle(.History.title)
141123
142124 if vm . isSelecting {
143- ToolbarItemGroup {
125+ if vm . allSelected {
126+ ToolbarItem ( placement : . topBarLeading ) {
127+ Button ( . toolsSelectAllUndo ) {
128+ withAnimation {
129+ vm . deselectAll ( vm . filteredIds )
130+ }
131+ }
132+ // TODO: logic for disabling button.
133+ }
134+ } else {
135+ ToolbarItem ( placement : . topBarLeading ) {
136+ Button ( . toolsSelectAll ) {
137+ withAnimation {
138+ vm . selectAll ( vm . filteredIds )
139+ }
140+ }
141+ // TODO: logic for disabling button.
142+ }
143+ }
144+
145+ ToolbarItemGroup ( placement : . topBarTrailing ) {
144146 Button ( role : . cancel ) {
145- vm . clearSelection ( )
147+ withAnimation {
148+ vm . clearSelection ( )
149+ }
146150 }
147151 . accessibilityIdentifier ( " history-cancel-selection " )
148152
@@ -153,38 +157,76 @@ private struct AlbumHistoryToolbar: ToolbarContent {
153157 . accessibilityIdentifier ( " history-delete-selection " )
154158 }
155159 } else {
156- ToolbarItem {
160+ ToolbarItem ( placement : . topBarTrailing ) {
157161 Button ( . toolsSelect ) {
158- vm . isSelecting = true
162+ withAnimation {
163+ vm . isSelecting = true
164+ }
159165 }
160166 . disabled ( vm . filteredCount == 0 )
161167 }
162168
163- ToolbarSpacer ( . fixed )
169+ ToolbarSpacer ( . fixed , placement : . topBarTrailing )
170+
171+ ToolbarItem ( placement : . topBarTrailing ) {
172+ @Bindable var vm = vm
164173
165- ToolbarItem {
166174 Menu {
167- Picker ( " Criteria " , selection : $vm . sort . criterion ) {
175+ Picker ( . toolsSortCriteria , selection : $vm . sort . criterion ) {
168176 ForEach ( SortCriterion . allCases ) { criterion in
169177 Text ( criterion . resource )
170178 . tag ( criterion )
171179 }
172180 }
173181
174- Picker ( " Order " , selection : vm . currentOrder ) {
182+ Picker ( . toolsSortDirection , selection : vm . currentOrder ) {
175183 ForEach ( vm . sort . criterion . orders ) { order in
176184 Text ( order . resource )
177185 . tag ( order )
178186 }
179187 }
180188 } label : {
181- Image ( systemName : " arrow.up.arrow.down " )
189+ Label ( . toolsSort , systemImage : " arrow.up.arrow.down " )
182190 }
183191 }
184192 }
185193 }
186194}
187195
196+ private struct EmptyStateButton : View {
197+ var navigation : AppNavigation
198+
199+ var body : some View {
200+ Button ( . History . stateEmptyButtonLabel , systemImage : " magnifyingglass " ) {
201+ navigation . screen = . search
202+ }
203+ . labelStyle ( . badge ( appearance : . highlighted ) )
204+ . controlSize ( . large )
205+ . imageScale ( . small )
206+ }
207+ }
208+
209+ private struct AlbumSearchSuggestions : View {
210+ @ Query ( sort : \Album . title ) private var albums : [ Album ]
211+
212+ let maxResults : Int
213+
214+ init ( maxResults : Int = 3 ) {
215+ self . maxResults = maxResults
216+ }
217+
218+ var titles : [ String ] {
219+ Array ( albums . map ( \. title ) . prefix ( min ( albums . count , maxResults ) ) )
220+ }
221+
222+ var body : some View {
223+ ForEach ( titles , id : \. self ) { title in
224+ Text ( title )
225+ . searchCompletion ( title )
226+ }
227+ }
228+ }
229+
188230private struct AlbumHistoryFilterBar : View {
189231 @ Environment ( \. locale ) private var locale
190232
0 commit comments