@@ -30,6 +30,8 @@ import {
3030 CreateContestDialog ,
3131 type CreateContestDialogInitialValues ,
3232} from '@/modules/Contests/components/CreateContestDialog' ;
33+ import { useSession } from '@/lib/auth-client' ;
34+ import PleaseLogin from './PleaseLogin' ;
3335import type {
3436 AiContestDraft ,
3537 AiContestNextResponse ,
@@ -56,13 +58,16 @@ function toChatMessages(history: ChatMessage[]) {
5658export function HomeContestChat ( ) {
5759 const router = useRouter ( ) ;
5860 const scrollRef = useRef < HTMLDivElement | null > ( null ) ;
61+ const { data : session , isPending : isSessionPending } = useSession ( ) ;
62+ const isLoggedIn = Boolean ( session ) ;
5963
6064 const [ history , setHistory ] = useState < ChatMessage [ ] > ( [ ] ) ;
6165 const [ draft , setDraft ] = useState < AiContestDraft > ( { } ) ;
6266 const [ languagePref , setLanguagePref ] = useState < 'javascript' | 'typescript' > ( 'typescript' ) ;
6367 const [ current , setCurrent ] = useState < AiContestNextResponse [ 'question' ] | null > ( null ) ;
6468 const [ input , setInput ] = useState ( '' ) ;
6569 const [ pendingSelection , setPendingSelection ] = useState < PendingSelection > ( null ) ;
70+ const [ loginOpen , setLoginOpen ] = useState ( false ) ;
6671
6772 const { mutateAsync : nextStep , isPending : isThinking } = useAiContestNext ( ) ;
6873 const { mutateAsync : previewContest , isPending : isPreviewing } = useAiContestPreview ( ) ;
@@ -129,6 +134,12 @@ export function HomeContestChat() {
129134 const submitText = async ( ) => {
130135 const text = input . trim ( ) ;
131136 if ( ! text ) return ;
137+
138+ if ( ! isSessionPending && ! isLoggedIn ) {
139+ setLoginOpen ( true ) ;
140+ return ;
141+ }
142+
132143 setInput ( '' ) ;
133144 pushUser ( text ) ;
134145
@@ -153,6 +164,11 @@ export function HomeContestChat() {
153164 return ;
154165 }
155166
167+ if ( ! isSessionPending && ! isLoggedIn ) {
168+ setLoginOpen ( true ) ;
169+ return ;
170+ }
171+
156172 const chosen = pendingSelection . values ;
157173 const labelById =
158174 current . kind === 'single' || current . kind === 'multi'
@@ -208,7 +224,7 @@ export function HomeContestChat() {
208224 }
209225 className = { cn (
210226 'w-full resize-none bg-transparent px-5 py-4 text-sm text-foreground placeholder:text-muted-foreground' ,
211- 'outline-none focus-visible:ring-0 disabled:opacity-60 border-0 pb-14 ' ,
227+ 'outline-none focus-visible:ring-0 disabled:opacity-60 border-0 pb-20 ' ,
212228 ) }
213229 />
214230
@@ -238,7 +254,6 @@ export function HomeContestChat() {
238254 >
239255 < SelectTrigger className = "h-7 w-auto rounded-full border border-border/80 bg-muted/30 px-3 py-1 text-xs text-muted-foreground" >
240256 < SelectValue />
241- < CaretDownIcon className = "ml-1 size-3.5 opacity-70" />
242257 </ SelectTrigger >
243258 < SelectContent >
244259 < SelectItem value = "javascript" > JavaScript</ SelectItem >
@@ -370,6 +385,12 @@ export function HomeContestChat() {
370385 router . push ( `/contests/${ contestId } ` ) ;
371386 } }
372387 />
388+
389+ < PleaseLogin
390+ open = { loginOpen }
391+ onClose = { ( ) => setLoginOpen ( false ) }
392+ onLogin = { ( ) => router . push ( '/login?redirect=/' ) }
393+ />
373394 </ div >
374395 ) ;
375396}
0 commit comments