Files
damus/damus/Views/PostView.swift
William Casarin 0eb1372937 more mention progress
Signed-off-by: William Casarin <jb55@jb55.com>
2022-05-07 13:50:19 -07:00

87 lines
1.9 KiB
Swift

//
// Post.swift
// damus
//
// Created by William Casarin on 2022-04-03.
//
import SwiftUI
enum NostrPostResult {
case post(NostrPost)
case cancel
}
struct PostView: View {
@State var post: String = ""
@FocusState var focus: Bool
let references: [ReferencedId]
@Environment(\.presentationMode) var presentationMode
enum FocusField: Hashable {
case post
}
func cancel() {
NotificationCenter.default.post(name: .post, object: NostrPostResult.cancel)
dismiss()
}
func dismiss() {
self.presentationMode.wrappedValue.dismiss()
}
func send_post() {
let new_post = NostrPost(content: self.post, references: references)
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post))
dismiss()
}
var body: some View {
VStack {
HStack {
Button("Cancel") {
self.cancel()
}
.foregroundColor(.primary)
Spacer()
Button("Post") {
self.send_post()
}
}
.padding([.top, .bottom], 4)
HStack(alignment: .top) {
ZStack(alignment: .leading) {
TextEditor(text: $post)
.focused($focus)
if self.post == "" {
VStack {
Text("What's happening?")
.foregroundColor(.gray)
.padding(6)
Spacer()
}
}
}
Spacer()
}
Spacer()
}
.onAppear() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.focus = true
}
}
.padding()
}
}