From 3f03cdd9fc68a1a6dba86dcd922893a0b8c731a5 Mon Sep 17 00:00:00 2001 From: lekhit <82832791+lekhit@users.noreply.github.com> Date: Fri, 25 Nov 2022 10:58:11 +0530 Subject: [PATCH 1/6] Added design Diagram.drawio --- Untitled Diagram.drawio | 1 + 1 file changed, 1 insertion(+) create mode 100644 Untitled Diagram.drawio diff --git a/Untitled Diagram.drawio b/Untitled Diagram.drawio new file mode 100644 index 0000000..bce32d0 --- /dev/null +++ b/Untitled Diagram.drawio @@ -0,0 +1 @@ +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 \ No newline at end of file From 0dbe627522b4a38fa5956e8d5c1ad65cbb804916 Mon Sep 17 00:00:00 2001 From: lekhit borole Date: Fri, 25 Nov 2022 12:51:58 +0530 Subject: [PATCH 2/6] before building kahoot --- components/Login.js | 18 +++++------ components/Question.js | 29 ++++++++++++----- pages/admin.js | 30 ++++++++++++++---- pages/api/addq.js | 10 +++--- pages/api/request_question.js | 15 +++++++++ pages/api/update_question_state.js | 20 ++++++++++++ pages/api/validate_user.js | 0 pages/quiz.js | 18 +---------- prisma/dev.db | Bin 53248 -> 53248 bytes .../migration.sql | 16 ++++++++++ prisma/schema.prisma | 5 ++- 11 files changed, 114 insertions(+), 47 deletions(-) create mode 100644 pages/api/request_question.js create mode 100644 pages/api/update_question_state.js create mode 100644 pages/api/validate_user.js create mode 100644 prisma/migrations/20221125062420_changed_schme/migration.sql diff --git a/components/Login.js b/components/Login.js index 017522d..439ded3 100644 --- a/components/Login.js +++ b/components/Login.js @@ -18,6 +18,10 @@ function Login(){ function loginHandler(){ signInWithGoogle(); } + function myloginHandler(){ +login_a.setEmail(email); + + } useEffect(() => { if (loading) { console.log('Loading') @@ -33,7 +37,7 @@ login_a.setEmail(user.email);
Loading -
Login
+
Login

Login to Start test Fast!

@@ -46,20 +50,16 @@ login_a.setEmail(user.email); onChange={(e) => setPassword(e.target.value)} className='cursor-pointer outline outline-0 m-2 mx-4 bg-transparent' placeholder='Enter your password' />
-
- Remember me -
-
- -
+ +
- Loading
Continue with Google
-
Register
+
Loading diff --git a/components/Question.js b/components/Question.js index 8713572..5707e0a 100644 --- a/components/Question.js +++ b/components/Question.js @@ -11,15 +11,16 @@ function Questions(props) { const[selected,setSelected]=useState(-1); const [colors,setColors]=useState(["bg-white","bg-white","bg-white","bg-white"]); const [isOver,setOver]=useState(false); - const [button_color,setButtoncolor]=useState("green") - const [clickTime,setClicktime]=useState(15); + const [button_state,setButtonstate]=useState({color:"green",text:"submit"}) + const[question,setQuestion]=useState({count:"1" ,number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}) + function MyTimer( {expiryTimestamp} ) { const { seconds, isRunning, } = useTimer({ expiryTimestamp, onExpire:() => { setOver(true); - setButtoncolor("green") + setButtonstate({color:"sky",text:"request question"}) }}); const handleClick=async (e)=>{ @@ -33,7 +34,7 @@ function Questions(props) { } const handleSubmit=async(e)=>{ setOver(true); - + if(button_state.color==="green"){ (async () => { const rawResponse = await fetch('/api/send_answer', { method: 'POST', @@ -47,7 +48,19 @@ function Questions(props) { console.log(content); })(); - setButtoncolor('purple') + setButtonstate({color:"purple",text:"submitted"})} + if(button_state.color==="sky"){ + (async () => { + const rawResponse = await fetch('/api/request_question', { }); + const content = await rawResponse.json(); + if(content.count==="0") return; + setButtonstate({color:"green",text:"submit"}); + setQuestion(content); + resetStates(); + console.log(content); + })(); + + } } // useEffect(()=>(console.log(selected)),[selected]) @@ -63,13 +76,13 @@ function Questions(props) {
-

{props.question.question}

+

{question.question}

- {props.question.options.map((option,id)=>{ + {question.options.map((option,id)=>{ return (
{option}
) })} -
Submit
+
{button_state.text}
diff --git a/pages/admin.js b/pages/admin.js index b3fe555..5a35f04 100644 --- a/pages/admin.js +++ b/pages/admin.js @@ -30,13 +30,31 @@ const handleUpdate=(e)=>{ const emitter=(e)=>{ - console.log(e); - const time = new Date(); - time.setSeconds(time.getSeconds() + parseInt(timer)); - e.time=time - e.colors=["bg-white","bg-white","bg-white","bg-white"] - socket.emit('input-change',JSON.stringify( e)); + (async () => { + const rawResponse = await fetch('/api/update_question_state', + { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({state:""}) + } + ); + const content = await rawResponse.json(); + + console.log(content); + })(); } +const [Questions,setQuestions]=useState(); +useEffect(()=>{ + (async () => { + const rawResponse = await fetch('/api/showq' ); + const content = await rawResponse.json(); + setQuestions(content); + //console.log(content); + })(); +}) const questions=[ {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', diff --git a/pages/api/addq.js b/pages/api/addq.js index be855c8..7682bfc 100644 --- a/pages/api/addq.js +++ b/pages/api/addq.js @@ -4,17 +4,15 @@ const prisma = new PrismaClient() export default async function handler (req, res){ const {body}=req; - const user = await prisma.question.create( + const user = await prisma.questions.create( { data:{ question:body.question, number:body.number, + state:"inactive", + time:"", option:{ - create:{ - data:[ - ...body.option - ] - } + create:body.options } } }); diff --git a/pages/api/request_question.js b/pages/api/request_question.js new file mode 100644 index 0000000..68e47a2 --- /dev/null +++ b/pages/api/request_question.js @@ -0,0 +1,15 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + res.status() + const user = await prisma.question.findUnique( + { + where:{ + state:"active" + } + }); + res.status(200).json(user) +} \ No newline at end of file diff --git a/pages/api/update_question_state.js b/pages/api/update_question_state.js new file mode 100644 index 0000000..0222aa4 --- /dev/null +++ b/pages/api/update_question_state.js @@ -0,0 +1,20 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + + + const user = await prisma.question.update( + { + where:{ + number:req.number + }, + data:{ + state:body.state, + time:body.time + } + }); + res.status(200).json(user) +} \ No newline at end of file diff --git a/pages/api/validate_user.js b/pages/api/validate_user.js new file mode 100644 index 0000000..e69de29 diff --git a/pages/quiz.js b/pages/quiz.js index 49332fd..17ef2b6 100644 --- a/pages/quiz.js +++ b/pages/quiz.js @@ -7,29 +7,13 @@ function Quiz(){ const [input, setInput] = useState('') const [Question,setQuestion]=useState({number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}); useEffect(() => { - socketInitializer(); + return () => { console.log("This will be logged on unmount"); } }) -const socketInitializer = async () => { - await fetch('/api/socket'); - socket = io({"rejectUnauthorized" : false}) - - socket.on('connect', () => { - console.log('connected') - }) - socket.on('update-input', msg => { - setInput(msg) - setQuestion(JSON.parse(msg)); - }) -} -const onChangeHandler = (e) => { - setInput(e.target.value) - socket.emit('input-change', e.target.value) -} //const nickname=localStorage.getItem('nick') //const email=localStorage.getItem('email') //let Question = {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']} diff --git a/prisma/dev.db b/prisma/dev.db index 313602a7c3a970c142b2361de538d401a7c6dfac..c0c32a303abb0534ea07716d91807c1f202236be 100644 GIT binary patch delta 907 zcmb_aPe>F|7=LeOcIVGF`|TzsCd-ZzY@u7TvorhWmf&{UvcQeVMBnbb(G7PqXEqT6 z6|+lF$=oVP!i0#>nn3F0DLO=X=+MD~XDR4pmk!NJdMi5g;NyLK{J!7!d++znF0r#q z?EQ{t5g{c14(#78i#=&vTpWqE9(i#XhtNZ|RBdy|jjko$#r2*w!zaOPyQRyq3=`9rplti^oDo*tVP4q~Lf4ZD%?a$zZ*DajHxYPY8 z#uz*5eh?iTaeJkD=M3;|@i?A8>yYv|z0jbxQ@vKV50a3(Dc$-1at1@sxNtyDAeabm zhtJC!a>9#7TIHF!BLS&2CkF}$1w_rv8s!w#lQ~UICv|G5$+BNdQj(_mOgTfd)F4zh zj9i`?rbWzbCadWcBS+JzY(AaKYnDl^e9E%&YR)8nmQSTfIaA4|R9#igO2$<2trv~K z_nN9{sg!0MRWq8dsl$~qQXi$}uw5Ce(LKmpZzI;ngae=>&|wH}!xvcfqDmK>IL?;v zzeo*uL#LibB3p=qbp-EV2R30HUVG8gPoM|3kQ`*=_~7Rm0kf^RWYfur6kywN|3uRn z0e+ycx7~kC6&Tn>@Dp~u=0p;KWCcxsF|O4U{@ zVmrRciZe;7b)`ba$EnGH{-fW(8m#yO?!sk3;83e*`^NA*hg!sm>t-m(p>}K&i%eFT zLjewT;BsShlsMCj#Brz%JM=2CnGoBAl^eczhY^@P8e*9|ZqnGM^=fGu+~rSKegWvE B_#prQ delta 339 zcmZozz}&Ead4jZ{3j+fKFA#GBF(VN3P1G@FbeWhS%f61wp7RuY(Pl+~cWhjoVGO&) z)zulB^e1bw%QNy$_GIthtj(dv$XGJDnp2aJd$I(V{Ny8?>P*FalPft(fGXZ`<|*p% zu#3yfGd8K0Bqrsg29~B4mt^MW6~h_4lWV!UH%D`?WZ_}qJ;1Ln_ z;?yDmE>>nqM*jkkHB3A#%<`Kb_^TMOG4lUm;QzB(u;D5H!~kACW@b)KE|7=$moe}! z0~#@hfAX^VQJW4d;b&rC05TKU-ZJoi=YI>-@sMAZgNcPfl(RT7Erp$tg+Z9JI3*1f UWQ_bv82Fa}b Date: Fri, 25 Nov 2022 16:09:57 +0530 Subject: [PATCH 3/6] final build kahoot --- components/Acc.jsx | 74 +++++++++- components/Login.js | 29 +++- pages/admin.js | 25 ++-- pages/api/create_users.js | 13 ++ pages/api/send_reply.js | 11 ++ pages/api/set_answer.js | 21 +++ pages/api/validate_user.js | 35 +++++ pages/reply.js | 132 ++++++++++++++++++ prisma/dev.db | Bin 53248 -> 61440 bytes .../20221125073529_user/migration.sql | 22 +++ .../20221125084728_add/migration.sql | 19 +++ .../20221125095151_number_add/migration.sql | 14 ++ prisma/schema.prisma | 19 ++- 13 files changed, 390 insertions(+), 24 deletions(-) create mode 100644 pages/api/create_users.js create mode 100644 pages/api/send_reply.js create mode 100644 pages/api/set_answer.js create mode 100644 pages/reply.js create mode 100644 prisma/migrations/20221125073529_user/migration.sql create mode 100644 prisma/migrations/20221125084728_add/migration.sql create mode 100644 prisma/migrations/20221125095151_number_add/migration.sql diff --git a/components/Acc.jsx b/components/Acc.jsx index c3fd61a..c50af97 100644 --- a/components/Acc.jsx +++ b/components/Acc.jsx @@ -6,8 +6,47 @@ import AccordionDetails from '@mui/material/AccordionDetails'; import Typography from '@mui/material/Typography'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import {Button} from '@mui/material'; +import { useTimer } from 'react-timer-hook'; +import { data } from 'autoprefixer'; + + + export default function Acc(props){ + const { + seconds, + minutes, + hours, + days, + isRunning, + start, + pause, + resume, + restart, + } = useTimer(props.timestamp); + + const emitter=(e)=>{ + (async () => { + const stamp=new Date(); + const rawResponse = await fetch('/api/set_answer', + { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + + body: JSON.stringify({ans:props.question.answer,timestamp:stamp.toUTCString(),time:15}) + } + ); + const content = await rawResponse.json(); + + console.log(content); + })(); + } + + + return(
@@ -19,10 +58,39 @@ export default function Acc(props){ Question {props.question.number} - - {props.question.question} + +
+
+
+ {seconds} +
+ +
+
+ + + {props.question.question} + + + - +
+ +
+ +
{props.question.options[0]}
+
{props.question.options[1]}
+
{props.question.options[2]}
+
{props.question.options[3]}
+ + +
+
+
diff --git a/components/Login.js b/components/Login.js index 439ded3..ce499d3 100644 --- a/components/Login.js +++ b/components/Login.js @@ -11,6 +11,7 @@ import { useAuthState } from "react-firebase-hooks/auth"; function Login(){ const login_a=useAppContext() + const [login_status,setLoginstatus]=useState("Login to Start test Fast!") const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [user, loading, error] = useAuthState(auth); @@ -19,9 +20,25 @@ function Login(){ signInWithGoogle(); } function myloginHandler(){ -login_a.setEmail(email); - - } + (async () => { + const rawResponse = await fetch('/api/validate_user', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({email:email,opt:password}) + }); + const content = await rawResponse.json(); + if(content.result==="success") + {login_a.setEmail(email); + navigate.push("/nickname");} + else{ +setLoginstatus("Failed to login"); + } + console.log(content); + })(); +} useEffect(() => { if (loading) { console.log('Loading') @@ -38,7 +55,7 @@ login_a.setEmail(user.email);
Loading
Login
-

Login to Start test Fast!

+

{login_status}

- setPassword(e.target.value)} className='cursor-pointer outline outline-0 m-2 mx-4 bg-transparent' placeholder='Enter your password' />
-
+
Loading diff --git a/pages/admin.js b/pages/admin.js index 5a35f04..f583232 100644 --- a/pages/admin.js +++ b/pages/admin.js @@ -8,22 +8,12 @@ let socket; export default function Home(){ const [timer,setTimer]=useState(15); useEffect(() => { - socketInitializer(); + return () => { console.log("This will be logged on unmount"); } }) -const socketInitializer = async () => { - await fetch('/api/socket'); - socket = io() - - socket.on('connect', () => { - console.log('connected') - }) - - -} const handleUpdate=(e)=>{ setTimer(e.target.value) } @@ -46,7 +36,10 @@ const emitter=(e)=>{ console.log(content); })(); } -const [Questions,setQuestions]=useState(); +const [Questions,setQuestions]=useState([ + {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', + options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, + {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}]); useEffect(()=>{ (async () => { const rawResponse = await fetch('/api/showq' ); @@ -56,6 +49,10 @@ useEffect(()=>{ })(); }) + +const time = new Date(); + time.setSeconds(time.getSeconds() + 300); + const questions=[ {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, @@ -69,8 +66,8 @@ useEffect(()=>{ return ( - {questions.map((data,id)=>{ - return () + {Questions.map((data,id)=>{ + return () })} {timer} diff --git a/pages/api/create_users.js b/pages/api/create_users.js new file mode 100644 index 0000000..e5eb7e2 --- /dev/null +++ b/pages/api/create_users.js @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + body.data.map(async (data)=>{ + const user=await prisma.user.create({ + data:data + }); + }) +res.status(200).json({result:"success"}); +} \ No newline at end of file diff --git a/pages/api/send_reply.js b/pages/api/send_reply.js new file mode 100644 index 0000000..1409355 --- /dev/null +++ b/pages/api/send_reply.js @@ -0,0 +1,11 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const answer = await prisma.answer.findOne( + {where:{ + id:1 + }}); + +} \ No newline at end of file diff --git a/pages/api/set_answer.js b/pages/api/set_answer.js new file mode 100644 index 0000000..e91ce89 --- /dev/null +++ b/pages/api/set_answer.js @@ -0,0 +1,21 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req.body; + body.a="hello"; + console.log(body.timestamp); + const usersWithPosts = await prisma.answer.update( + + {where:{id:1}, + + data:{ + "ans":body.ans, + "time":body.time, + "timestamp":body.timestamp + } +}); +res.status(200).json(body); + +} \ No newline at end of file diff --git a/pages/api/validate_user.js b/pages/api/validate_user.js index e69de29..f33b2cd 100644 --- a/pages/api/validate_user.js +++ b/pages/api/validate_user.js @@ -0,0 +1,35 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + let user; + try { + // body of try + user = await prisma.user.findUniqueOrThrow( + { + where:{ + email:body.email + }, + + }); + console.log(body) + console.log(user); +} +catch(error) { + res.status(200).json({result:"failed"});return; +} + + + + if(user===null){ + res.status(200).json({result:"failed"}); + return; + } + else if(user.opt === body.opt) + { res.status(200).json({result:"success"}); return;} + else + {user.result="failed"; + res.status(200).json(user);} +} \ No newline at end of file diff --git a/pages/reply.js b/pages/reply.js new file mode 100644 index 0000000..4a64260 --- /dev/null +++ b/pages/reply.js @@ -0,0 +1,132 @@ +import { useEffect, useState } from "react"; + +import {useAppContext} from '../context/notes/state' + + //const time = new Date(); + //time.setSeconds(time.getSeconds() + 5); + + +function Questions(props) { + const login_a=useAppContext(); + const[selected,setSelected]=useState(-1); + const [colors,setColors]=useState(["bg-green","bg-red","bg-purple","bg-yellow"]); + + const [button_state,setButtonstate]=useState({color:"green",text:"submit"}) + + + const handleSubmit=async(e)=>{ + + if(button_state.color==="green"){ + (async () => { + const rawResponse = await fetch('/api/send_answer', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({number:props.question.number,select:selected,time:seconds, user:login_a.nick ,email:login_a.email}) + }); + const content = await rawResponse.json(); + + console.log(content); + })(); + setButtonstate({color:"purple",text:"submitted! Answer again "}) + } + if(button_state.color==="purple"){ + setButtonstate({color:"green",text:"submit"}); + (async () => { + const rawResponse = await fetch('/api/request_question', { }); + const content = await rawResponse.json(); + if(content.count==="0") return; + + setQuestion(content); + resetStates(); + console.log(content); + }); + + } + } + + // useEffect(()=>(console.log(selected)),[selected]) + + + const handleClick=async (e)=>{ + + setColors((colors)=>{if(selected===-1) return colors; colors[selected]="bg-white";colors[e.target.id]="bg-amber-300"; + return colors; + }) + setSelected(e.target.id); + + //console.log(e.target.sid,colors) + } + + + const resetStates=()=>{ + setColors(["bg-white","bg-white","bg-white","bg-white"]) + setSelected(-1) + + } + + useEffect(()=>{ + console.log("question updated") + resetStates(); + },[props.question]); + + return ( +
+ +
+
+
+
+
+ + +
+
+
+ +
+ +
a
+
b
+
c
+
d
+ + +
{button_state.text}
+
+
+
+
+) + } +export default Questions; + + +// useEffect(()=>{ +// if(isOver){ +// (async () => { +// const rawResponse = await fetch('/api/send_answer', { +// method: 'POST', +// headers: { +// 'Accept': 'application/json', +// 'Content-Type': 'application/json' +// }, +// body: JSON.stringify({number:props.question.number,user:props.user,selection:selected}) +// }); +// const content = await rawResponse.json(); +// // const answer=await content.answer; +// // ( (colors)=>{ +// // if(selected!=-1) +// // colors[selected]="bg-red-400" +// // colors[answer]="bg-green-400" +// // setColors(colors) +// // })(colors); + + +// //console.log(content); +// })(colors); + +// } +// },[isOver,colors,selected,props.question.number,props.user]) diff --git a/prisma/dev.db b/prisma/dev.db index c0c32a303abb0534ea07716d91807c1f202236be..dd0b0b78475c23d62e4b22186bf207bac236b872 100644 GIT binary patch delta 2114 zcmbtUU1%It6rRa!W@mPH<~H4Imt~t~vVv(!b~|_e2O&*t*HTTBHtb4mDCwQQW}Dq4 z?vITiY_{!-f?(L9pbttB1dD<$TKXmk#UDz2vG`!M7R921eQSj(-kD8ep?xSg>@1h> zeD|F1-0#d?eTQ1TLA{plvk8I#_}zGRtc}VeHj$fti3_h0eCQg%T?3uimFQQ|V@x)5 zjs1f?MR#H^^!^%I3Sa(cZ7LKw&4X}qaF9H+&~_tt#z%z=TCAONs~Mq?KT;TJ9Y}_}aWle! zsX~5#enyy@E(lY_$w^^f{;7%LWI=%HeY{#7RhGNeBO|TZcsQ9zkY`ds`C`qj`Y+$s zxdm!zx$c(2?9<78@1I ztJuOFS+=ysCqZ?D7#$WZ(B*vlbsm$=w@jQgplpNUopu*~1!4{@Jy!?8DF z80ZXbIT~%Y;!LF2;(GTGL@%pYhNI}7owXcfXBFg{S;O?Ktf?rP?1%<3E!$HiC~1bJ zY0yKuXhX#_bZFV4iy$YgO)9<)V?Jo};i+@F#tNf1hE zQ#4hmZaRt_Cy3u_#lnFs=*v=ZUI;BOD@)MJDvIi5ktnNK$3ReWp^QXRvs~RVEYI*n zMR5%onih05-SjkwY}c`M)es#8DtL#bB3(tcqBzjho0g=hwuc$y*$?i{f48AaG!$Jj z<^nw!zuMyHK#v^gk)b6Uij{RV$IL38?q(70F{{{;Y~jMVOHcL`=!%wsPt4YJ8KbHU zH3_+{V`wI{blkP&K|@zn#c(9q!Do--lu`=B6H9RwZ+;fj_Sx@NH*! z;Cc_w@RtanfMfh6{w9caV#0fTb0<|KAH_(%PlgMmYm&^s* zQMuem(7v)}syj1&hNX&Io3AH(eR7(tD*o7XbJR+UCz9JjL2|MhG~Er9Q8}5Qd>oHi z&^N|Uy7hTnC>dq;wM1i07fTm1#B L9pXY1#j^hbu=p=E delta 649 zcmYL`O=uHA6vt<>AKA@j_a&AkhICD$XjIzNHUSTU#)BtQTE$jDim+3wHFaltl~*UyfsH>q{e|^=KbFPJ>JLS2DkW-yOoNU z5kl(L#q=GxJyh6TM)`@WsyvMpX&9;RAW+lMH_=PVD`iF+j+~W$%H41}$j0uA8F?CO ziChjZPkE$jnN72M{zS)gy+*6)GQJxg3e7Er;@e%2S<3&fp`O9Dz#@mQ&r zuQ|lFJEIV$NSB;iX)a$QmeoOVQ9y|#b{TM6w&~Wr0fCBA*ePzYCaHUgZ9GecodSb2 znMJHboTDs(oiWBPnqHlZLx`r+4`GL)d0O(pK`fws2CkBN=YPG-suHVVtMC!=u!`U% ze22HN3eSRgWd+VqtcqM3_m>rtFsI`w*K}eLflK0vHrt^Dn@E%UA|=G7@X@B*H653u t Date: Fri, 25 Nov 2022 16:51:39 +0530 Subject: [PATCH 4/6] updated question --- pages/admin.js | 66 ++++++++++++++++++++++++++++++------------------- pages/reply.js | 2 +- prisma/dev.db | Bin 61440 -> 61440 bytes 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/pages/admin.js b/pages/admin.js index f583232..05893d0 100644 --- a/pages/admin.js +++ b/pages/admin.js @@ -2,9 +2,32 @@ import Accord from '../components/Accordination'; import {Paper,Input} from '@mui/material'; import Acc from '../components/Acc'; import { useEffect,useState } from 'react'; -import io from 'socket.io-client' -import { Timer } from '@mui/icons-material'; -let socket; + +const data=[ + {number:'1',question:"which is the world's biggest real estate company?",options:["L and T","McDonalds","Reliance","DLF"],ans:"McDonalds"}, + {number:'2',question:"which Indian movie has the highest worldwide collection?",options:["Dangal","3 Idiots","Bajrangi Bhaijaan","PK"],ans:"Dangal"}, + {number:'3',question:"Who was the first female president of India?",options:["Sushma Swaraj","Droupadi Murmu","Pratibha Patil","Sarojini Naidu"],ans:"Pratibha Patil"}, + {number:'4',question:"who is the golden investor of 2k22 hillfair?",options:["Unacademy","SJVNL","Dayal Sweets","Byjus"],ans:"Unacademy"}, + {number:'5',question:"'Nabha Sparsham Deeptam' is the motto of which military unit of india? ",options:["Coast Guard","Air Force","Air Force","Navy"],ans:"Air Force"}, + {number:'6',question:"what is the full form of GDP?",options:["Growth Domestic Price","Growth Daily Product","Gross Daily Product","Gross Domestic Product"],ans:"Gross Domestic Product"}, + {number:'7',question:"When is the ‘National Girl Child Day’ celebrated annually in India?",options:["21 March","14 November","24 January","5 December"],ans:"24 January"}, + {number:'8',question:"Who has been appointed new Prime Minister of United Kingdom?",options:["Boris Johnson","Rishi Sunak","Angela Merkel","Byjus"],ans:"Rishi Sunak"}, + {number:'9',question:"which company has the tag line of 'zindagi ke sath bhi zindagi ke baad bhi'?",options:["LIC","Bajaj Finance","SBI","HDFC"],ans:"LIC"}, + {number:'10',question:"What was the theme of Hill'fair 2022? ",options:["Mirage-Ocean of mystique","Ocean-Mirage of Pharoah","Pharaoh-Ocean of mystique","Mirage-oasis of mystique"],ans:"Mirage-oasis of mystique"}, + {number:'11',question:"The name 'PARAM' is an Indian Technology, what is it ?",options:["Supercomputer","Submarine","Rocket","Helicopter"],ans:"Supercomputer"}, + {number:'12',question:"which of these colours are not present in olympic rings?",options:["Red","Green","Blue","orange"],ans:"orange"}, + {number:'13',question:"Which stock market crash was biggest in the history?",options:["1994","1992","1991","1983"],ans:"1992"}, + {number:'14',question:"What is the full form of LCD?",options:["liquid crystal display","liquid crystal diode","lithium crystal diode","large crystal device"],ans:"liquid crystal display"}, + {number:'15',question:"Company with biggest market capitalization in India?",options:["Tata","Adani","Reliance","Unilever"],ans:"Reliance"}, + {number:'16',question:"When was E-Cell NIT Hamirpur formed? ",options:["2017","2018","2019","2008"],ans:"2018"}, + {number:'17',question:"which is the oldest stock exchange in asia? ",options:["bse","nse","cse(colombo)","cse(bejing)"],ans:"Supercomputer"}, + {number:'18',question:"What was the most-watched series on Netflix in 2019?",options:["Squid Games","stranger things","Never Have I ever","Breaking Bad"],ans:"stranger things"}, + {number:'19',question:"which brand of tata group is indulged in jewellery related business ?",options:["kalyan ","PC Jewelers ","tanishq","BlueStone"],ans:"tanishq"}, + {number:'20',question:"Latest Indian Unicorn>?",options:["Molbio Diagnostics","OneCard","Shiprocket","Helicopter"],ans:"Molbio Diagnostics"}, + + +] + export default function Home(){ const [timer,setTimer]=useState(15); useEffect(() => { @@ -18,7 +41,10 @@ const handleUpdate=(e)=>{ setTimer(e.target.value) } - +const [Questions,setQuestions]=useState([ + {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', + options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, + {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}]); const emitter=(e)=>{ (async () => { const rawResponse = await fetch('/api/update_question_state', @@ -36,37 +62,25 @@ const emitter=(e)=>{ console.log(content); })(); } -const [Questions,setQuestions]=useState([ - {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', - options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, - {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}]); -useEffect(()=>{ - (async () => { - const rawResponse = await fetch('/api/showq' ); - const content = await rawResponse.json(); - setQuestions(content); - //console.log(content); - })(); -}) +// useEffect(()=>{ +// (async () => { +// const rawResponse = await fetch('/api/showq' ); +// const content = await rawResponse.json(); +// setQuestions(content); +// //console.log(content); +// })(); +// }) const time = new Date(); time.setSeconds(time.getSeconds() + 300); - const questions=[ - {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', - options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, - - - - {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, - {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']} - ] + const questions=data return ( - {Questions.map((data,id)=>{ + {questions.map((data,id)=>{ return () })} {timer} diff --git a/pages/reply.js b/pages/reply.js index 4a64260..9029357 100644 --- a/pages/reply.js +++ b/pages/reply.js @@ -86,7 +86,7 @@ function Questions(props) {
-
+
a
b
diff --git a/prisma/dev.db b/prisma/dev.db index dd0b0b78475c23d62e4b22186bf207bac236b872..765f79d37251a5e2147cfa1fd0a3f5a606d5a960 100644 GIT binary patch delta 135 zcmZp8z})bFd4e=!%0wAw#*~c-ss4=2n~(Y18E`T4e`MhQ$p44`+h)Or$NaJ^%p8o& ztjvszOiawooSa+?3=GWtwG8~r_-pxFH!C{i^K-B>3o~YCWHC=}onOzx%pbwPKZ`#X lNO1zCJ@`e1nb{dQgk|{|fNC=H5|c|Z%TmoZ=dPdZ004fsBFF#$ delta 95 zcmZp8z})bFd4e=!@ Date: Fri, 25 Nov 2022 17:04:27 +0530 Subject: [PATCH 5/6] fixed reply --- pages/nickname.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/nickname.js b/pages/nickname.js index 22cc980..6ee28a2 100644 --- a/pages/nickname.js +++ b/pages/nickname.js @@ -30,7 +30,7 @@ function Nickname(){ console.log(content); })(); console.log(login_a.email); - navigator.push('/quiz'); + navigator.push('/reply'); } function changeHandler(event){ From b9cd48c02ccf76cabae8599e06d3c676448ce152 Mon Sep 17 00:00:00 2001 From: lekhit borole Date: Fri, 25 Nov 2022 17:26:56 +0530 Subject: [PATCH 6/6] updated font --- components/Acc.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Acc.jsx b/components/Acc.jsx index c50af97..3ba2826 100644 --- a/components/Acc.jsx +++ b/components/Acc.jsx @@ -55,7 +55,7 @@ export default function Acc(props){ aria-controls="panel1a-content" id="panel1a-header" > - Question {props.question.number} + Question {props.question.number} @@ -68,7 +68,7 @@ export default function Acc(props){
- + {props.question.question}