@@ -73,6 +73,7 @@ export default function Chat(props: Readonly<HTMLAttributes<HTMLDivElement>>) {
73
73
type = { message . type }
74
74
hld = { message . hld }
75
75
prev = { arr [ index - 1 ] }
76
+ cancelled = { message . cancelled }
76
77
/>
77
78
</ ErrorBoundary >
78
79
) ) : null }
@@ -100,44 +101,80 @@ const options = {
100
101
} as const ;
101
102
102
103
export function ChallengeMessage (
103
- { message, user } : Readonly < {
104
+ { message, user, cancelled } : Readonly < {
104
105
message : string ;
105
106
user : string ;
107
+ cancelled ?: boolean ;
106
108
} > ,
107
109
) {
108
110
const { client } = useClientContext ( ) ;
109
111
const currentRoom = useClientStore ( state => state . currentRoom ) ;
110
112
113
+
111
114
function acceptChallenge ( ) {
112
115
assert ( currentRoom , 'currentRoom' ) ;
113
116
client . send ( '/accept' , currentRoom . ID ) ;
114
117
}
115
118
119
+ function cancelChallenge ( ) {
120
+ assert ( currentRoom , 'currentRoom' ) ;
121
+ client . send ( '/reject' , currentRoom . ID ) ;
122
+ }
123
+
116
124
const formatID = message . split ( '|' ) [ 0 ] ;
117
125
const format = client . formatName ( formatID ) || { gen : 9 , name : `Unknown(${ formatID } )` } ;
126
+ if ( cancelled ) {
127
+ return (
128
+ < div className = "p-2 bg-gray-100 rounded-md flex flex-col justify-center items-center" >
129
+ Challenge from < Username user = { user } bold /> was cancelled
130
+ </ div >
131
+ ) ;
132
+ }
118
133
return (
119
134
< div className = "p-2 bg-blue-pastel rounded-md flex flex-col justify-center items-center" >
120
- You received a challenge from < Username user = { user } bold />
121
- < strong >
122
- < span className = 'text-sm text-gray-125' > [Gen { format . gen } ]</ span > { format . name }
123
- </ strong >
124
- < Button
125
- onClick = { ( ) => {
126
- acceptChallenge ( ) ;
127
- } }
128
- > Accept</ Button >
135
+ { user === client . username ? (
136
+ < >
137
+ < div > Waiting for opponent to accept challenge</ div >
138
+ < strong >
139
+ < span className = 'text-sm text-gray-125' > [Gen { format . gen } ]</ span > { format . name }
140
+ </ strong >
141
+ </ >
142
+ ) :
143
+ < >
144
+ < div > You received a challenge from < Username user = { user } bold /> </ div >
145
+ < strong >
146
+ < span className = 'text-sm text-gray-125' > [Gen { format . gen } ]</ span > { format . name }
147
+ </ strong >
148
+ < div className = "flex justify-center items-center gap-4" >
149
+ < Button
150
+ variant = "secondary"
151
+ onClick = { ( ) => {
152
+ acceptChallenge ( ) ;
153
+ } }
154
+ > Accept</ Button >
155
+
156
+ < Button
157
+ variant = "secondary"
158
+ onClick = { ( ) => {
159
+ cancelChallenge ( ) ;
160
+ } }
161
+ > Decline</ Button >
162
+ </ div >
163
+ </ >
164
+ }
129
165
</ div >
130
166
) ;
131
167
}
132
168
133
169
export function MessageComponent (
134
- { message, user, type, time, hld, prev } : Readonly < {
170
+ { message, user, type, time, hld, prev, cancelled } : Readonly < {
135
171
message : string ;
136
172
user : string ;
137
173
type : MessageType ;
138
174
time ?: Date ;
139
175
hld ?: boolean | null ;
140
176
prev ?: Message ;
177
+ cancelled ?: boolean ;
141
178
} > ,
142
179
) {
143
180
if ( type === 'boxedHTML' ) {
@@ -171,7 +208,7 @@ export function MessageComponent(
171
208
) ;
172
209
}
173
210
if ( type === 'challenge' ) {
174
- return < ChallengeMessage message = { message } user = { user } /> ;
211
+ return < ChallengeMessage message = { message } user = { user } cancelled = { cancelled } /> ;
175
212
}
176
213
if ( type === 'log' ) {
177
214
return (
0 commit comments