forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedPanel.swift
More file actions
56 lines (49 loc) · 1.57 KB
/
Copy pathSharedPanel.swift
File metadata and controls
56 lines (49 loc) · 1.57 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
import ComposableArchitecture
import Preferences
import SwiftUI
@Reducer
public struct SharedPanel {
public struct Content {
public var promptToCodeGroup = PromptToCodeGroup.State()
var suggestion: PresentingCodeSuggestion?
var error: String?
}
@ObservableState
public struct State {
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.promptToCodeGroup.promptToCodes.isEmpty { 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 {
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
}
}
}
}