Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Input & Button Wrappers. Also Beautify the Webpage. #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 107 additions & 302 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/forms": "^0.5.7",
"@types/socket.io-client": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
29 changes: 17 additions & 12 deletions frontend/src/components/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { io } from "socket.io-client";
import { Socket } from "socket.io-client/debug";
import { CreateProblem } from "./CreateProblem";
import { QuizControls } from "./QuizControls";
import QInput from "./Common/QInput";
import QButton from "./Common/QButton";

export const Admin = () => {
const [socket, setSocket] = useState<null | any>(null);
Expand All @@ -24,18 +26,21 @@ export const Admin = () => {
}, []);

if (!quizId) {
return <div>
<input type="text" onChange={(e) => {
setRoomId(e.target.value)
}} />
<br />
<button onClick={() => {
socket.emit("createQuiz", {
roomId
});
setQuizId(roomId);
}}>Create room</button>
</div>
return <div className='w-full h-full flex flex-col items-center justify-center'>
<div className='mt-20 mb-10 text-xl font-semibold'>100x Devs</div>
<div className='flex flex-col items-center gap-3'>
<QInput type="text" styleClass="w-[200px]" onChange={(e) => {
setRoomId(e.target.value)
}} />
<br />
<QButton text="Create room" onClick={() => {
socket.emit("createQuiz", {
roomId
});
setQuizId(roomId);
}} />
</div>
</div>
}
return <div>
<CreateProblem roomId={quizId} socket={socket} />
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/components/Common/QButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type ButtonProps = {
text: string;
styleClass?: string;
disabled?: boolean;
variant?: 'primary' | 'danger' | 'success' | 'dark';
onClick?: (e: any) => void;
};

function classNames(...classes: any) {
return classes.filter(Boolean).join(' ');
}

const QButton = ({
text = '',
styleClass = '',
variant = 'primary',
disabled=false,
onClick,
}: ButtonProps) => {
return (
<button
disabled={disabled}
type='button'
className={classNames(
variant === 'primary'
? 'hover:bg-indigo-500 focus:ring-indigo-500 focus:border-indigo-500 focus:shadow-[0_0_0_0.3rem_#ede9fe] bg-indigo-600'
: variant === 'danger'
? 'hover:bg-red-500 focus:ring-red-500 focus:border-red-500 focus:shadow-[0_0_0_0.3rem_#fee2e2] bg-red-600'
: variant === 'success'
? 'hover:bg-green-500 focus:ring-green-500 focus:border-green-500 focus:shadow-[0_0_0_0.3rem_#dcfce7] bg-green-600'
: 'hover:bg-gray-600 focus:ring-gray-600 focus:border-gray-600 focus:shadow-[0_0_0_0.3rem_#f3f4f6] bg-gray-700',
`inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-full shadow-sm text-white ${styleClass}`
)}
onClick={onClick}
>
{text}
</button>
);
};

export default QButton;
72 changes: 72 additions & 0 deletions frontend/src/components/Common/QInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
type InputTextProps = {
type: 'text' | 'email' | 'number' | 'radio';
name?: string;
value?: string | number | boolean;
defaultValue?: string | number;
defaultChecked?: boolean;
checked?: boolean;
placeholder?: string;
styleClass?: string;
variant?: 'primary' | 'danger' | 'success' | 'dark';
onChange?: (e: any) => void;
onClick?: (e: any) => void;
};

function classNames(...classes: any) {
return classes.filter(Boolean).join(' ');
}

const QInput = ({
type = 'text',
name = '',
value,
defaultValue = '',
defaultChecked = false,
checked = false,
placeholder = '',
styleClass = '',
variant = 'primary',
onChange,
onClick,
}: InputTextProps) => {
return type === 'radio' ? (
<input
name={name}
type='radio'
{...(checked ? { checked } : { defaultChecked: defaultChecked })}
className={classNames(
variant === 'primary'
? 'focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 focus:shadow-[0_0_0_0.3rem_#ede9fe]'
: variant === 'danger'
? 'focus:ring-red-500 h-4 w-4 text-red-600 border-gray-300 focus:shadow-[0_0_0_0.3rem_#fee2e2]'
: variant === 'success'
? 'focus:ring-success-500 h-4 w-4 text-success-600 border-gray-300 focus:shadow-[0_0_0_0.3rem_#dcfce7]'
: 'focus:ring-gray-500 h-4 w-4 text-gray-600 border-gray-300 focus:shadow-[0_0_0_0.3rem_#f3f4f6]',
`shadow-sm block w-full sm:text-sm border-gray-300 rounded-md ${styleClass}`
)}
onClick={onClick}
/>
) : (
<input
name={name}
{...(value && (typeof value === 'string' || typeof value === 'number')
? { value }
: { defaultValue: defaultValue })}
type={type}
className={classNames(
variant === 'primary'
? 'focus:ring-indigo-500 focus:border-indigo-500 focus:shadow-[0_0_0_0.3rem_#ede9fe]'
: variant === 'danger'
? 'focus:ring-red-500 focus:border-red-500 focus:shadow-[0_0_0_0.3rem_#fee2e2]'
: variant === 'success'
? 'focus:ring-green-500 focus:border-green-500 focus:shadow-[0_0_0_0.3rem_#dcfce7]'
: 'focus:ring-gray-500 focus:border-gray-500 focus:shadow-[0_0_0_0.3rem_#f3f4f6]',
`shadow-sm block w-full sm:text-sm border-gray-300 rounded-md ${styleClass}`
)}
placeholder={placeholder}
onChange={onChange}
/>
);
};

