Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
02a5c5b
Change hover color to be distinct from selection
embeddedt Oct 7, 2022
a805ba8
Explicitly state when no option is selected on voting page
embeddedt Oct 7, 2022
60557a2
Send a browser notification when a new question starts
embeddedt Oct 7, 2022
8954af6
Fix a typo in the README
embeddedt Oct 7, 2022
b18d2db
Revert hover color and choose a new selected color
embeddedt Oct 9, 2022
8d177c1
Refactor notification permission state
embeddedt Oct 9, 2022
e10b80f
Refactor page focus/notification system
embeddedt Oct 9, 2022
47b2e0a
Added MUI
ggggg Oct 10, 2022
fbba2ba
Added loading wheel (see #73)
ggggg Oct 10, 2022
2a094e7
Removed debug code
ggggg Oct 10, 2022
4c4321e
Removed MUI
ggggg Oct 12, 2022
073b4a9
Removed MUI imports
ggggg Oct 12, 2022
7cabb3a
Uses tailwind's error dialog instead of javascripts's alert
ggggg Oct 22, 2022
19bfdca
Centered spinner
ggggg Oct 23, 2022
f78c263
Update spinner
ggggg Oct 23, 2022
ecb4c4f
Linting and Formatting for the backend (#71)
ggggg Oct 25, 2022
7f07086
Merge branch 'main' into qol-improvements
logonoff Oct 25, 2022
2fa05ac
Removed use of any. (#70)
ggggg Oct 31, 2022
36aadac
Added missing import statement (#80)
ggggg Nov 4, 2022
0055134
Changed char set (see #77) (#83)
ggggg Nov 9, 2022
3facdf5
moved mongo, redis setup to functions (#84)
shubhbapna Dec 23, 2022
7d91038
Merge pull request #74 from ggggg/UX-vote-loading
huonggiangbui Dec 28, 2022
7d1a8ef
Make sure polling results are only sent to instructors (#76)
embeddedt Jan 6, 2023
1ebc5a2
Minor changes
hiimchrislim Jan 11, 2023
4cb1fdb
Merge gdsc open source branch
hiimchrislim Jan 11, 2023
e3b9734
Revert some changed files
hiimchrislim Jan 11, 2023
3054f73
Merge pull request #56 from embeddedt/qol-improvements
hiimchrislim Jan 11, 2023
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: cd client && yarn --frozen-lockfile && yarn lint
lint_server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: cd server && yarn --frozen-lockfile && yarn lint
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

cd client
npx lint-staged

cd ../server
yarn lint
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Note: Only the core files & directories are listed below
| |── routes
| | |── pollRoute.ts
| | └── userRoutes.ts
| |── types
| | └── pollController.types.ts
| |── redis.ts # Redis related configurations to setup the professor list
| |── server.ts
| └── socket.ts
Expand Down Expand Up @@ -205,7 +207,7 @@ utorid3
2. Setting up the server `.env` file (Placed in the root of your `server` folder)

```
PPORT=3001
PORT=3001
MONGODB_URL="mongodb://localhost:27018/quiz"
FRONTEND_URL="http://localhost:3000"
REDIS_URL="redis://default:password@localhost:6379"
Expand Down
93 changes: 93 additions & 0 deletions client/src/components/ErrorAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from "react";

interface ErrorAlertProps {
title: string;
text?: string;
onClose: () => void;
enabled: boolean;
buttonText?: string;
}

export const ErrorAlert = ({
title,
text,
onClose,
enabled,
buttonText,
}: ErrorAlertProps) => {
return (
<div
className={`relative z-10 ${enabled ? "" : "hidden"}`}
aria-labelledby="modal-title"
role="dialog"
aria-modal={enabled}
>
{/* Background backdrop, show/hide based on modal state. */}

{/* Entering: "ease-out duration-300" */}
{/* From: "opacity-0" */}
{/* To: "opacity-100" */}
{/* Leaving: "ease-in duration-200" */}
{/* From: "opacity-100" */}
{/* To: "opacity-0" */}
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div>

<div className="fixed inset-0 z-10 overflow-y-auto">
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
{/* Modal panel, show/hide based on modal state. */}

{/* Entering: "ease-out duration-300" */}
{/* From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" */}
{/* To: "opacity-100 translate-y-0 sm:scale-100" */}
{/* Leaving: "ease-in duration-200" */}
{/* From: "opacity-100 translate-y-0 sm:scale-100" */}
{/* To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" */}
<div className="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg">
<div className="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div className="sm:flex sm:items-start">
<div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
{/* Heroicon name: outline/exclamation-triangle */}
<svg
className="h-6 w-6 text-red-600"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
aria-hidden="true"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 10.5v3.75m-9.303 3.376C1.83 19.126 2.914 21 4.645 21h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 4.88c-.866-1.501-3.032-1.501-3.898 0L2.697 17.626zM12 17.25h.007v.008H12v-.008z"
/>
</svg>
</div>
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3
className="text-lg font-medium leading-6 text-gray-900"
id="modal-title"
>
{title}
</h3>
<div className="mt-2">
<p className="text-sm text-gray-500">{text}</p>
</div>
</div>
</div>
</div>
<div className="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6">
<button
type="button"
className="inline-flex w-full justify-center rounded-md border border-transparent bg-red-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm"
onClick={onClose}
>
{buttonText ?? "Close"}
</button>
</div>
</div>
</div>
</div>
</div>
);
};
8 changes: 3 additions & 5 deletions client/src/components/PollOptionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ export const PollOptionButton = ({
disabled={disabled}
onClick={onClick}
className={`m-2 py-2 px-40 inline-block ${
selected ? "bg-hover" : "bg-primary"
} ${
disabled
? "cursor-not-allowed opacity-50"
: "hover:bg-hover cursor-pointer"
selected ? "bg-selected" : "bg-primary"
} ${disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"} ${
!selected && !disabled ? "hover:bg-hover" : ""
}`}
>
<div className={"text-xl font-bold text-white text-center"}>{name}</div>
Expand Down
109 changes: 93 additions & 16 deletions client/src/pages/VotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,41 @@ import {
questionStarted,
} from "../constants/constants";
import { socket } from "../socket";
import { ErrorAlert } from "../components/ErrorAlert";

export const VotePage = () => {
const history = useHistory();
const cookies = new Cookies();
const [pollCode] = useState(cookies.get(pollCodeCookie));
const [started, setStarted] = useState(false);
const [hasAllowedNotif, setAllowedNotif] = useState(false);
const [lastNotif, setLastNotif] = useState<Notification | null>(null);

const [loading, setLoading] = useState(false);
const [timeoutCode, setTimeoutCode] = useState(0);
const [timeoutError, setTimeoutError] = useState(false);

const [errorCode, setErrorCode] = useState(0);
const [selectedOption, setSelectionOption] = useState("");
const [isFocus, setFocus] = useState(true);

const onBlur = () => {
setFocus(false);
};

const onFocus = () => {
document.title = mcsPollVoting;
setFocus(true);
if (document.visibilityState === "visible") {
document.title = mcsPollVoting;
}
};

useEffect(() => {
socket.emit("join", pollCode);
window.addEventListener("blur", onBlur);
window.addEventListener("focus", onFocus);
try {
Notification.requestPermission().then((permission) =>
setAllowedNotif(permission === "granted")
);
} catch (e) {
/* notifications probably not supported */
}
document.addEventListener("visibilitychange", onFocus);
return () => {
window.removeEventListener("blur", onBlur);
window.removeEventListener("focus", onFocus);
document.removeEventListener("visibilitychange", onFocus);
};
}, []);

Expand All @@ -57,8 +65,20 @@ export const VotePage = () => {
const audio = new Audio("/newQuestion.wav");
audio.play();
setSelectionOption("");
if (!isFocus) {
if (document.visibilityState === "hidden") {
document.title = questionStarted;
if (hasAllowedNotif) {
/* Close old notification to prevent spam */
if (lastNotif != null) {
lastNotif.close();
}
/* send new notification */
const notification = new Notification("New Question Started!", {
icon: "/favicon.ico",
tag: "new-question",
});
setLastNotif(notification);
}
}
}
};
Expand All @@ -73,6 +93,12 @@ export const VotePage = () => {

const voteAckHandler = (data: any) => {
setSelectionOption(String.fromCharCode(data + 64));
if (lastNotif != null) {
lastNotif.close();
setLastNotif(null);
}
clearTimeout(timeoutCode);
setLoading(false);
};
socket.on("ack", voteAckHandler);

Expand All @@ -82,12 +108,21 @@ export const VotePage = () => {
socket.off("end", pollClosedHandler);
socket.off("ack", voteAckHandler);
};
}, [errorCode, started, selectedOption]);
}, [errorCode, started, selectedOption, hasAllowedNotif, lastNotif]);

const pollButtonHandler = (selectedOption: string) => {
setLoading(true);
setTimeoutCode(
setTimeout(() => {
triggerTimeOutError();
setLoading(false);
}, 10000) as unknown as number
);
socket.emit("vote", (selectedOption.charCodeAt(0) % 65) + 1);
};

const triggerTimeOutError = () => {
setTimeoutError(true);
};
const optionButtons = () => {
const pollOptionButtons = [];
for (let i = 65; i < 70; i++) {
Expand All @@ -110,8 +145,50 @@ export const VotePage = () => {
) : (
<div className={"flex flex-col items-center px-5"}>
<Header text={`Poll Code: ${pollCode}`} />
<Header text={`Selected Option: ${selectedOption}`} />
<div className={"flex flex-col max-w-md"}>{optionButtons()}</div>
<Header
text={`Selected Option: ${
selectedOption.length > 0 ? selectedOption : "None"
}`}
/>
<div className={"relative"}>
<div className={"flex flex-col max-w-md"}>{optionButtons()}</div>
{loading ? (
<div className={"z-50 top-0 left-0 block w-full h-full absolute "}>
<div
className={
"flex items-center w-full bg- h-full flex-col justify-center align-middle"
}
style={{ backgroundColor: "rgba(0,0,0,0.5)" }}
>
<svg
aria-hidden="true"
className="w-1/4 h-1/4 text-gray-200 animate-spin dark:text-gray-900 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="transparent"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="white"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
</div>
) : null}
</div>
<ErrorAlert
text={"Your vote was not received, please try again."}
title={"Vote not received!"}
enabled={timeoutError}
onClose={() => {
setTimeoutError(false);
}}
/>
</div>
);
};
1 change: 1 addition & 0 deletions client/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
primary: "#00204E",
secondary: "#FFFFFF",
hover: "#00B5B5",
selected: "#0171B7",
background: "#F5F5F5",
}),
},
Expand Down
8 changes: 4 additions & 4 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1937,9 +1937,9 @@
integrity sha512-8MLkBIYQMuhRBQzGN9875bYsOhPnf/0rgXGo66S2FemHkhbn9qtsz9ywV1iCG+vbjigE4WUNVvw37Dx+L0qsPg==

"@types/node@^12.0.0":
version "12.20.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.33.tgz#24927446e8b7669d10abacedd16077359678f436"
integrity sha512-5XmYX2GECSa+CxMYaFsr2mrql71Q4EvHjKS+ox/SiwSdaASMoBIWE6UmZqFO+VX1jIcsYLStI4FFoB6V7FeIYw==
version "12.20.55"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
Expand Down Expand Up @@ -10825,7 +10825,7 @@ source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc
source-map@^0.5.0, source-map@^0.5.6:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
integrity sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==

source-map@^0.7.3, source-map@~0.7.2:
version "0.7.3"
Expand Down
3 changes: 3 additions & 0 deletions server/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
.idea
25 changes: 25 additions & 0 deletions server/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"env": {
"node": true
},
"extends": [
"standard",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"no-use-before-define": "off",
"no-unused-vars": "warn",
"no-console": "off",
"camelcase": "off",
"no-throw-literal": "warn"
},
"settings": {
}
}
5 changes: 4 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"prestart": "tsc",
"start": "node .",
"dev": "nodemon --watch src -e ts,ejs --exec yarn run start",
"build": "tsc --project ./"
"build": "tsc --project ./",
"lint": "eslint --ext .ts .",
"lint:fix": "eslint --ext .ts --fix ."
},
"repository": "git+https://github.com/hiimchrislim/QuizVotingSystem.git",
"author": "Chris, Akshit, Shubh, Ilir",
Expand Down Expand Up @@ -42,6 +44,7 @@
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"husky": "^8.0.1",
"nodemon": "^2.0.14",
"prettier": "^2.4.1",
"socket.io-client": "^4.3.2",
Expand Down
Loading