Skip to content

Commit

Permalink
Added Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
rishit-singh committed Aug 22, 2023
1 parent b7766ec commit dee1929
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
8 changes: 8 additions & 0 deletions frontend/src/app/hacks/Body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Timer} from "@/app/hacks/Timer";

export function Body()
{
return <div className={"bg-hacks-bg-black"}>
<Timer EndTime={new Date(2023, 8, 23, 8, 0, 0)}/>
</div>
}
2 changes: 1 addition & 1 deletion frontend/src/app/hacks/IconLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export function IconLabel({iconSrc, label, height, width}: {iconSrc: string, lab
{
return <div className={"grid grid-cols-2"}>
<Image src={iconSrc as string} alt={"Image"} height={height as number} width={width as number} className={"self-center justify-self-end"}></Image>
<span className={"text-lg text-white self-center ml-2"}>{label}</span>
<span className={"text-lg max-[850px]:text-xs text-white self-center ml-2"}>{label}</span>
</div>;
}
72 changes: 72 additions & 0 deletions frontend/src/app/hacks/Timer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use client";

import {Component, useState} from "react";

class TimeStamp
{
public readonly Days: number;
public readonly Hours: number;
public readonly Minutes: number;
public readonly Seconds: number;

public constructor(days: number, hours: number, minutes: number, seconds: number)
{
this.Days = days;
this.Hours = hours;
this.Seconds = seconds;
this.Minutes = minutes;
}
}

interface TimerProps
{
EndTime: Date;
}

interface TimerState
{
CurrentTimeStamp: TimeStamp;
}

export class Timer extends Component<TimerProps, TimerState>
{
protected TimeDifference: number;

protected Days: number;

public Tick(): void
{
setInterval(()=> {
this.UpdateTimeStamp();
if(this.TimeDifference > 0)
this.TimeDifference -= 1;
}, 1000);
}

public UpdateTimeStamp(): void {
let seconds: number = Math.floor(this.TimeDifference % 60),
minutes: number = Math.floor((this.TimeDifference % 3600) / 60),
hours: number = Math.floor((this.TimeDifference % 86400) / 3600),
days: number = Math.floor(this.TimeDifference / (3600 * 24));

this.setState({CurrentTimeStamp: new TimeStamp(days, hours, minutes, seconds)});
}

public componentWillMount() {
this.TimeDifference = Math.abs(this.props.EndTime - new Date()) / 1000;
this.setState({CurrentTime: this.TimeDifference, CurrentTimeStamp: new TimeStamp(0,0,0,0)});
this.Tick();
}

render()
{
return <div className={"text-white text-3xl"}>
{this.state.CurrentTimeStamp.Days}d {this.state.CurrentTimeStamp.Hours}h {this.state.CurrentTimeStamp.Minutes}m {this.state.CurrentTimeStamp.Seconds}s
</div>
}

constructor(props: TimerProps)
{
super(props);
}
}
2 changes: 2 additions & 0 deletions frontend/src/app/hacks/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {Header} from "./Header";
import {Body} from "@/app/hacks/Body";

export default function Page()
{
return <div className={"grid grid-rows-[30vh_70vh] bg-navs-bg-black h-full font-audiowide"}>
<Header/>
<Body/>
</div>;
}
2 changes: 1 addition & 1 deletion frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
"nav-bar-black": "#010101",
"body-gray": "#171717",
"hacks-nav-black": "#202020",
"hacks-bg-black": "#1E1E1E"
"hacks-bg-black": "#212121"
},
fontFamily: {
"audiowide": ["audiowide", "regular"]
Expand Down

0 comments on commit dee1929

Please sign in to comment.