mute: fix issue with not being able to change mute duration
This patch fixes an issue where the user can’t change the mute duration when adding a new mute item. The problem was that `expiration` was nil for indefinite which isn’t really allowed for a Picker. I fixed this by adding an indefinite case to DamusDuration. Closes: https://github.com/damus-io/damus/issues/1907 Lighting-address: fishcharlie@strike.me Signed-off-by: Charlie Fish <contact@charlie.fish> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
a4f0eeadec
commit
a6b508c25a
@@ -8,12 +8,15 @@
|
||||
import Foundation
|
||||
|
||||
enum DamusDuration: CaseIterable {
|
||||
case indefinite
|
||||
case day
|
||||
case week
|
||||
case month
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .indefinite:
|
||||
return NSLocalizedString("Indefinite", comment: "Mute a given item indefinitly (until user unmutes it). As opposed to muting the item for a given period of time.")
|
||||
case .day:
|
||||
return NSLocalizedString("24 hours", comment: "A duration of 24 hours/1 day to be shown to the user. Most likely in the context of how long they want to mute a piece of content for.")
|
||||
case .week:
|
||||
@@ -27,6 +30,8 @@ enum DamusDuration: CaseIterable {
|
||||
let current_date = Date()
|
||||
|
||||
switch self {
|
||||
case .indefinite:
|
||||
return nil
|
||||
case .day:
|
||||
return Calendar.current.date(byAdding: .day, value: 1, to: current_date)
|
||||
case .week:
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
struct AddMuteItemView: View {
|
||||
let state: DamusState
|
||||
@State var new_text: String = ""
|
||||
@State var expiration: DamusDuration?
|
||||
@State var expiration: DamusDuration = .indefinite
|
||||
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@@ -23,7 +23,6 @@ struct AddMuteItemView: View {
|
||||
.padding(.bottom)
|
||||
|
||||
Picker(selection: $expiration) {
|
||||
Text("Indefinite", comment: "Mute a given item indefinitly (until user unmutes it). As opposed to muting the item for a given period of time.")
|
||||
ForEach(DamusDuration.allCases, id: \.self) { duration in
|
||||
Text(duration.title).tag(duration)
|
||||
}
|
||||
@@ -55,7 +54,7 @@ struct AddMuteItemView: View {
|
||||
.cornerRadius(10)
|
||||
|
||||
Button(action: {
|
||||
let expiration_date: Date? = self.expiration?.date_from_now
|
||||
let expiration_date: Date? = self.expiration.date_from_now
|
||||
let mute_item: MuteItem? = {
|
||||
if new_text.starts(with: "npub") {
|
||||
if let pubkey: Pubkey = bech32_pubkey_decode(new_text) {
|
||||
|
||||
Reference in New Issue
Block a user