-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathSharedPanelFeature.swift
More file actions
58 lines (51 loc) · 1.71 KB
/
SharedPanelFeature.swift
File metadata and controls
58 lines (51 loc) · 1.71 KB
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
import ComposableArchitecture
import Preferences
import SwiftUI
@Reducer
public struct SharedPanelFeature {
public struct Content: Equatable {
public var promptToCodeGroup = PromptToCodeGroup.State()
var suggestion: CodeSuggestionProvider?
var isExpanded: Bool = false
public var promptToCode: PromptToCode.State? { promptToCodeGroup.activePromptToCode }
var error: String?
}
@ObservableState
public struct State: Equatable {
var content: Content = .init()
var colorScheme: ColorScheme = .light
var alignTopToAnchor = false
var isPanelDisplayed: Bool = false
var isEmpty: Bool {
if content.error != nil { return false }
if content.promptToCode != nil { return false }
if content.suggestion != nil,
UserDefaults.shared
.value(for: \.suggestionPresentationMode) == .floatingWidget { return false }
return true
}
var opacity: Double {
guard isPanelDisplayed else { return 0 }
guard !isEmpty else { return 0 }
return 1
}
}
public enum Action: Equatable {
case errorMessageCloseButtonTapped
case promptToCodeGroup(PromptToCodeGroup.Action)
}
public var body: some ReducerOf<Self> {
Scope(state: \.content.promptToCodeGroup, action: \.promptToCodeGroup) {
PromptToCodeGroup()
}
Reduce { state, action in
switch action {
case .errorMessageCloseButtonTapped:
state.content.error = nil
return .none
case .promptToCodeGroup:
return .none
}
}
}
}