Skip to content

Commit

Permalink
Merge pull request #151 from Prodeko/main
Browse files Browse the repository at this point in the history
Move db call outside of client component
  • Loading branch information
nlinnanen authored Nov 20, 2023
2 parents f265215 + d6d380f commit 793628c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions app/components/ui/Header/HeaderTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { ComponentProps } from 'react'

import { getCurrentSeason } from '@server/db/seasons'
import { Season } from '@common/types'

import styles from './Header.module.scss'

type h1Props = ComponentProps<'h1'>

interface Props extends h1Props {
title: string
seasonal?: boolean
currentSeason?: Season | null
}

const HeaderTitle = async ({ title, seasonal, ...props }: Props) => {
const currentSeason = await getCurrentSeason()
const HeaderTitle = async ({ title, currentSeason, ...props }: Props) => {
return (
<div className={styles.titleContainer}>
<h1 {...props} className={styles.title}>
{title}
</h1>
{currentSeason && seasonal && <h2 className={styles.seasonTitle}>{currentSeason.name}</h2>}
{currentSeason && <h2 className={styles.seasonTitle}>{currentSeason.name}</h2>}
</div>
)
}
Expand Down
8 changes: 7 additions & 1 deletion app/components/ui/Header/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ComponentProps } from 'react'

import billiardPic from '@public/images/billiard-balls.jpg'
import { getRandomPlayer } from '@server/db/players'
import { getCurrentSeason } from '@server/db/seasons'

import styles from '../Header.module.scss'
import HeaderTitle from '../HeaderTitle'
Expand All @@ -16,6 +17,7 @@ type Props = HeaderProps & {

export const Header = async ({ seasonal, ...props }: Props) => {
const randomPlayer = await getRandomPlayer().then(player => player?.toJSON())
const currentSeason = await getCurrentSeason()
return (
<header {...props} className={styles.header}>
<Image
Expand All @@ -26,7 +28,11 @@ export const Header = async ({ seasonal, ...props }: Props) => {
priority={true}
/>
<div className={styles.layout}>
<HeaderTitle seasonal={seasonal} title="Biliskilke" style={{ gridColumn: '1 / 2' }} />
<HeaderTitle
currentSeason={currentSeason}
title="Biliskilke"
style={{ gridColumn: '1 / 2' }}
/>
<RandomPlayer randomPlayer={randomPlayer} />
</div>
</header>
Expand Down

0 comments on commit 793628c

Please sign in to comment.