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

style(fe): delete the title if no data #2273

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions apps/frontend/app/(client)/(main)/_components/ContestCards.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
import { Button } from '@/components/shadcn/button'
import { fetcher } from '@/libs/utils'
import type { Contest } from '@/types/type'
import type { Route } from 'next'
import Link from 'next/link'
import ContestCard from './ContestCard'

export default async function ContestCards() {
const contests = await getContests()

return (
contests.length > 0 && (
<div className="flex w-full flex-col gap-6">
<div className="flex items-center justify-between text-gray-700">
<p className="text-2xl font-bold">Contest 🏆</p>
<Link href={'/contest'}>
<Button variant="ghost" className="h-8 px-3">
See More
</Button>
</Link>
</div>
<div className="flex justify-start gap-5 md:hidden">
{contests.slice(0, 2).map((contest) => {
return (
<Link
key={contest.id}
href={`/contest/${contest.id}` as Route}
className="inline-block w-1/2"
>
<ContestCard contest={contest} />
</Link>
)
})}
</div>
<div className="hidden justify-start gap-5 md:flex">
{contests.map((contest) => {
return (
<Link
key={contest.id}
href={`/contest/${contest.id}` as Route}
className="inline-block w-1/3"
>
<ContestCard contest={contest} />
</Link>
)
})}
</div>
</div>
)
)
}

const getContests = async () => {
const data: {
ongoing: Contest[]
@@ -20,38 +66,3 @@ const getContests = async () => {

return contests.slice(0, 3)
}

export default async function ContestCards() {
const contests = await getContests()

return (
<>
<div className="flex justify-start gap-5 md:hidden">
{contests.slice(0, 2).map((contest) => {
return (
<Link
key={contest.id}
href={`/contest/${contest.id}` as Route}
className="inline-block w-1/2"
>
<ContestCard contest={contest} />
</Link>
)
})}
</div>
<div className="hidden justify-start gap-5 md:flex">
{contests.map((contest) => {
return (
<Link
key={contest.id}
href={`/contest/${contest.id}` as Route}
className="inline-block w-1/3"
>
<ContestCard contest={contest} />
</Link>
)
})}
</div>
</>
)
}
55 changes: 33 additions & 22 deletions apps/frontend/app/(client)/(main)/_components/ProblemCards.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Button } from '@/components/shadcn/button'
import Link from 'next/link'
import { getProblemList } from '../../_libs/apis/problem'
import ProblemCard from './ProblemCard'
@@ -9,29 +10,39 @@ export default async function ProblemCards() {
})

return (
<>
<div className="flex justify-start gap-5 md:hidden">
{problems.slice(0, 2).map((problem) => (
<Link
key={problem.id}
href={`/problem/${problem.id}`}
className="inline-block w-1/2"
>
<ProblemCard problem={problem} />
problems.length > 0 && (
<div className="flex w-full flex-col gap-6">
<div className="flex items-center justify-between text-gray-700">
<p className="text-2xl font-bold">Problem ✨</p>
<Link href={'/problem'}>
<Button variant="ghost" className="h-8 px-3">
See More
</Button>
</Link>
))}
</div>
<div className="flex justify-start gap-5 md:hidden">
{problems.slice(0, 2).map((problem) => (
<Link
key={problem.id}
href={`/problem/${problem.id}`}
className="inline-block w-1/2"
>
<ProblemCard problem={problem} />
</Link>
))}
</div>
<div className="hidden justify-start gap-5 md:flex">
{problems.map((problem) => (
<Link
key={problem.id}
href={`/problem/${problem.id}`}
className="inline-block w-1/3"
>
<ProblemCard problem={problem} />
</Link>
))}
</div>
</div>
<div className="hidden justify-start gap-5 md:flex">
{problems.map((problem) => (
<Link
key={problem.id}
href={`/problem/${problem.id}`}
className="inline-block w-1/3"
>
<ProblemCard problem={problem} />
</Link>
))}
</div>
</>
)
)
}
34 changes: 6 additions & 28 deletions apps/frontend/app/(client)/(main)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import FetchErrorFallback from '@/components/FetchErrorFallback'
import { Button } from '@/components/shadcn/button'
import { ErrorBoundary } from '@suspensive/react'
import Link from 'next/link'
import Carousel from './_components/Carousel'
import ContestCards from './_components/ContestCards'
import ProblemCards from './_components/ProblemCards'
@@ -60,33 +58,13 @@ export default function Home() {
</div>
</div> */}

<div className="flex w-full flex-col gap-6">
<div className="flex items-center justify-between text-gray-700">
<p className="text-2xl font-bold">Contest 🏆</p>
<Link href={'/contest'}>
<Button variant="ghost" className="h-8 px-3">
See More
</Button>
</Link>
</div>
<ErrorBoundary fallback={FetchErrorFallback}>
<ContestCards />
</ErrorBoundary>
</div>
<ErrorBoundary fallback={FetchErrorFallback}>
<ContestCards />
</ErrorBoundary>

<div className="flex w-full flex-col gap-6">
<div className="flex items-center justify-between text-gray-700">
<p className="text-2xl font-bold">Problem ✨</p>
<Link href={'/problem'}>
<Button variant="ghost" className="h-8 px-3">
See More
</Button>
</Link>
</div>
<ErrorBoundary fallback={FetchErrorFallback}>
<ProblemCards />
</ErrorBoundary>
</div>
<ErrorBoundary fallback={FetchErrorFallback}>
<ProblemCards />
</ErrorBoundary>
</div>
)
}