Skip to content

Commit

Permalink
use same function to get data
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschonti committed Jan 25, 2024
1 parent 30101ed commit 789ba10
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/app/giveaway/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GiveawayTile } from '@/components/tiles/giveaway-tile';
import { getIndexData } from '@/models/get-index-data';

export default async function Giveaway() {
const { giveaway } = await getIndexData();

return (
<div className='grid grid-col-6 max-w-6xl w-full my-40 px-6 xl:px-0'>
<GiveawayTile data={giveaway} showLink={false} />
</div>
);
}
10 changes: 1 addition & 9 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ import { GiveawayTile } from '@/components/tiles/giveaway-tile';
import { PromoVideoTile } from '@/components/tiles/promo-video-tile';
import { RegisterTile } from '@/components/tiles/register-tile';
import { StatTile } from '@/components/tiles/stat-tile';
import { IndexPageData } from '@/models/models';
import { getIndexData } from '@/models/get-index-data';

import konfLogo from '../../public/img/konf.svg';

async function getIndexData(): Promise<IndexPageData> {
const res = await fetch(`${process.env.BACKEND_URL}/conference/index`);
if (!res.ok) {
throw new Error(res.status.toString());
}
return res.json();
}

export default async function Landing() {
const data = await getIndexData();
return (
Expand Down
11 changes: 7 additions & 4 deletions src/components/tiles/giveaway-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { GiveawayData } from '@/models/models';

type Props = {
data: GiveawayData;
showLink?: boolean;
};

export function GiveawayTile({ data: { description, sectionTitle, pictureUrl } }: Props) {
export function GiveawayTile({ data: { description, sectionTitle, pictureUrl }, showLink = true }: Props) {
const [preText, shinyText, postText] = description.split('***');
return (
<div className='tile sm:col-span-6 p-10'>
Expand All @@ -16,9 +17,11 @@ export function GiveawayTile({ data: { description, sectionTitle, pictureUrl } }
<p className='text-lg sm:text-xl font-medium text-justify w-full'>{preText}</p>
<h3 className='text-5xl sm:text-6xl font-bold text-[#FFE500]'>{shinyText}</h3>
<p className='text-lg mb-8 sm:text-xl font-medium text-justify w-full'>{postText}</p>
<Link className='text-2xl font-medium underline' href='/giveaway'>
További részleteket itt találsz
</Link>
{showLink && (
<Link className='text-2xl font-medium underline' href='/giveaway'>
További részleteket itt találsz
</Link>
)}
</div>
<img className='w-full aspect-[16/9]' src={pictureUrl} />
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/models/get-index-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IndexPageData } from './models';

export async function getIndexData(): Promise<IndexPageData> {
const res = await fetch(`${process.env.BACKEND_URL}/conference/index`);
if (!res.ok) {
throw new Error(res.status.toString());
}
return res.json();
}

0 comments on commit 789ba10

Please sign in to comment.