Skip to content

Commit 1855061

Browse files
committed
PEER-232: Add styles for match form
Signed-off-by: SeeuSim <[email protected]>
1 parent 97d221a commit 1855061

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

frontend/src/routes/match/main.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import { observer } from 'mobx-react';
22
import { Suspense } from 'react';
33
import { Await, useLoaderData } from 'react-router-dom';
44

5+
import { ScrollArea } from '@/components/ui/scroll-area';
6+
57
import { MatchForm } from './match-form';
68

79
export const Match = observer(() => {
810
const { topics } = useLoaderData() as { topics: Promise<Array<string>> };
911

1012
return (
11-
<div className='m-auto flex grow items-center justify-center'>
13+
<ScrollArea className='flex size-full py-8'>
1214
<Suspense fallback={<div>Loading topics...</div>}>
1315
<Await resolve={topics}>
14-
{(resolvedTopics) => (
15-
<div className='flex size-full items-center justify-center'>
16-
<MatchForm topics={resolvedTopics.topics} />
17-
</div>
18-
)}
16+
{(resolvedTopics) => <MatchForm topics={resolvedTopics.topics} />}
1917
</Await>
2018
</Suspense>
21-
</div>
19+
</ScrollArea>
2220
);
2321
});

frontend/src/routes/match/match-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export const MatchForm = ({ topics }: MatchFormProps) => {
4040
}, [socketPort]);
4141

4242
return (
43-
<div className='flex h-full items-center justify-center'>
43+
<div className='flex size-full items-center justify-center'>
4444
<Card
4545
className={cn(
4646
'text-card-foreground bg-primary-foreground rounded-xl border border-border shadow',
47-
'flex w-full max-w-[400px] md:size-full md:max-h-[600px]',
47+
'flex max-w-[400px] size-full md:max-h-[600px]',
4848
'flex-col items-center justify-center'
4949
)}
5050
>

frontend/src/routes/match/waiting-room/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const WaitingRoomModal: FC<IMatchingModalProps> = ({
2424
}) => {
2525
return (
2626
<Dialog modal={true} open={isModalOpen}>
27-
<DialogContent className='max-h-[500px] [&>button]:hidden'>
27+
<DialogContent className='border-border max-h-[500px] [&>button]:hidden'>
2828
<DialogHeader>
2929
<VisuallyHidden>
3030
<DialogTitle>Waiting Room</DialogTitle>

frontend/src/routes/match/waiting-room/waiting.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ type IWaitingRoomProps = {
1717

1818
type IWaitingRoomUIState = {
1919
connected: boolean;
20-
cancel: boolean;
20+
isCancelling: boolean;
21+
canCancel: boolean;
2122
uiState: (typeof UI_STATUS)[keyof typeof UI_STATUS];
2223
};
2324

2425
export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) => {
2526
const navigate = useNavigate();
2627
const { values } = useMatchRequest();
2728

28-
const [{ connected, cancel, uiState }, setUIState] = useState<IWaitingRoomUIState>({
29-
connected: false,
30-
cancel: false,
31-
uiState: UI_STATUS.WAITING_STATUS,
32-
});
29+
const [{ connected, isCancelling, canCancel, uiState }, setUIState] =
30+
useState<IWaitingRoomUIState>({
31+
connected: false,
32+
isCancelling: false,
33+
canCancel: false,
34+
uiState: UI_STATUS.WAITING_STATUS,
35+
});
3336

3437
const countdownRef = useRef(31);
3538
const timerRef = useRef<number | null>(null);
@@ -45,11 +48,12 @@ export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) =
4548
};
4649

4750
useEffect(() => {
48-
if (cancel) {
51+
if (isCancelling) {
4952
clearInterval(timerRef.current!);
5053
setUIState((state) => ({
5154
...state,
52-
cancel: true,
55+
isCancelling: true,
56+
canCancel: false,
5357
}));
5458
} else if (connected) {
5559
timerRef.current = window.setInterval(() => {
@@ -68,7 +72,7 @@ export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) =
6872
}
6973

7074
return () => clearInterval(timerRef.current!);
71-
}, [connected, cancel]);
75+
}, [connected, isCancelling]);
7276

7377
useEffect(() => {
7478
if (!socketPort) {
@@ -101,10 +105,12 @@ export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) =
101105

102106
socket.on(MATCHING_EVENT.MATCHING, () => {
103107
console.log('Matching in progress');
108+
setUIState((prev) => ({ ...prev, canCancel: false }));
104109
});
105110

106111
socket.on(MATCHING_EVENT.PENDING, () => {
107112
console.log('Waiting in pool');
113+
setUIState((prev) => ({ ...prev, canCancel: true }));
108114
});
109115

110116
socket.on(MATCHING_EVENT.SUCCESS, (data) => {
@@ -148,7 +154,7 @@ export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) =
148154
try {
149155
setUIState((prevState) => ({
150156
...prevState,
151-
cancel: true,
157+
isCancelling: true,
152158
uiState: UI_STATUS.CANCELLING_STATUS,
153159
}));
154160
countdownRef.current = 0;
@@ -166,8 +172,13 @@ export const WaitingRoom = ({ socketPort, setIsModalOpen }: IWaitingRoomProps) =
166172
{uiState.icon}
167173
<p className='mt-4 whitespace-pre-wrap text-lg'>{uiState.description}</p>
168174
</div>
169-
{countdownRef.current > 0 || cancel ? (
170-
<Button className='mt-5' variant='destructive' onClick={handleCancel} disabled={cancel}>
175+
{countdownRef.current > 0 || isCancelling ? (
176+
<Button
177+
className='mt-5'
178+
variant='destructive'
179+
onClick={handleCancel}
180+
disabled={isCancelling || !canCancel}
181+
>
171182
Cancel
172183
</Button>
173184
) : (

0 commit comments

Comments
 (0)