Skip to content

Commit aa0fe32

Browse files
committed
Adjust timing issue of prompt to code
1 parent 80acb92 commit aa0fe32

4 files changed

Lines changed: 44 additions & 19 deletions

File tree

Core/Sources/SuggestionWidget/FeatureReducers/PanelFeature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public struct PanelFeature: ReducerProtocol {
111111

112112
case .removeDisplayedContent:
113113
state.content.error = nil
114-
state.content.promptToCodeGroup.activePromptToCode = nil
114+
state.content.promptToCodeGroup.activeDocumentURL = nil
115115
state.content.suggestion = nil
116116
return .none
117117

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodeGroup.swift

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public struct PromptToCodeGroup: ReducerProtocol {
1818
guard let id = activeDocumentURL else { return nil }
1919
return promptToCodes[id: id]
2020
}
21-
set { activeDocumentURL = newValue?.id }
21+
set {
22+
activeDocumentURL = newValue?.id
23+
if let id = newValue?.id {
24+
promptToCodes[id: id] = newValue
25+
}
26+
}
2227
}
2328
}
2429

@@ -77,6 +82,7 @@ public struct PromptToCodeGroup: ReducerProtocol {
7782
case updateActivePromptToCode(documentURL: URL)
7883
case discardExpiredPromptToCode(documentURLs: [URL])
7984
case promptToCode(PromptToCode.State.ID, PromptToCode.Action)
85+
case activePromptToCode(PromptToCode.Action)
8086
}
8187

8288
@Dependency(\.promptToCodeServiceFactory) var promptToCodeServiceFactory
@@ -141,22 +147,38 @@ public struct PromptToCodeGroup: ReducerProtocol {
141147
}
142148
return .none
143149

144-
case let .promptToCode(id, action):
145-
switch action {
146-
case .cancelButtonTapped:
147-
state.promptToCodes.remove(id: id)
148-
return .run { _ in
149-
activatePreviousActiveXcode()
150-
}
151-
default:
152-
return .none
153-
}
150+
case .promptToCode:
151+
return .none
152+
153+
case .activePromptToCode:
154+
return .none
154155
}
155156
}
157+
.ifLet(\.activePromptToCode, action: /Action.activePromptToCode) {
158+
PromptToCode()
159+
.dependency(\.promptToCodeService, promptToCodeServiceFactory())
160+
}
156161
.forEach(\.promptToCodes, action: /Action.promptToCode, element: {
157162
PromptToCode()
158163
.dependency(\.promptToCodeService, promptToCodeServiceFactory())
159164
})
165+
166+
Reduce { state, action in
167+
switch action {
168+
case let .promptToCode(id, .cancelButtonTapped):
169+
state.promptToCodes.remove(id: id)
170+
return .run { _ in
171+
activatePreviousActiveXcode()
172+
}
173+
case .activePromptToCode(.cancelButtonTapped):
174+
guard let id = state.activePromptToCode?.id else { return .none }
175+
state.promptToCodes.remove(id: id)
176+
return .run { _ in
177+
activatePreviousActiveXcode()
178+
}
179+
default: return .none
180+
}
181+
}
160182
}
161183
}
162184

Core/Sources/SuggestionWidget/FeatureReducers/WidgetFeature.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ public struct WidgetFeature: ReducerProtocol {
196196
Scope(state: \.panelState, action: /Action.panel) {
197197
PanelFeature()
198198
}
199-
200-
Reduce { state, action in
199+
200+
Reduce { _, action in
201201
switch action {
202202
case .panel(.sharedPanel(.promptToCodeGroup(.activateOrCreatePromptToCode))):
203203
return .run { send in
@@ -619,7 +619,7 @@ public struct WidgetFeature: ReducerProtocol {
619619
return .none
620620

621621
case let .updateKeyWindow(window):
622-
return .run { send in
622+
return .run { _ in
623623
switch window {
624624
case .chatPanel:
625625
await windows.chatPanelWindow.makeKeyAndOrderFront(nil)

Core/Sources/SuggestionWidget/SharedPanelView.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ struct SharedPanelView: View {
5757
)
5858
}
5959
} else if let promptToCode = viewStore.state.promptToCode {
60-
PromptToCodePanel(store: store.scope(
61-
state: { _ in promptToCode },
60+
IfLetStore(store.scope(
61+
state: { $0.content.promptToCodeGroup.activePromptToCode },
6262
action: {
6363
SharedPanelFeature.Action
64-
.promptToCodeGroup(.promptToCode(promptToCode.id, $0))
64+
.promptToCodeGroup(.activePromptToCode($0))
6565
}
66-
))
66+
)) {
67+
PromptToCodePanel(store: $0)
68+
}
69+
6770
} else if let suggestion = viewStore.state.suggestion {
6871
switch suggestionPresentationMode {
6972
case .nearbyTextCursor:

0 commit comments

Comments
 (0)