Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(board): added clock to board #1102

Merged
merged 8 commits into from
Jul 6, 2023
2 changes: 1 addition & 1 deletion next-tavla/pages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function BoardPage({ settings }: { settings: TSettings }) {
return (
<div className={classes.root} data-theme={settings.theme || 'dark'}>
<div className={classes.rootContainer}>
<Header theme={settings.theme} />
<Header theme={settings.theme} showClock={true} />
<Board settings={settings} />
</div>
</div>
Expand Down
19 changes: 19 additions & 0 deletions next-tavla/src/Shared/components/Clock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from 'react'

function Clock() {
const [currentTime, setCurrentTime] = useState(Date.now())

useEffect(() => {
const intervalId = setInterval(() => setCurrentTime(Date.now()), 1000)
return () => clearInterval(intervalId)
}, [])

const time = new Intl.DateTimeFormat('no-NB', {
timeStyle: 'short',
timeZone: 'Europe/Oslo',
}).format(currentTime)

return <span>{time}</span>
}

export { Clock }
48 changes: 26 additions & 22 deletions next-tavla/src/Shared/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ import TavlaLogoLight from 'assets/logos/Tavla-blue.svg'
import Image from 'next/image'
import classes from './styles.module.css'
import { TTheme } from 'types/settings'
import { Clock } from 'components/Clock'

function Header({ theme }: { theme?: TTheme }) {
function Header({ theme, showClock }: { theme?: TTheme; showClock?: boolean }) {
return (
<div>
{theme === 'light' ? (
<Image
src={TavlaLogoLight}
alt="Entur Tavla logo"
width={117}
height={20}
className={classes.logo}
/>
) : (
<Image
src={TavlaLogo}
alt="Entur Tavla logo"
width={117}
height={20}
className={classes.logo}
/>
)}
<p className={classes.tagText}>
Finn din rute på entur.no eller i Entur-appen
</p>
<div className={classes.headerWrapper}>
<div>
{theme === 'light' ? (
<Image
src={TavlaLogoLight}
alt="Entur Tavla logo"
width={117}
height={20}
className={classes.logo}
/>
) : (
<Image
src={TavlaLogo}
alt="Entur Tavla logo"
width={117}
height={20}
className={classes.logo}
/>
)}
<p className={classes.tagText}>
Finn din rute på entur.no eller i Entur-appen
</p>
</div>
{showClock && <Clock />}
</div>
)
}
Expand Down
8 changes: 8 additions & 0 deletions next-tavla/src/Shared/components/Header/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
.tagText {
font-size: 0.5em;
color: var(--main-text-color);
margin: 0;
}

.headerWrapper {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}