aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/NewsEditorView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/macOS/NewsEditorView.swift')
-rw-r--r--Hotline/macOS/NewsEditorView.swift52
1 files changed, 27 insertions, 25 deletions
diff --git a/Hotline/macOS/NewsEditorView.swift b/Hotline/macOS/NewsEditorView.swift
index f69c846..9a7242e 100644
--- a/Hotline/macOS/NewsEditorView.swift
+++ b/Hotline/macOS/NewsEditorView.swift
@@ -10,31 +10,32 @@ struct NewsEditorView: View {
@Environment(\.colorScheme) private var colorScheme
@Environment(\.dismiss) private var dismiss
@Environment(Hotline.self) private var model: Hotline
-
+
let editorTitle: String
let isReply: Bool
let path: [String]
let parentID: UInt32
-
+
@State var title: String = ""
@State private var text: String = ""
@State private var sending: Bool = false
-
+
@FocusState private var focusedField: FocusFields?
-
+
func sendArticle() async -> Bool {
sending = true
-
- let success = await model.postNewsArticle(title: title, body: text, at: path, parentID: parentID)
+
+ let success = await model.postNewsArticle(
+ title: title, body: text, at: path, parentID: parentID)
if success {
await model.getNewsList(at: path)
}
-
+
sending = false
-
+
return success
}
-
+
var body: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .center, spacing: 0) {
@@ -49,9 +50,9 @@ struct NewsEditorView: View {
}
.buttonStyle(.plain)
.frame(width: 16, height: 16)
-
+
Spacer()
-
+
if !isReply {
Image("News Category")
.resizable()
@@ -59,20 +60,19 @@ struct NewsEditorView: View {
.frame(width: 16, height: 16)
.padding(.trailing, 6)
}
-
+
Text(editorTitle)
.fontWeight(.semibold)
.lineLimit(1)
.truncationMode(.middle)
-
+
Spacer()
-
+
if sending {
ProgressView()
.controlSize(.small)
.frame(width: 22, height: 22)
- }
- else {
+ } else {
Button {
Task {
if await sendArticle() {
@@ -94,7 +94,7 @@ struct NewsEditorView: View {
}
.frame(maxWidth: .infinity)
.padding([.leading, .top, .trailing])
-
+
TextField("Title", text: $title, axis: .vertical)
.textFieldStyle(.plain)
.lineLimit(3)
@@ -107,9 +107,9 @@ struct NewsEditorView: View {
.clipShape(RoundedRectangle(cornerRadius: 8))
.padding()
.focused($focusedField, equals: .title)
-
+
Divider()
-
+
BetterTextEditor(text: $text)
.betterEditorFont(NSFont.monospacedSystemFont(ofSize: 14.0, weight: .regular))
.betterEditorAutomaticSpellingCorrection(true)
@@ -117,10 +117,10 @@ struct NewsEditorView: View {
.background(Color(nsColor: .textBackgroundColor))
.frame(maxWidth: .infinity, maxHeight: .infinity)
.focused($focusedField, equals: .body)
-
+
HStack(alignment: .center) {
Spacer()
-
+
Text(String("**bold** _italics_ [link name](url) ![image name](url)"))
.foregroundStyle(.secondary)
.font(.caption)
@@ -128,21 +128,23 @@ struct NewsEditorView: View {
.lineLimit(1)
.truncationMode(.middle)
.padding()
-
+
Spacer()
}
.frame(maxWidth: .infinity)
.background(.tertiary.opacity(0.15))
}
- .frame(minWidth: 300, idealWidth: 450, maxWidth: .infinity, minHeight: 300, idealHeight: 500, maxHeight: .infinity)
+ .frame(
+ minWidth: 300, idealWidth: 450, maxWidth: .infinity, minHeight: 300, idealHeight: 500,
+ maxHeight: .infinity
+ )
.background(Color(nsColor: .textBackgroundColor))
.presentationCompactAdaptation(.sheet)
.toolbarTitleDisplayMode(.inlineLarge)
.onAppear {
if !title.isEmpty {
focusedField = .body
- }
- else {
+ } else {
focusedField = .title
}
}