Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat(page:home): add Skeleton when fetching data
Browse files Browse the repository at this point in the history
  ## what
  - add `Skeleton` when fetching data

  ## how
  - use shadcn-ui components
    - `Table`
    - `Skeleton`

  ## why
  - add better user experience when the data is being fetched

  ## where
  - ./src/app/page.tsx

  ## usage
  • Loading branch information
Clumsy-Coder committed Dec 31, 2023
1 parent 59477bc commit b2aee44
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
"use client";

import { useRef } from "react";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Skeleton } from '@/components/ui/skeleton'

import { useFetchLiveSubmission } from "@/hooks";
import LiveSubmissionTable from "./LiveSubmissionTable";

const Loading = () => {
return (
<Table>
<TableHeader>
<TableRow>
<TableHead>Submission ID</TableHead>
<TableHead>Problem number</TableHead>
<TableHead>Problem title</TableHead>
<TableHead>User (username)</TableHead>
<TableHead className="text-center">Verdict</TableHead>
<TableHead>Language</TableHead>
<TableHead>Time</TableHead>
<TableHead>Rank</TableHead>
<TableHead className="text-right">Submit time</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{[...Array(10)].map((_, i) => {
return (
<TableRow key={`row-${i}`}>
{[...Array(9)].map((_, k) => (
<TableCell key={`row-${i}-cell-${k}`}>
<Skeleton className="w-full h-4" />
</TableCell>
))}
</TableRow>
);
})}
</TableBody>
</Table>
);
}

///////////////////////////////////////////////////////////////////////////////////////////////////

export default function Home() {
// used for setting the pollId.
// not using useState, because that will force a re-render every time it's set
Expand All @@ -14,7 +58,8 @@ export default function Home() {
const { data, isLoading, isError, isSuccess } = useFetchLiveSubmission(pollIdRef.current);

if (isLoading || !data) {
return <div>Fetching data</div>;
return <Loading />
;
}

if (isError) {
Expand Down

0 comments on commit b2aee44

Please sign in to comment.