Skip to content

Commit

Permalink
style(fe): delete the title if no data (#2273)
Browse files Browse the repository at this point in the history
* style: delete the title if no data

* fix(fe): fix by deleting unnecessary fractions
  • Loading branch information
Clover229 authored Jan 5, 2025
1 parent 53aae12 commit e2b7649
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 85 deletions.
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[]
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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>
)
}

0 comments on commit e2b7649

Please sign in to comment.