-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ContentView.swift
99 lines (86 loc) · 3.24 KB
/
ContentView.swift
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
import Foundation
import SwiftUI
import UniformTypeIdentifiers
struct ContentDebounce: DebounceSnapshot {
let workflows: Set<ContentViewModel.ID>
let groups: Set<GroupViewModel.ID>
}
struct ContentView: View {
@ObserveInjection var inject
enum Action: Hashable {
case refresh(_ groupIds: Set<WorkflowGroup.ID>)
case moveWorkflowsToGroup(_ groupId: WorkflowGroup.ID, workflows: Set<ContentViewModel.ID>)
case selectWorkflow(workflowIds: Set<ContentViewModel.ID>, groupIds: Set<WorkflowGroup.ID>)
case removeWorkflows(Set<ContentViewModel.ID>)
case reorderWorkflows(source: IndexSet, destination: Int)
case addWorkflow(workflowId: Workflow.ID)
}
static var appStorage: AppStorageStore = .init()
@Namespace var namespace
@Environment(\.controlActiveState) var controlActiveState
@EnvironmentObject private var groupsPublisher: GroupsPublisher
@EnvironmentObject private var publisher: ContentPublisher
@Environment(\.resetFocus) var resetFocus
private var focus: FocusState<AppFocus?>.Binding
private var focusPublisher = FocusPublisher<ContentViewModel>()
@ObservedObject private var contentSelectionManager: SelectionManager<ContentViewModel>
@ObservedObject private var groupSelectionManager: SelectionManager<GroupViewModel>
private let onAction: (Action) -> Void
init(_ focus: FocusState<AppFocus?>.Binding,
contentSelectionManager: SelectionManager<ContentViewModel>,
groupSelectionManager: SelectionManager<GroupViewModel>,
onAction: @escaping (Action) -> Void) {
_contentSelectionManager = .init(initialValue: contentSelectionManager)
_groupSelectionManager = .init(initialValue: groupSelectionManager)
self.focus = focus
self.onAction = onAction
}
var body: some View {
VStack(spacing: 0) {
ContentHeaderView(groupSelectionManager: groupSelectionManager,
namespace: namespace,
onAction: onAction)
ContentListView(focus,
contentSelectionManager: contentSelectionManager,
groupSelectionManager: groupSelectionManager,
focusPublisher: focusPublisher,
onAction: onAction)
.focused(focus, equals: .workflows)
}
.background(
LinearGradient(stops: [
.init(color: Color.clear, location: 0.5),
.init(color: Color(nsColor: .gridColor), location: 1.0),
], startPoint: .topLeading, endPoint: .bottomTrailing)
)
.focusSection()
.debugEdit()
}
private func divider() -> some View {
VStack(spacing: 0) {
Rectangle()
.fill(Color(nsColor: .textBackgroundColor))
Rectangle()
.fill(Color.gray)
.frame(height: 1)
.opacity(0.15)
Rectangle()
.fill(Color.black)
.frame(height: 1)
.opacity(0.5)
}
.allowsHitTesting(false)
.shadow(color: Color(.gridColor), radius: 8, x: 0, y: 2)
.edgesIgnoringSafeArea(.top)
}
}
struct ContentView_Previews: PreviewProvider {
@FocusState static var focus: AppFocus?
static var previews: some View {
ContentView($focus,
contentSelectionManager: .init(),
groupSelectionManager: .init()) { _ in }
.designTime()
.frame(height: 900)
}
}