Choose Participants on a Thread Reply
Closes: #345 Changelog-Added: Add the ability to choose participants when replying
This commit is contained in:
committed by
William Casarin
parent
5e9580377d
commit
2a9ddd10c8
79
damus/Views/ParicipantsView.swift
Normal file
79
damus/Views/ParicipantsView.swift
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// ParicipantsView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Joel Klabo on 1/18/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ParticipantsView: View {
|
||||
|
||||
let damus_state: DamusState
|
||||
|
||||
@Binding var references: [ReferencedId]
|
||||
@Binding var originalReferences: [ReferencedId]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Edit participants")
|
||||
HStack {
|
||||
Spacer()
|
||||
Button {
|
||||
// Remove all "p" refs, keep "e" refs
|
||||
references = originalReferences.eRefs
|
||||
} label: {
|
||||
Text("Remove all")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
Spacer()
|
||||
Button {
|
||||
references = originalReferences
|
||||
} label: {
|
||||
Text("Add all")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
Spacer()
|
||||
}
|
||||
VStack {
|
||||
ForEach(originalReferences.pRefs) { participant in
|
||||
let pubkey = participant.id
|
||||
HStack {
|
||||
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
let profile = damus_state.profiles.lookup(id: pubkey)
|
||||
ProfileName(pubkey: pubkey, profile: profile, damus: damus_state, show_friend_confirmed: false, show_nip5_domain: false)
|
||||
if let about = profile?.about {
|
||||
Text(FollowUserView.markdown.process(about))
|
||||
.lineLimit(3)
|
||||
.font(.footnote)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.font(.system(size: 30))
|
||||
.foregroundColor(references.contains(participant) ? .purple : .gray)
|
||||
}
|
||||
.onTapGesture {
|
||||
if references.contains(participant) {
|
||||
references = references.filter {
|
||||
$0 != participant
|
||||
}
|
||||
} else {
|
||||
if references.contains(participant) {
|
||||
// Don't add it twice
|
||||
} else {
|
||||
references.append(participant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,16 @@ struct ReplyView: View {
|
||||
let replying_to: NostrEvent
|
||||
let damus: DamusState
|
||||
|
||||
@State var originalReferences: [ReferencedId] = []
|
||||
@State var references: [ReferencedId] = []
|
||||
|
||||
@State var participantsShown: Bool = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Replying to:", comment: "Indicating that the user is replying to the following listed people.")
|
||||
HStack(alignment: .top) {
|
||||
let names = all_referenced_pubkeys(replying_to)
|
||||
let names = references.pRefs
|
||||
.map { pubkey in
|
||||
let pk = pubkey.ref_id
|
||||
let prof = damus.profiles.lookup(id: pk)
|
||||
@@ -33,13 +38,22 @@ struct ReplyView: View {
|
||||
.foregroundColor(.gray)
|
||||
.font(.footnote)
|
||||
}
|
||||
ScrollView {
|
||||
EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
|
||||
.onTapGesture {
|
||||
participantsShown.toggle()
|
||||
}
|
||||
PostView(replying_to: replying_to, references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to))
|
||||
.sheet(isPresented: $participantsShown) {
|
||||
ParticipantsView(damus_state: damus, references: $references, originalReferences: $originalReferences)
|
||||
}
|
||||
ScrollView {
|
||||
EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
|
||||
}
|
||||
PostView(replying_to: replying_to, references: references)
|
||||
}
|
||||
.onAppear {
|
||||
references = gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to)
|
||||
originalReferences = references
|
||||
}
|
||||
.padding()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +61,6 @@ struct ReplyView: View {
|
||||
|
||||
struct ReplyView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state())
|
||||
ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state(), references: [])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user