Add a Reset button to clear selected currencies, with confirmation
New "Reset" button in the currency picker's top bar (next to Done), shown only when more than the pinned default currency is selected. Tapping it asks for confirmation before removing every other selected currency, via PriceViewModel.onSelectedCurrenciesReset() — same recompute/persist pattern as onFiatCurrencyToggled. Compose uses an AlertDialog; iOS/macOS uses .alert with a destructive Reset action, matching the destructive-role toolbar button that triggers it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -238,7 +238,9 @@ struct ContentView: View {
|
||||
pricedCurrencyCodes: state.pricedCurrencyCodes,
|
||||
sourceName: state.sourceName,
|
||||
localeCurrencyCode: state.localeCurrencyCode,
|
||||
onToggle: { viewModel.onFiatCurrencyToggled($0) }
|
||||
selectedCount: state.selectedCurrencyCodes.count,
|
||||
onToggle: { viewModel.onFiatCurrencyToggled($0) },
|
||||
onReset: { viewModel.onSelectedCurrenciesReset() }
|
||||
)
|
||||
}
|
||||
.environment(\.openURL, OpenURLAction { url in
|
||||
|
||||
@@ -39,6 +39,10 @@ final class ConverterViewModel: ObservableObject {
|
||||
bridge.onFiatCurrenciesReordered(newOrder: newOrder)
|
||||
}
|
||||
|
||||
func onSelectedCurrenciesReset() {
|
||||
bridge.onSelectedCurrenciesReset()
|
||||
}
|
||||
|
||||
func onSourceSelected(_ name: String) {
|
||||
bridge.onSourceSelected(name: name)
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@ struct CurrencyPickerSheet: View {
|
||||
let pricedCurrencyCodes: [String]
|
||||
let sourceName: String
|
||||
let localeCurrencyCode: String?
|
||||
let selectedCount: Int
|
||||
let onToggle: (String) -> Void
|
||||
let onReset: () -> Void
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var searchQuery = ""
|
||||
@State private var showResetConfirmation = false
|
||||
|
||||
private func matches(_ info: CurrencyInfo) -> Bool {
|
||||
SystemCurrenciesKt.matchesCurrencySearch(info: info, query: searchQuery)
|
||||
@@ -60,6 +63,16 @@ struct CurrencyPickerSheet: View {
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
.toolbar {
|
||||
if selectedCount > 1 {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(
|
||||
IosLocalizationKt.localizedString(resource: MR.strings.shared.reset_selected_currencies_button),
|
||||
role: .destructive
|
||||
) {
|
||||
showResetConfirmation = true
|
||||
}
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(IosLocalizationKt.localizedString(resource: MR.strings.shared.done)) { dismiss() }
|
||||
}
|
||||
@@ -74,6 +87,23 @@ struct CurrencyPickerSheet: View {
|
||||
text: $searchQuery,
|
||||
prompt: IosLocalizationKt.localizedString(resource: MR.strings.shared.search_currencies_placeholder)
|
||||
)
|
||||
.alert(
|
||||
IosLocalizationKt.localizedString(resource: MR.strings.shared.reset_selected_currencies_confirmation_title),
|
||||
isPresented: $showResetConfirmation
|
||||
) {
|
||||
Button(
|
||||
IosLocalizationKt.localizedString(resource: MR.strings.shared.reset_selected_currencies_button),
|
||||
role: .destructive
|
||||
) {
|
||||
onReset()
|
||||
}
|
||||
Button(IosLocalizationKt.localizedString(resource: MR.strings.shared.cancel), role: .cancel) {}
|
||||
} message: {
|
||||
Text(IosLocalizationKt.localizedFormattedString(
|
||||
resource: MR.strings.shared.reset_selected_currencies_confirmation_message,
|
||||
args: [currentCurrency.code]
|
||||
))
|
||||
}
|
||||
#if os(macOS)
|
||||
// macOS sizes a .sheet() to its content's ideal size rather than the parent window's
|
||||
// size (unlike iOS, which presents modally full-size); without an explicit frame here,
|
||||
|
||||
Reference in New Issue
Block a user