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) {