aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/BroadcastMessageSheet.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-14 09:56:46 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-14 09:56:46 -0800
commitda1d7001f5132115bfdbe19cd95e73b04ba76c95 (patch)
treeba9b446db9a15e4b32d9101be518bdf65ac105a2 /Hotline/macOS/BroadcastMessageSheet.swift
parent46384d99b78cca150aa720eb915d161b5be8c08d (diff)
Add kick and improve client info display. Also improve error messages when can't connect (server down) or can't login (show server message).
Diffstat (limited to 'Hotline/macOS/BroadcastMessageSheet.swift')
-rw-r--r--Hotline/macOS/BroadcastMessageSheet.swift66
1 files changed, 66 insertions, 0 deletions
diff --git a/Hotline/macOS/BroadcastMessageSheet.swift b/Hotline/macOS/BroadcastMessageSheet.swift
new file mode 100644
index 0000000..b3bd7ea
--- /dev/null
+++ b/Hotline/macOS/BroadcastMessageSheet.swift
@@ -0,0 +1,66 @@
+import SwiftUI
+
+fileprivate let CHARACTER_LIMIT: Int = 255
+
+struct BroadcastMessageSheet: View {
+ @Environment(HotlineState.self) private var model: HotlineState
+ @Environment(\.dismiss) private var dismiss
+
+ @State private var sending: Bool = false
+
+ private var message: String {
+ self.model.broadcastMessage.trimmingCharacters(in: .whitespacesAndNewlines)
+ }
+
+ var body: some View {
+ @Bindable var model = self.model
+
+ VStack {
+ TextField("Write a message...", text: $model.broadcastMessage, axis: .vertical)
+ .textFieldStyle(.plain)
+ .lineLimit(5, reservesSpace: true)
+ }
+ .padding(.leading, 32)
+ .padding(.top, 2)
+ .overlay(alignment: .topLeading) {
+ Image("Server Message")
+ }
+ .padding(16)
+ .frame(width: 400)
+ .toolbar {
+ if self.sending {
+ ToolbarItem {
+ ProgressView()
+ .controlSize(.small)
+ }
+ }
+
+ ToolbarItem(placement: .cancellationAction) {
+ Button("Cancel") {
+ self.dismiss()
+ }
+ }
+
+ ToolbarItem(placement: .confirmationAction) {
+ Button("Broadcast") {
+ let message = self.message
+ model.broadcastMessage = ""
+
+ guard !message.isBlank else {
+ return
+ }
+
+ Task {
+ self.sending = true
+ defer { self.sending = false }
+
+ try await model.sendBroadcast(message)
+
+ self.dismiss()
+ }
+ }
+ .disabled(self.message.isEmpty)
+ }
+ }
+ }
+}