profile: allow post button on every profile and prefill user tag
Changelog-Added: Add post button to profile pages
This commit is contained in:
@@ -128,7 +128,7 @@ struct ContentView: View {
|
|||||||
|
|
||||||
if privkey != nil {
|
if privkey != nil {
|
||||||
PostButtonContainer(is_left_handed: damus_state?.settings.left_handed ?? false) {
|
PostButtonContainer(is_left_handed: damus_state?.settings.left_handed ?? false) {
|
||||||
self.active_sheet = .post(.posting)
|
self.active_sheet = .post(.posting(.none))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,15 @@ class TagModel: ObservableObject {
|
|||||||
var diff = 0
|
var diff = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum PostTarget {
|
||||||
|
case none
|
||||||
|
case user(String)
|
||||||
|
}
|
||||||
|
|
||||||
enum PostAction {
|
enum PostAction {
|
||||||
case replying_to(NostrEvent)
|
case replying_to(NostrEvent)
|
||||||
case quoting(NostrEvent)
|
case quoting(NostrEvent)
|
||||||
case posting
|
case posting(PostTarget)
|
||||||
|
|
||||||
var ev: NostrEvent? {
|
var ev: NostrEvent? {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -155,9 +160,20 @@ struct PostView: View {
|
|||||||
.clipShape(Capsule())
|
.clipShape(Capsule())
|
||||||
}
|
}
|
||||||
|
|
||||||
var isEmpty: Bool {
|
func isEmpty() -> Bool {
|
||||||
self.uploadedMedias.count == 0 &&
|
return self.uploadedMedias.count == 0 &&
|
||||||
self.post.mutableString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
self.post.mutableString.trimmingCharacters(in: .whitespacesAndNewlines) ==
|
||||||
|
initialString().mutableString.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initialString() -> NSMutableAttributedString {
|
||||||
|
guard case .posting(let target) = action,
|
||||||
|
case .user(let pubkey) = target else {
|
||||||
|
return .init(string: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
let profile = damus_state.profiles.lookup(id: pubkey)
|
||||||
|
return user_tag_attr_string(profile: profile, pubkey: pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func clear_draft() {
|
func clear_draft() {
|
||||||
@@ -172,15 +188,17 @@ struct PostView: View {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_draft() {
|
func load_draft() -> Bool {
|
||||||
guard let draft = load_draft_for_post(drafts: self.damus_state.drafts, action: self.action) else {
|
guard let draft = load_draft_for_post(drafts: self.damus_state.drafts, action: self.action) else {
|
||||||
self.post = NSMutableAttributedString("")
|
self.post = NSMutableAttributedString("")
|
||||||
self.uploadedMedias = []
|
self.uploadedMedias = []
|
||||||
return
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
self.uploadedMedias = draft.media
|
self.uploadedMedias = draft.media
|
||||||
self.post = draft.content
|
self.post = draft.content
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func post_changed(post: NSMutableAttributedString, media: [UploadedMedia]) {
|
func post_changed(post: NSMutableAttributedString, media: [UploadedMedia]) {
|
||||||
@@ -321,6 +339,11 @@ struct PostView: View {
|
|||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fill_target_content(target: PostTarget) {
|
||||||
|
self.post = initialString()
|
||||||
|
self.tagModel.diff = post.string.count
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { (deviceSize: GeometryProxy) in
|
GeometryReader { (deviceSize: GeometryProxy) in
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
@@ -390,7 +413,7 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear() {
|
.onAppear() {
|
||||||
load_draft()
|
let loaded_draft = load_draft()
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case .replying_to(let replying_to):
|
case .replying_to(let replying_to):
|
||||||
@@ -399,8 +422,10 @@ struct PostView: View {
|
|||||||
case .quoting(let quoting):
|
case .quoting(let quoting):
|
||||||
references = gather_quote_ids(our_pubkey: damus_state.pubkey, from: quoting)
|
references = gather_quote_ids(our_pubkey: damus_state.pubkey, from: quoting)
|
||||||
originalReferences = references
|
originalReferences = references
|
||||||
case .posting:
|
case .posting(let target):
|
||||||
break
|
guard !loaded_draft else { break }
|
||||||
|
|
||||||
|
fill_target_content(target: target)
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
@@ -408,7 +433,7 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
if isEmpty {
|
if isEmpty() {
|
||||||
clear_draft()
|
clear_draft()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,7 +473,7 @@ func get_searching_string(_ word: String?) -> String? {
|
|||||||
|
|
||||||
struct PostView_Previews: PreviewProvider {
|
struct PostView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
PostView(action: .posting, damus_state: test_damus_state())
|
PostView(action: .posting(.none), damus_state: test_damus_state())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -523,9 +523,9 @@ struct ProfileView: View {
|
|||||||
QRCodeView(damus_state: damus_state, pubkey: profile.pubkey)
|
QRCodeView(damus_state: damus_state, pubkey: profile.pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if profile.pubkey == damus_state.pubkey && damus_state.is_privkey_user {
|
if damus_state.is_privkey_user {
|
||||||
PostButtonContainer(is_left_handed: damus_state.settings.left_handed) {
|
PostButtonContainer(is_left_handed: damus_state.settings.left_handed) {
|
||||||
notify(.compose, PostAction.posting)
|
notify(.compose, PostAction.posting(.user(profile.pubkey)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user