forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedPanelFeature.swift
More file actions
54 lines (48 loc) · 1.49 KB
/
SharedPanelFeature.swift
File metadata and controls
54 lines (48 loc) · 1.49 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
import ComposableArchitecture
import Environment
import Preferences
import SwiftUI
public struct SharedPanelFeature: ReducerProtocol {
public enum Content: Equatable {
case suggestion(SuggestionProvider)
case promptToCode(PromptToCodeProvider)
case error(String)
var contentHash: String {
switch self {
case let .error(e):
return "error: \(e)"
case let .suggestion(provider):
return "suggestion: \(provider.code.hashValue)"
case let .promptToCode(provider):
return "provider: \(provider.id)"
}
}
public static func == (lhs: Content, rhs: Content) -> Bool {
lhs.contentHash == rhs.contentHash
}
}
public struct State: Equatable {
var content: Content?
var colorScheme: ColorScheme = .light
var alignTopToAnchor = false
var isPanelDisplayed: Bool = false
var opacity: Double {
guard isPanelDisplayed else { return 0 }
guard content != nil else { return 0 }
return 1
}
}
public enum Action: Equatable {
case closeButtonTapped
}
public var body: some ReducerProtocol<State, Action> {
Reduce { state, action in
switch action {
case .closeButtonTapped:
state.content = nil
state.isPanelDisplayed = false
return .none
}
}
}
}