aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/NewsEditorView.swift
blob: 18c4a0da15e2030b7838467c2a2d0677e319e407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import SwiftUI
import UniformTypeIdentifiers

struct NewsEditorView: View {
  @Environment(\.controlActiveState) private var controlActiveState
  @Environment(\.colorScheme) private var colorScheme
  @Environment(\.dismiss) private var dismiss
  @Environment(Hotline.self) private var model: Hotline
  
//  @Binding var article: NewsArticle?
  @State var title: String = ""
  @State var text: String = ""
  
  var body: some View {
    NavigationStack {
      VStack(alignment: .leading, spacing: 0) {
        HStack {
          Button {
            dismiss()
          } label: {
            Image(systemName: "xmark.circle.fill")
              .resizable()
              .scaledToFit()
          }
          .buttonStyle(.plain)
          .frame(width: 16, height: 16)
          .padding()
          
          Spacer()
          
          Button {
          } label: {
            Image(systemName: "paperplane")
              .resizable()
              .scaledToFit()
          }
          .buttonStyle(.plain)
          .frame(width: 16, height: 16)
          .padding()
        }
        .frame(maxWidth: .infinity)
        TextField("Title", text: $title, axis: .vertical)
          .textFieldStyle(.plain)
          .padding()
          .focusEffectDisabled()
          .font(.title)
          .frame(maxWidth: .infinity)
          .border(Color.pink, width: 0)
        Divider()
        TextEditor(text: $text)
          .textEditorStyle(.plain)
          .font(.system(size: 14))
          .lineSpacing(3)
          .padding(16)
          .contentMargins(.top, -16.0, for: .scrollIndicators)
          .contentMargins(.bottom, -16.0, for: .scrollIndicators)
          .contentMargins(.trailing, -16.0, for: .scrollIndicators)
          .scrollClipDisabled()
          .frame(maxWidth: .infinity, maxHeight: .infinity)
      }
    }
    .frame(minWidth: 300, idealWidth: 450, maxWidth: .infinity, minHeight: 300, idealHeight: 500, maxHeight: .infinity)
    .background(Color(nsColor: .textBackgroundColor))
    .presentationCompactAdaptation(.sheet)
    .toolbarTitleDisplayMode(.inlineLarge)
//    .toolbar {
//      ToolbarItem(placement: .navigation) {
//        Button("Post", action: {})
//      }
//      ToolbarItem(placement: .automatic) {
//        Button("Delete", action: {
//          dismiss()
//        })
//      }
//    }
    .task {
//      if let info = info {
//        preview = FilePreview(info: info)
//        preview?.download()
//      }
    }
    .onAppear {
//      if info == nil {
//        Task {
//          dismiss()
//        }
//        return
//      }
    }
    .onDisappear {
//      preview?.cancel()
      dismiss()
    }
//    .onChange(of: preview?.state) {
//      if preview?.state == .failed {
//        dismiss()
//      }
//    }
  }
}