Files
damus/damus/Views/Muting/AddMuteItemView.swift
Charlie Fish 9f332a148f mute: add new UI views for new mute list
- Adding MuteDurationMenu & AddMuteItemView
    - In a future patch I will update AddMuteItemView to actually update and relay the new mute list

Related: https://github.com/damus-io/damus/issues/1718
Related: https://github.com/damus-io/damus/issues/856
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>
2024-01-22 11:03:06 -08:00

103 lines
3.5 KiB
Swift

//
// AddMuteItemView.swift
// damus
//
// Created by Charlie Fish on 1/10/24.
//
import SwiftUI
struct AddMuteItemView: View {
let state: DamusState
@State var new_text: String = ""
@State var expiration: DamusDuration?
@Environment(\.dismiss) var dismiss
var body: some View {
VStack {
Text("Add mute item", comment: "Title text to indicate user to an add an item to their mutelist.")
.font(.system(size: 20, weight: .bold))
.padding(.vertical)
Divider()
.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)
}
} label: {
Text("Duration", comment: "The duration in which to mute the given item.")
}
HStack {
Label("", image: "copy2")
.onTapGesture {
if let pasted_text = UIPasteboard.general.string {
self.new_text = pasted_text
}
}
TextField(NSLocalizedString("npub, #hashtag, phrase", comment: "Placeholder example for relay server address."), text: $new_text)
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
Label("", image: "close-circle")
.foregroundColor(.accentColor)
.opacity((new_text == "") ? 0.0 : 1.0)
.onTapGesture {
self.new_text = ""
}
}
.padding(10)
.background(.secondary.opacity(0.2))
.cornerRadius(10)
Button(action: {
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) {
return .user(pubkey, expiration_date)
} else {
return nil
}
} else if new_text.starts(with: "#") {
// Remove the starting `#` character
new_text.removeFirst()
return .hashtag(Hashtag(hashtag: new_text), expiration_date)
} else {
return .word(new_text, expiration_date)
}
}()
// @TODO: in future patch - actually update & relay the new mute list
new_text = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
dismiss()
}) {
HStack {
Text(verbatim: "Add mute item")
.bold()
}
.frame(minWidth: 300, maxWidth: .infinity, alignment: .center)
}
.buttonStyle(GradientButtonStyle(padding: 10))
.padding(.vertical)
Spacer()
}
.padding()
}
}
struct AddMuteItemView_Previews: PreviewProvider {
static var previews: some View {
AddMuteItemView(state: test_damus_state)
}
}