@@ -25,8 +25,10 @@ import {
25
25
} from "@remix-run/react" ;
26
26
import {
27
27
GetOidcRedirectUrlDocument ,
28
+ LatestUserSummaryDocument ,
28
29
LoginErrorVariant ,
29
30
LoginUserDocument ,
31
+ MediaLot ,
30
32
RegisterErrorVariant ,
31
33
RegisterUserDocument ,
32
34
} from "@ryot/generated/graphql/backend/graphql" ;
@@ -38,11 +40,12 @@ import { match } from "ts-pattern";
38
40
import { withQuery } from "ufo" ;
39
41
import { z } from "zod" ;
40
42
import { zx } from "zodix" ;
41
- import { redirectToQueryParam } from "~/lib/generals" ;
43
+ import { dayjsLib , redirectToQueryParam } from "~/lib/generals" ;
42
44
import {
43
45
createToastHeaders ,
44
46
getAuthorizationCookie ,
45
47
getCachedCoreDetails ,
48
+ getCachedUserPreferences ,
46
49
getCookiesForApplication ,
47
50
getCoreEnabledFeatures ,
48
51
processSubmission ,
@@ -61,10 +64,30 @@ export type SearchParams = z.infer<typeof searchParamsSchema> &
61
64
export const loader = unstable_defineLoader ( async ( { request } ) => {
62
65
const query = zx . parseQuery ( request , searchParamsSchema ) ;
63
66
const isAuthenticated = ! ! getAuthorizationCookie ( request ) ;
64
- if ( isAuthenticated )
67
+ if ( isAuthenticated ) {
68
+ const [ userPreferences , { latestUserSummary } ] = await Promise . all ( [
69
+ getCachedUserPreferences ( request ) ,
70
+ serverGqlService . authenticatedRequest ( request , LatestUserSummaryDocument ) ,
71
+ ] ) ;
72
+ if (
73
+ latestUserSummary . data . media . metadataOverall . interactedWith === 0 &&
74
+ userPreferences . featuresEnabled . media . enabled === true
75
+ )
76
+ throw await redirectWithToast (
77
+ $path (
78
+ "/media/:action/:lot" ,
79
+ { action : "search" , lot : MediaLot . Movie } ,
80
+ { query : "avengers" } ,
81
+ ) ,
82
+ {
83
+ message : "Welcome to Ryot! Add any movie you want to your watchlist!" ,
84
+ closeAfter : dayjsLib . duration ( 10 , "second" ) . asMilliseconds ( ) ,
85
+ } ,
86
+ ) ;
65
87
throw await redirectWithToast ( $path ( "/" ) , {
66
88
message : "You were already logged in" ,
67
89
} ) ;
90
+ }
68
91
const [ enabledFeatures , { coreDetails } ] = await Promise . all ( [
69
92
getCoreEnabledFeatures ( ) ,
70
93
getCachedCoreDetails ( ) ,
@@ -141,11 +164,12 @@ export const action = unstable_defineAction(async ({ request }) => {
141
164
} ,
142
165
} ) ;
143
166
if ( loginUser . __typename === "LoginResponse" ) {
144
- let redirectUrl = $path ( "/" ) ;
145
- if ( submission [ redirectToQueryParam ] )
146
- redirectUrl = safeRedirect ( submission [ redirectToQueryParam ] ) ;
147
167
const headers = await getCookiesForApplication ( loginUser . apiKey ) ;
148
- return redirect ( redirectUrl , { headers } ) ;
168
+ if ( submission [ redirectToQueryParam ] )
169
+ return redirect ( safeRedirect ( submission [ redirectToQueryParam ] ) , {
170
+ headers,
171
+ } ) ;
172
+ return Response . json ( { } , { headers } ) ;
149
173
}
150
174
const message = match ( loginUser . error )
151
175
. with (
0 commit comments