export default QInput;
27 changes: 14 additions & 13 deletions frontend/src/components/CreateProblem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from "react"
import QInput from "./Common/QInput";
import QButton from "./Common/QButton";

export const CreateProblem = ({socket, roomId}: {socket: any; roomId: string;}) => {
const [title, setTitle] = useState("");
Expand All @@ -18,23 +20,22 @@ export const CreateProblem = ({socket, roomId}: {socket: any; roomId: string;})
title: ""
}])

return <div>
Create problem
Title = <input type="text" onChange={(e) => {
return <div className='w-[80vw] mx-auto h-full flex flex-col items-center justify-center my-10'>
Create problem Title <QInput type="text" onChange={(e) => {
setTitle(e.target.value)
}}></input>
}} />
<br /><br />
Description - <input type="text" onChange={(e) => {
Description <QInput type="text" onChange={(e) => {
setDescription(e.target.value)
}}></input>
}}/>
<br />

{[0, 1, 2, 3].map(optionId => <div>
{[0, 1, 2, 3].map(optionId => <div className="w-full flex gap-4 space-y-2 items-center justify-between">
<input type="radio" checked={optionId === answer} onChange={() => {
setAnswer(optionId)
}}></input>
Option {optionId}
<input type="text" onChange={(e) => {
}} />
<p>Option {optionId}</p>
<QInput type="text" styleClass="max-w-[80%]" onChange={(e) => {
setOptions(options => options.map(x => {
if (x.id === optionId) {
return {
Expand All @@ -44,11 +45,11 @@ export const CreateProblem = ({socket, roomId}: {socket: any; roomId: string;})
}
return x;
}))
}}></input>
}} />
<br />
</div>)}

<button onClick={() => {
<QButton text="Add problem" styleClass='rounded-lg mt-10' onClick={() => {
socket.emit("createProblem", {
roomId,
problem: {
Expand All @@ -58,7 +59,7 @@ export const CreateProblem = ({socket, roomId}: {socket: any; roomId: string;})
answer,
}
});
}}>Add problem</button>
}} />

</div>
}
10 changes: 7 additions & 3 deletions frontend/src/components/Leaderboard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

export const LeaderBoard = ({leaderboard}: {leaderboard: any}) => {
return <div>
Leaderboard
return (
<div
className='text-[rgba(255_255_255_0.87)] bg-[#242424]'
>
Leaderboard
{JSON.stringify(leaderboard)}
</div>
</div>
);
}
17 changes: 9 additions & 8 deletions frontend/src/components/Quiz.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from 'react';
import QInput from './Common/QInput';
import QButton from './Common/QButton';

/**
Simple View with title and answers - $25
Expand All @@ -25,14 +27,15 @@ export function Quiz({quizData, socket, userId, problemId, roomId}: {
<div className="flex w-full justify-center">
<div className="">
<SingleQuiz
choices={quizData.options.map(x => x.title)}
choices={quizData.options.map(x => x?.title)}
title={quizData.title}
imageURL={""}
setSelected={setSubmission}
/>
<div className="flex justify-between w-full mt-4 text-white">
<button
className="py-3 px-10 bg-indigo-600 rounded-lg mx-8"
<QButton
text="Submit"
styleClass="py-3 px-10 rounded-lg mx-8"
disabled={submitted}
onClick={() => {
setSubmitted(true);
Expand All @@ -43,9 +46,7 @@ export function Quiz({quizData, socket, userId, problemId, roomId}: {
roomId,
})
}}
>
Submit
</button>
/>
</div>

</div>
Expand Down Expand Up @@ -80,11 +81,11 @@ function SingleQuiz({
key={index}
className="flex items-center w-full py-4 pl-5 m-2 ml-0 space-x-2 border-2 cursor-pointer border-white/10 rounded-xl bg-white/5"
>
<input
<QInput
type="radio"
name="option"
value={choice}
className="w-6 h-6 bg-black"
// styleClass="w-6 h-6 bg-black"
onClick={() => {
setSelected(index)
}}
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/QuizControls.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import QButton from "./Common/QButton"

export const QuizControls = ({socket, roomId}: {socket: any, roomId: string}) => {
return <div>
return <div className='w-[80vw] mx-auto h-full gap-4 flex items-center justify-center my-20'>
Quiz controls
<button onClick={() => {
<QButton text="Next problem" variant="dark" onClick={() => {
socket.emit("next", {
roomId
})
}}>Next problem</button>
}} />
</div>
}
Loading