damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit f5cdd4a15973afdf849bbcd21917187ce9a9e9f2
parent c4f41220e5875fbe72454319200eae98bc7c0a75
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 23 Apr 2023 10:31:51 -0700

You can now change the default zap type

Changelog-Added: You can now change the default zap type

Diffstat:
Mdamus/Components/ZapButton.swift | 2+-
Mdamus/Models/UserSettingsStore.swift | 3+++
Mdamus/Views/Zaps/CustomizeZapView.swift | 10+++++++---
Mdamus/Views/Zaps/ZapTypePicker.swift | 37+++++++++++++++++++++++++++++++++----
4 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/damus/Components/ZapButton.swift b/damus/Components/ZapButton.swift @@ -86,7 +86,7 @@ struct ZapButton: View { return } - send_zap(damus_state: damus_state, event: event, lnurl: lnurl, is_custom: false, comment: nil, amount_sats: nil, zap_type: ZapType.pub) + send_zap(damus_state: damus_state, event: event, lnurl: lnurl, is_custom: false, comment: nil, amount_sats: nil, zap_type: damus_state.settings.default_zap_type) self.zapping = true }) .accessibilityLabel(NSLocalizedString("Zap", comment: "Accessibility label for zap button")) diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift @@ -99,6 +99,9 @@ class UserSettingsStore: ObservableObject { @Setting(key: "mention_notification", default_value: true) var mention_notification: Bool + + @StringSetting(key: "zap_type", default_value: ZapType.pub) + var default_zap_type: ZapType @Setting(key: "repost_notification", default_value: true) var repost_notification: Bool diff --git a/damus/Views/Zaps/CustomizeZapView.swift b/damus/Views/Zaps/CustomizeZapView.swift @@ -73,7 +73,7 @@ struct CustomizeZapView: View { self._error = State(initialValue: nil) self._invoice = State(initialValue: "") self._showing_wallet_selector = State(initialValue: false) - self._zap_type = State(initialValue: .pub) + self._zap_type = State(initialValue: state.settings.default_zap_type) self._custom_amount = State(initialValue: String(state.settings.default_zap_amount)) self._custom_amount_sats = State(initialValue: nil) self._zapping = State(initialValue: false) @@ -294,15 +294,19 @@ struct CustomizeZapView: View { } .sheet(isPresented: $show_zap_types) { if #available(iOS 16.0, *) { - ZapTypePicker(zap_type: $zap_type, profiles: state.profiles, pubkey: event.pubkey) + ZapPicker .presentationDetents([.medium]) .presentationDragIndicator(.visible) } else { - ZapTypePicker(zap_type: $zap_type, profiles: state.profiles, pubkey: event.pubkey) + ZapPicker } } } + var ZapPicker: some View { + ZapTypePicker(zap_type: $zap_type, settings: state.settings, profiles: state.profiles, pubkey: event.pubkey) + } + var MainContent: some View { CustomZap } diff --git a/damus/Views/Zaps/ZapTypePicker.swift b/damus/Views/Zaps/ZapTypePicker.swift @@ -7,15 +7,29 @@ import SwiftUI -enum ZapType { +enum ZapType: String, StringCodable { case pub case anon case priv case non_zap + + init?(from string: String) { + guard let v = ZapType(rawValue: string) else { + return nil + } + + self = v + } + + func to_string() -> String { + return self.rawValue + } + } struct ZapTypePicker: View { @Binding var zap_type: ZapType + @ObservedObject var settings: UserSettingsStore let profiles: Profiles let pubkey: String @@ -29,10 +43,24 @@ struct ZapTypePicker: View { colorScheme == .light ? DamusColors.black : DamusColors.white } + var is_default: Bool { + zap_type == settings.default_zap_type + } + var body: some View { VStack(spacing: 20) { - Text("Zap type") - .font(.system(size: 18, weight: .heavy)) + HStack { + Text("Zap type") + .font(.system(size: 25, weight: .heavy)) + Spacer() + if !is_default { + Button(action: { + settings.default_zap_type = zap_type + }) { + Label("Make Default", image: "checkmark.circle.fill") + } + } + } ZapTypeSelection(text: "Public", comment: "Picker option to indicate that a zap should be sent publicly and identify the user as who sent it.", img: "person.2.circle.fill", action: {zap_type = ZapType.pub}, type: ZapType.pub) ZapTypeSelection(text: "Private", comment: "Picker option to indicate that a zap should be sent privately and not identify the user to the public.", img: "lock.circle.fill", action: {zap_type = ZapType.priv}, type: ZapType.priv) ZapTypeSelection(text: "Anonymous", comment: "Picker option to indicate that a zap should be sent anonymously and not identify the user as who sent it.", img: "person.crop.circle.fill.badge.questionmark", action: {zap_type = ZapType.anon}, type: ZapType.anon) @@ -70,9 +98,10 @@ struct ZapTypePicker: View { struct ZapTypePicker_Previews: PreviewProvider { @State static var zap_type: ZapType = .pub + @State static var default_type: ZapType = .pub static var previews: some View { let ds = test_damus_state() - ZapTypePicker(zap_type: $zap_type, profiles: ds.profiles, pubkey: "bob") + ZapTypePicker(zap_type: $zap_type, settings: ds.settings, profiles: ds.profiles, pubkey: "bob") } }