From e201330efa9fe8f8177119fe001fa0c42fd4053a Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Sat, 13 Jan 2024 19:48:03 -0800 Subject: Add support for posting to the message board. --- Hotline/macOS/MessageBoardView.swift | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'Hotline/macOS/MessageBoardView.swift') diff --git a/Hotline/macOS/MessageBoardView.swift b/Hotline/macOS/MessageBoardView.swift index 65a947f..e7fdeb5 100644 --- a/Hotline/macOS/MessageBoardView.swift +++ b/Hotline/macOS/MessageBoardView.swift @@ -4,6 +4,8 @@ struct MessageBoardView: View { @Environment(Hotline.self) private var model: Hotline @State private var initialLoadComplete = false + @State private var composerDisplayed = false + @State private var composerText = "" var body: some View { NavigationStack { @@ -12,6 +14,7 @@ struct MessageBoardView: View { ForEach(model.messageBoard, id: \.self) { Text($0) .lineLimit(100) + .lineSpacing(4) .padding() .textSelection(.enabled) Divider() @@ -35,10 +38,37 @@ struct MessageBoardView: View { } .background(Color(nsColor: .textBackgroundColor)) } + .sheet(isPresented: $composerDisplayed) { + TextEditor(text: $composerText) + .padding() + .font(.system(size: 13)) + .lineSpacing(4) + .background(Color(nsColor: .textBackgroundColor)) + .frame(idealWidth: 450, idealHeight: 350) + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button("Cancel") { + composerDisplayed.toggle() + } + } + + ToolbarItem(placement: .primaryAction) { + Button("Post") { + composerDisplayed.toggle() + let text = composerText + composerText = "" + model.postToMessageBoard(text: text) + Task { + await model.getMessageBoard() + } + } + } + } + } .toolbar { ToolbarItem(placement:.primaryAction) { Button { - + composerDisplayed.toggle() } label: { Image(systemName: "square.and.pencil") } -- cgit