Hell (working)
This commit is contained in:
parent
8a7b7d69a7
commit
71d65f2cda
2 changed files with 29 additions and 4 deletions
27
src/components/Clock.tsx
Normal file
27
src/components/Clock.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { useState, useEffect } from 'preact/hooks';
|
||||
|
||||
const Clock = () => {
|
||||
const [currentTime, setCurrentTime] = useState('');
|
||||
|
||||
useEffect(() => { // Hell
|
||||
const updateCurrentTime = () => {
|
||||
const now = new Date();
|
||||
const dayOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][now.getDay()];
|
||||
let hours = now.getHours();
|
||||
hours = hours % 12 || 12;
|
||||
|
||||
const formattedTime = `${dayOfWeek}, ${hours < 10 ? '0' : ''}${hours}`;
|
||||
|
||||
setCurrentTime(formattedTime);
|
||||
};
|
||||
updateCurrentTime();
|
||||
const intervalId = setInterval(updateCurrentTime, 1000);
|
||||
return () => clearInterval(intervalId);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<h1>{currentTime}</h1>
|
||||
);
|
||||
};
|
||||
|
||||
export default Clock;
|
||||
|
|
@ -2,11 +2,9 @@ import { useLocation } from "preact-iso";
|
|||
import LinkSvg from "../assets/link.svg";
|
||||
import LogoSvg from "../assets/logo.svg";
|
||||
import { useState, useEffect } from "preact/hooks"
|
||||
|
||||
import Clock from "./Clock";
|
||||
export function Header() {
|
||||
const { url } = useLocation();
|
||||
const [currentTime, setCurrentTime] = useState('');
|
||||
|
||||
|
||||
return (
|
||||
<div id="navbar" className="h-16 px-4 bg-navbar-color flex flex-row items-center justify-between">
|
||||
|
|
@ -16,7 +14,7 @@ export function Header() {
|
|||
</div>
|
||||
|
||||
<div className="w-1/3">
|
||||
Clock
|
||||
<Clock />
|
||||
</div>
|
||||
<div className="w-1/3">
|
||||
<span className="">Games</span>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue