1- import { useState } from "react"
2- import { useNavigate } from "react-router-dom"
3- import { Settings } from "lucide-react"
1+ import { useState } from "react"
2+ import { useNavigate } from "react-router-dom"
3+ import { Settings } from "lucide-react"
44import QuizSelectModal from "../../../pages/game/QuizSelectModal" ;
55import { useRecoilValue } from "recoil" ;
66import { stompSendMessageAtom } from "../../../state/atoms" ;
77
8- function GameSettings ( { roomId } ) {
9- const [ timePerQuestion , setTimePerQuestion ] = useState ( "30초" ) ;
10- const [ questionCount , setQuestionCount ] = useState ( 25 ) ;
8+ function GameSettings ( { roomId, gameSetting , allReady } ) {
9+ const [ timePerQuestion , setTimePerQuestion ] = useState ( 60 ) ;
10+ const [ questionCount , setQuestionCount ] = useState ( gameSetting ?. quiz . numberOfQuestion ) ;
1111 const [ quizSelectModalOpen , setQuizSelectModalOpen ] = useState ( false ) ;
12- const [ selectedQuiz , setSelectedQuiz ] = useState ( null ) ;
1312 const navigate = useNavigate ( ) ;
1413 const sendMessage = useRecoilValue ( stompSendMessageAtom ) ;
1514
@@ -19,9 +18,36 @@ function GameSettings({ roomId }) {
1918 }
2019
2120 const handleQuizSelect = ( quiz ) => {
22- setSelectedQuiz ( quiz ) ;
21+ const quizChangeMessage = {
22+ "message" : {
23+ "quizId" : quiz . quizId ,
24+ }
25+ }
26+ sendMessage ( `/room/quiz/${ roomId } ` , quizChangeMessage ) ;
2327 }
2428
29+ const handleTimePerQuestionChange = ( e ) => {
30+ console . log ( 'handleTimePerQuestionChange: ' , e . target . value )
31+ setTimePerQuestion ( e . target . value ) ;
32+ const timePerQuestionMessage = {
33+ "message" : {
34+ "timeLimit" : e . target . value
35+ }
36+ }
37+ sendMessage ( `/room/time-limit/${ roomId } ` , timePerQuestionMessage ) ;
38+ } ;
39+
40+ const handleQuestionCountChange = ( e ) => {
41+ console . log ( 'handleQuestionCountChange: ' , e . target . value )
42+ setQuestionCount ( e . target . value ) ;
43+ const questionCountMessage = {
44+ "message" : {
45+ "round" : e . target . value
46+ }
47+ }
48+ sendMessage ( `/room/round/${ roomId } ` , questionCountMessage ) ;
49+ } ;
50+
2551 return (
2652 < >
2753 < div className = "bg-white rounded-2xl shadow-lg p-6 mb-6" >
@@ -44,38 +70,47 @@ function GameSettings({ roomId }) {
4470 < label className = "block text-sm font-medium text-gray-700 mb-2" > 제한 시간</ label >
4571 < select
4672 value = { timePerQuestion }
47- onChange = { ( e ) => setTimePerQuestion ( e . target . value ) }
73+ onChange = { handleTimePerQuestionChange }
4874 className = "w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-500 appearance-none bg-white bg-no-repeat bg-right pr-8"
4975 style = { {
5076 backgroundImage : `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' strokeLinecap='round' strokeLinejoin='round' strokeWidth='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e")` ,
5177 backgroundPosition : "right 0.5rem center" ,
5278 backgroundSize : "1.5em 1.5em" ,
5379 } }
5480 >
55- < option > 15초</ option >
56- < option > 30초</ option >
57- < option > 45초</ option >
58- < option > 60초</ option >
81+ < option value = { 15 } > 15초</ option >
82+ < option value = { 30 } > 30초</ option >
83+ < option value = { 45 } > 45초</ option >
84+ < option value = { 60 } > 60초</ option >
5985 </ select >
6086 </ div >
6187 < div >
62- < label className = "block text-sm font-medium text-gray-700 mb-2" > 문제 수</ label >
63- < input
64- type = "number"
65- min = "10"
66- max = "80"
88+ < label className = "block text-sm font-medium text-gray-700 mb-2" > 라운드</ label >
89+ < select
6790 value = { questionCount }
68- onChange = { ( e ) => setQuestionCount ( Number . parseInt ( e . target . value ) || 30 ) }
69- className = "w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-500 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
70- placeholder = "문제 수를 입력하세요 (10-80)"
71- />
91+ onChange = { handleQuestionCountChange }
92+ className = "w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-500 appearance-none bg-white bg-no-repeat bg-right pr-8"
93+ style = { {
94+ backgroundImage : `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' strokeLinecap='round' strokeLinejoin='round' strokeWidth='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e")` ,
95+ backgroundPosition : "right 0.5rem center" ,
96+ backgroundSize : "1.5em 1.5em" ,
97+ } }
98+ >
99+ { Array . from ( { length : gameSetting ?. quiz . numberOfQuestion - 9 } , ( _ , i ) => {
100+ const value = i + 10 ;
101+ return (
102+ < option key = { value } value = { value } >
103+ { value }
104+ </ option >
105+ ) ;
106+ } ) }
107+ </ select >
72108 </ div >
73109 </ div >
74110 < div className = "pt-4" >
75- < button
76- onClick = { handleStartGame }
77- disabled = { ! selectedQuiz }
78- className = "w-full px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors font-semibold disabled:bg-gray-400 disabled:cursor-not-allowed"
111+ < button onClick = { handleStartGame }
112+ disabled = { ! allReady }
113+ className = "w-full px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors font-semibold disabled:bg-gray-400 disabled:cursor-not-allowed"
79114 >
80115 게임 시작
81116 </ button >
0 commit comments