@@ -29,6 +29,7 @@ import {
29
29
MetadataSpecificsSchema ,
30
30
colorSchemeCookie ,
31
31
createToastHeaders ,
32
+ extendResponseHeaders ,
32
33
getAuthorizationHeader ,
33
34
getLogoutCookies ,
34
35
gqlClient ,
@@ -43,7 +44,8 @@ export const action = unstable_defineAction(async ({ request, response }) => {
43
44
const url = new URL ( request . url ) ;
44
45
const intent = url . searchParams . get ( "intent" ) as string ;
45
46
invariant ( intent , "No intent provided" ) ;
46
- let redirectTo = formData . get ( redirectToQueryParam ) ;
47
+ const redirectToForm = formData . get ( redirectToQueryParam ) ;
48
+ let redirectTo = redirectToForm ? redirectToForm . toString ( ) : undefined ;
47
49
let returnData = { } ;
48
50
await match ( intent )
49
51
. with ( "commitMedia" , async ( ) => {
@@ -109,7 +111,10 @@ export const action = unstable_defineAction(async ({ request, response }) => {
109
111
} )
110
112
. with ( "logout" , async ( ) => {
111
113
redirectTo = $path ( "/auth" ) ;
112
- response . headers = await getLogoutCookies ( ) ;
114
+ response . headers = extendResponseHeaders (
115
+ response . headers ,
116
+ await getLogoutCookies ( ) ,
117
+ ) ;
113
118
} )
114
119
. with ( "createReviewComment" , async ( ) => {
115
120
const submission = processSubmission ( formData , reviewCommentSchema ) ;
@@ -118,15 +123,18 @@ export const action = unstable_defineAction(async ({ request, response }) => {
118
123
{ input : submission } ,
119
124
await getAuthorizationHeader ( request ) ,
120
125
) ;
121
- response . headers = await createToastHeaders ( {
122
- message :
123
- submission . incrementLikes || submission . decrementLikes
124
- ? "Score changed successfully"
125
- : `Comment ${
126
- submission . shouldDelete ? "deleted" : "posted"
127
- } successfully`,
128
- type : "success" ,
129
- } ) ;
126
+ response . headers = extendResponseHeaders (
127
+ response . headers ,
128
+ await createToastHeaders ( {
129
+ message :
130
+ submission . incrementLikes || submission . decrementLikes
131
+ ? "Score changed successfully"
132
+ : `Comment ${
133
+ submission . shouldDelete ? "deleted" : "posted"
134
+ } successfully`,
135
+ type : "success" ,
136
+ } ) ,
137
+ ) ;
130
138
} )
131
139
. with ( "addEntityToCollection" , async ( ) => {
132
140
const [ submission , input ] =
@@ -147,10 +155,13 @@ export const action = unstable_defineAction(async ({ request, response }) => {
147
155
await getAuthorizationHeader ( request ) ,
148
156
) ;
149
157
}
150
- response . headers = await createToastHeaders ( {
151
- message : "Media added to collection successfully" ,
152
- type : "success" ,
153
- } ) ;
158
+ response . headers = extendResponseHeaders (
159
+ response . headers ,
160
+ await createToastHeaders ( {
161
+ message : "Media added to collection successfully" ,
162
+ type : "success" ,
163
+ } ) ,
164
+ ) ;
154
165
} )
155
166
. with ( "removeEntityFromCollection" , async ( ) => {
156
167
const [ submission , input ] =
@@ -176,32 +187,34 @@ export const action = unstable_defineAction(async ({ request, response }) => {
176
187
{ reviewId : submission . reviewId } ,
177
188
await getAuthorizationHeader ( request ) ,
178
189
) ;
179
- response . headers = await createToastHeaders ( {
180
- message : "Review deleted successfully" ,
181
- type : "success" ,
182
- } ) ;
190
+ response . headers = extendResponseHeaders (
191
+ response . headers ,
192
+ await createToastHeaders ( {
193
+ message : "Review deleted successfully" ,
194
+ type : "success" ,
195
+ } ) ,
196
+ ) ;
183
197
} else {
184
198
await gqlClient . request (
185
199
PostReviewDocument ,
186
200
{ input : submission } ,
187
201
await getAuthorizationHeader ( request ) ,
188
202
) ;
189
- response . headers = await createToastHeaders ( {
190
- message : "Review submitted successfully" ,
191
- type : "success" ,
192
- } ) ;
203
+ response . headers = extendResponseHeaders (
204
+ response . headers ,
205
+ await createToastHeaders ( {
206
+ message : "Review submitted successfully" ,
207
+ type : "success" ,
208
+ } ) ,
209
+ ) ;
193
210
}
194
211
} )
195
212
. run ( ) ;
196
213
if ( redirectTo ) {
197
214
response . headers . append ( "Location" , redirectTo . toString ( ) ) ;
198
215
response . status = 302 ;
199
216
}
200
- // FIXME Once https://discord.com/channels/770287896669978684/1251219797098762290 is resolved
201
- return Response . json ( returnData , {
202
- headers : response . headers ,
203
- status : response . status ,
204
- } ) ;
217
+ return Response . json ( returnData ) ;
205
218
} ) ;
206
219
207
220
const commitMediaSchema = z . object ( {
0 commit comments