Skip to content

Commit

Permalink
add a countdown to login
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshith-403 committed Mar 4, 2024
1 parent ede8e37 commit 087f499
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
31 changes: 31 additions & 0 deletions frontend/src/Components/Login/Login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,35 @@
background-color: #fff;
font-weight: bold;
pointer-events: none;
}

.reg-section {
max-width: 600px;
margin-left: auto;
margin-right: auto;
}

@import url('https://fonts.googleapis.com/css2?family=Orbitron:[email protected]&display=swap');

.countdown {
font-size: 1.5em;
text-align: center;
color: #7589b0;

.timer {
font-family: "Orbitron", sans-serif;
font-optical-sizing: auto;
font-style: normal;
font-weight: bold;
}
}

.mobile-break {
display: none;
}

@media screen and (max-width: 768px) {
.mobile-break {
display: block;
}
}
47 changes: 46 additions & 1 deletion frontend/src/Components/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,50 @@ import './Login.scss';
import {Network, ResponseModel} from "../../Network";
import Swal from "sweetalert2";
import Task from "../Task/Task.";
import {useEffect} from "react"

function Countdown() {
type TimeLeft = {
days?: number;
hours?: number;
minutes?: number;
seconds?: number;
};

const calculateTimeLeft = (): TimeLeft => {
const difference = +new Date("2024-03-14T23:59") - +new Date();
let timeLeft = {};

if (difference > 0) {
timeLeft = {
days: Math.floor(difference / (1000 * 60 * 60 * 24)),
hours: Math.floor((difference / (1000 * 60 * 60)) % 24),
minutes: Math.floor((difference / 1000 / 60) % 60),
seconds: Math.floor((difference / 1000) % 60),
};
}

return timeLeft;
};

const [timeLeft, setTimeLeft] = useState(calculateTimeLeft());

useEffect(() => {
const timer = setTimeout(() => {
setTimeLeft(calculateTimeLeft());
}, 1000);

return () => clearTimeout(timer);
});

return (
<div className="countdown">
<span>Time Left to Submit: </span>
<br className="mobile-break" />
<span className={"timer"}>{timeLeft.days}d {timeLeft.hours}h {timeLeft.minutes}m {timeLeft.seconds}s</span>
</div>
);
}

export default function Login() {

Expand Down Expand Up @@ -62,7 +105,7 @@ export default function Login() {

<div className="row form-group">
<div className="col-md-12">
<label htmlFor="nic">NIC</label>
<label htmlFor="nic">NIC (Of any member)</label>
<input type="text" id="nic" className="form-control"
{...register("nic", {required: true})}/>
</div>
Expand All @@ -79,6 +122,8 @@ export default function Login() {
</form>
</div>
</div>

<Countdown />
</div>
</div>
);
Expand Down

0 comments on commit 087f499

Please sign in to comment.