|
@ -12,11 +12,15 @@ enum NostrPostResult { |
|
|
case cancel |
|
|
case cancel |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let POST_PLACEHOLDER = "Type your post here..." |
|
|
|
|
|
|
|
|
struct PostView: View { |
|
|
struct PostView: View { |
|
|
@State var post: String = "" |
|
|
@State var post: String = POST_PLACEHOLDER |
|
|
|
|
|
@State var new: Bool = true |
|
|
|
|
|
|
|
|
@FocusState var focus: Bool |
|
|
@FocusState var focus: Bool |
|
|
let references: [ReferencedId] |
|
|
let references: [ReferencedId] |
|
|
|
|
|
|
|
|
@Environment(\.presentationMode) var presentationMode |
|
|
@Environment(\.presentationMode) var presentationMode |
|
|
|
|
|
|
|
|
enum FocusField: Hashable { |
|
|
enum FocusField: Hashable { |
|
@ -27,7 +31,7 @@ struct PostView: View { |
|
|
NotificationCenter.default.post(name: .post, object: NostrPostResult.cancel) |
|
|
NotificationCenter.default.post(name: .post, object: NostrPostResult.cancel) |
|
|
dismiss() |
|
|
dismiss() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func dismiss() { |
|
|
func dismiss() { |
|
|
self.presentationMode.wrappedValue.dismiss() |
|
|
self.presentationMode.wrappedValue.dismiss() |
|
|
} |
|
|
} |
|
@ -37,7 +41,7 @@ struct PostView: View { |
|
|
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post)) |
|
|
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post)) |
|
|
dismiss() |
|
|
dismiss() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var is_post_empty: Bool { |
|
|
var is_post_empty: Bool { |
|
|
return post.allSatisfy { $0.isWhitespace } |
|
|
return post.allSatisfy { $0.isWhitespace } |
|
|
} |
|
|
} |
|
@ -60,8 +64,17 @@ struct PostView: View { |
|
|
} |
|
|
} |
|
|
.padding([.top, .bottom], 4) |
|
|
.padding([.top, .bottom], 4) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextEditor(text: $post) |
|
|
TextEditor(text: $post) |
|
|
|
|
|
.foregroundColor(self.post == POST_PLACEHOLDER ? .gray : .primary) |
|
|
.focused($focus) |
|
|
.focused($focus) |
|
|
|
|
|
.onTapGesture { |
|
|
|
|
|
handle_post_placeholder() |
|
|
|
|
|
} |
|
|
|
|
|
.onChange(of: post) { value in |
|
|
|
|
|
handle_post_placeholder() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
.onAppear() { |
|
|
.onAppear() { |
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { |
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { |
|
@ -70,5 +83,14 @@ struct PostView: View { |
|
|
} |
|
|
} |
|
|
.padding() |
|
|
.padding() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handle_post_placeholder() { |
|
|
|
|
|
guard new else { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
new = false |
|
|
|
|
|
post = post.replacingOccurrences(of: POST_PLACEHOLDER, with: "") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|