Skip to content

Commit

Permalink
refactor, added eslint fix to husky hooks (#32)
Browse files Browse the repository at this point in the history
* fix: better form handling

* fix: refactor

---------

Co-authored-by: avinash2wards <[email protected]>
  • Loading branch information
avinashcodelabs and avinash2wards authored Sep 23, 2023
1 parent 984f4bb commit d0c08c7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
npx lint-staged
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"src/**/*": "prettier --write --ignore-unknown"
"src/**/*": ["eslint --fix", "prettier --write --ignore-unknown"]
}
58 changes: 30 additions & 28 deletions src/components/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export default function ParticipantsCard({
const [userName, setUserName] = useState(placeholderUserName);
const [isError, setError] = useState(false);

const handleClick = (e) => {
const handleSubmit = (e) => {
e.preventDefault();
if (userName.length < 3) {
setError(true);
return;
}
if (userName.length >= 3 && e.key === "Enter") {
handleSetUserName(userName);
}
handleSetUserName(userName);
};
return (
<>
Expand All @@ -32,30 +31,33 @@ export default function ParticipantsCard({
<h1 className="">{`You have been invited to join a room`}</h1>
</>
)}

<div className="form-control">
<input
onChange={(e) => {
setUserName(e.target.value);
}}
value={userName}
type="text"
autoFocus
placeholder="Enter your name"
className={classNames("input input-bordered border border-primary", {
"border-red-600": isError && userName.length < 3,
})}
onKeyUp={handleClick}
/>
</div>
<div className="form-control mt-6 w-fit self-end">
<button
className="btn btn-primary text-base-100 normal-case"
onClick={handleClick}
>
{isAdmin ? "Create Room" : "Join Room"}
</button>
</div>
<form onSubmit={handleSubmit}>
<div className="form-control">
<input
onChange={(e) => {
setUserName(e.target.value);
}}
value={userName}
type="text"
autoFocus
placeholder="Enter your name"
className={classNames(
"input input-bordered border border-primary",
{
"border-red-600": isError && userName.length < 3,
},
)}
/>
</div>
<div className="form-control mt-6 w-fit self-end">
<button
className="btn btn-primary text-base-100 normal-case"
type="submit"
>
{isAdmin ? "Create Room" : "Join Room"}
</button>
</div>
</form>
</>
);
}
5 changes: 0 additions & 5 deletions src/pages/api/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ import {
getRoomInfo,
updateRoom,
resetUserVotesByRoom,
logCollectionValues,
} from "@/lib/manageUsers";

export default function handler(req, res) {
if (res.socket.server.io) {
console.log("Socket is already running");
// DB logger with set timing interval for development puroposes
// setInterval(function () {
// logCollectionValues();
// }, 5000);
} else {
console.log("Socket is initializing");
const io = new Server(res.socket.server, {
Expand Down

0 comments on commit d0c08c7

Please sign in to comment.