@@ -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
0 commit comments