4
4
codeLangAtom ,
5
5
codeMirrorValueAtom ,
6
6
innkeeperWriteAtom ,
7
+ isMatchedAtom ,
7
8
isQuestionModalOpenAtom ,
8
9
questionIdAtom ,
9
10
resultAtom ,
@@ -13,6 +14,7 @@ import { atom, useAtomValue, useSetAtom } from "jotai";
13
14
import Button from "../button/Button" ;
14
15
import { message } from "antd" ;
15
16
import UserStateBadge from "./UserStatusBadge" ;
17
+ import { ExclamationCircleFilled } from "@ant-design/icons" ;
16
18
17
19
interface StatusBarProps {
18
20
exitMethod : ( ) => void ;
@@ -34,6 +36,7 @@ const triggerExitRoomRequestAtom = atom(null, (get, set) => {
34
36
} ) ;
35
37
36
38
const StatusBar = ( { exitMethod } : StatusBarProps ) => {
39
+ const isMatched = useAtomValue ( isMatchedAtom ) ;
37
40
const code = useAtomValue ( codeMirrorValueAtom ) ;
38
41
const userStates = useAtomValue ( userStatesAtom ) ;
39
42
const questionId = useAtomValue ( questionIdAtom ) ;
@@ -42,6 +45,23 @@ const StatusBar = ({ exitMethod }: StatusBarProps) => {
42
45
const setQuestionModalOpen = useSetAtom ( isQuestionModalOpenAtom ) ;
43
46
const [ api , contextHolder ] = message . useMessage ( ) ;
44
47
48
+ const UiElementOnClose = ( ) => {
49
+ return (
50
+ < div className = "flex items-center gap-2" >
51
+ < div className = "mt-1 flex gap-2 rounded-full bg-error px-2 py-1 font-bold text-white" >
52
+ < ExclamationCircleFilled />
53
+ Your room has been closed.
54
+ </ div >
55
+ < Button
56
+ className = "btn-accent btn-sm"
57
+ onClick = { ( ) => window . location . reload ( ) }
58
+ >
59
+ Back to Matching
60
+ </ Button >
61
+ </ div >
62
+ ) ;
63
+ } ;
64
+
45
65
return (
46
66
< footer className = "fixed bottom-0 left-0 flex w-[100svw] items-center justify-between border-black bg-primary px-4 py-2 shadow-sm lg:static lg:w-full lg:px-12" >
47
67
{ contextHolder }
@@ -51,42 +71,45 @@ const StatusBar = ({ exitMethod }: StatusBarProps) => {
51
71
< UserStateBadge userState = { userState } key = { userState . userId } />
52
72
) ) }
53
73
</ div >
54
- < div className = "flex items-center gap-4" >
55
- < Button
56
- className = "btn-outline btn-sm"
57
- onClick = { ( ) =>
58
- questionId &&
59
- completeQuestion ( questionId ) . then ( ( res ) =>
60
- res . statusMessage . type . toLowerCase ( ) === "success"
61
- ? api . success ( {
62
- type : "success" ,
63
- content : "Successfully completed question!" ,
64
- } )
65
- : api . error ( {
66
- type : "error" ,
67
- content : "Failure completing question" ,
68
- } ) ,
69
- )
70
- }
71
- children = { < span > Mark As Complete</ span > }
72
- disabled = { ! questionId }
73
- />
74
- < Button
75
- className = "btn-success btn-sm"
76
- onClick = { ( ) => setQuestionModalOpen ( true ) }
77
- children = { < span > Select Question</ span > }
78
- />
79
- < Button
80
- className = "btn-sm"
81
- onClick = { callExecution }
82
- children = { < span > Execute</ span > }
83
- />
84
- < Button
85
- className = "btn-error btn-sm"
86
- onClick = { callExitRoom }
87
- children = { < span > Exit</ span > }
88
- />
89
- </ div >
74
+ { isMatched === "MATCHED" && (
75
+ < div className = "flex items-center gap-4" >
76
+ < Button
77
+ className = "btn-outline btn-sm"
78
+ onClick = { ( ) =>
79
+ questionId &&
80
+ completeQuestion ( questionId ) . then ( ( res ) =>
81
+ res . statusMessage . type . toLowerCase ( ) === "success"
82
+ ? api . success ( {
83
+ type : "success" ,
84
+ content : "Successfully completed question!" ,
85
+ } )
86
+ : api . error ( {
87
+ type : "error" ,
88
+ content : "Failure completing question" ,
89
+ } ) ,
90
+ )
91
+ }
92
+ children = { < span > Mark As Complete</ span > }
93
+ disabled = { ! questionId }
94
+ />
95
+ < Button
96
+ className = "btn-success btn-sm"
97
+ onClick = { ( ) => setQuestionModalOpen ( true ) }
98
+ children = { < span > Select Question</ span > }
99
+ />
100
+ < Button
101
+ className = "btn-sm"
102
+ onClick = { callExecution }
103
+ children = { < span > Execute</ span > }
104
+ />
105
+ < Button
106
+ className = "btn-error btn-sm"
107
+ onClick = { callExitRoom }
108
+ children = { < span > Exit</ span > }
109
+ />
110
+ </ div >
111
+ ) }
112
+ { isMatched !== "MATCHED" && < UiElementOnClose /> }
90
113
</ footer >
91
114
) ;
92
115
} ;
0 commit comments