Skip to content

Commit

Permalink
WIP: skeletons for loading
Browse files Browse the repository at this point in the history
  • Loading branch information
geekysilento committed Apr 26, 2024
1 parent 21a476e commit cc9c5d8
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 49 deletions.
38 changes: 19 additions & 19 deletions app/[locale]/academics/curricula/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Suspense } from 'react';
import { FaExternalLinkAlt } from 'react-icons/fa';

import Heading from '~/components/heading';
import Loading from '~/components/loading';
import CurriculaSkeleton from '~/components/skeletons/curricula-skeleton';
import {
Button,
Table,
Expand Down Expand Up @@ -35,25 +35,25 @@ export default async function Curricula({
<search className="container">
{/* FIXME: Add input and filters here */}
</search>

{/* FIXME: Make Tables mobile friendly by adding horizontal scrolling*/}
<main className="container">
<Suspense fallback={<Loading />}>
<Table>
<TableHeader>
<TableRow>
<TableHead>{text.code}</TableHead>
<TableHead>{text.title}</TableHead>
<TableHead>{text.major}</TableHead>
<TableHead>{text.credits}</TableHead>
<TableHead>{text.totalCredits}</TableHead>
<TableHead className="text-center">{text.syllabus}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<Table>
<TableHeader>
<TableRow>
<TableHead>{text.code}</TableHead>
<TableHead>{text.title}</TableHead>
<TableHead>{text.major}</TableHead>
<TableHead>{text.credits}</TableHead>
<TableHead>{text.totalCredits}</TableHead>
<TableHead className="text-center">{text.syllabus}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<Suspense fallback={<CurriculaSkeleton />}>
<Courses />
</TableBody>
</Table>
</Suspense>
</Suspense>
</TableBody>
</Table>
</main>
</>
);
Expand All @@ -74,7 +74,7 @@ const Courses = async () => {
},
});

return courses.map(({ code, coursesToMajors, title }, index) =>
return courses.map(({ code, coursesToMajors, title }) =>
coursesToMajors.map(
({ lectureCredits, practicalCredits, tutorialCredits, major }, index) => (
<TableRow key={index}>
Expand Down
11 changes: 9 additions & 2 deletions app/[locale]/faculty-and-staff/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
SelectValue,
} from '~/components/inputs';
import Loading from '~/components/loading';
import DepartmentCardSkeleton from '~/components/skeletons/department-card-skeleton';
import DepartmentNameSkeleton from '~/components/skeletons/department-name-skeleton';
import { Button } from '~/components/ui';
import { getTranslations } from '~/i18n/translations';
import { cn } from '~/lib/utils';
Expand All @@ -36,7 +38,7 @@ export default async function FacultyAndStaff({
'border border-primary-700 bg-neutral-50'
)}
>
<Suspense fallback={<Loading className="max-xl:hidden" />}>
<Suspense fallback={<DepartmentNameSkeleton />}>
<Departments department={departmentName} />
</Suspense>
</search>
Expand All @@ -58,7 +60,12 @@ export default async function FacultyAndStaff({
</search>

<ol className="space-y-4">
<Suspense fallback={<Loading />} key={`${query}-${departmentName}`}>
<Suspense
fallback={Array.from({ length: 10 }).map((_, index) => (
<DepartmentCardSkeleton key={index} />
))}
key={`${query}-${departmentName}`}
>
<FacultyList
department={departmentName}
deptartmentHeadText={text.departmentHead}
Expand Down
46 changes: 26 additions & 20 deletions app/[locale]/institute/administration/(committees)/committee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Suspense } from 'react';
import { FaExternalLinkAlt } from 'react-icons/fa';

import Heading from '~/components/heading';
import Loading from '~/components/loading';
import { PaginationUI } from '~/components/pagination/pagination';
import MeetingsSkeleton from '~/components/skeletons/meetings-skeleton';
import {
Button,
Table,
Expand Down Expand Up @@ -76,26 +76,32 @@ export default async function Committee({
</Table>

<Heading glyphDirection="ltr" heading="h2" text={text.meetings.title} />
<Suspense fallback={<Loading />}>
<Table>
<TableHeader>
<TableRow>
<TableHead>{text.meetings.serial}</TableHead>
<TableHead>{text.meetings.date}</TableHead>
<TableHead>{text.meetings.place}</TableHead>
<TableHead className="text-center">
{text.meetings.agenda}
</TableHead>
<TableHead className="text-center">
{text.meetings.minutes}
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<Table>
<TableHeader>
<TableRow>
<TableHead>{text.meetings.serial}</TableHead>
<TableHead>{text.meetings.date}</TableHead>
<TableHead>{text.meetings.place}</TableHead>
<TableHead className="text-center">
{text.meetings.agenda}
</TableHead>
<TableHead className="text-center">
{text.meetings.minutes}
</TableHead>
</TableRow>
</TableHeader>

<TableBody>
<Suspense
fallback={Array.from({ length: 10 }).map((_, index) => (
<MeetingsSkeleton key={index} />
))}
key={meetingPage}
>
<Meetings locale={locale} page={meetingPage} type={type} />
</TableBody>
</Table>
</Suspense>
</Suspense>
</TableBody>
</Table>
<PaginationUI
currentPage={meetingPage}
query={db
Expand Down
9 changes: 7 additions & 2 deletions app/[locale]/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Suspense } from 'react';
import { MdOutlineKeyboardArrowRight } from 'react-icons/md';

import Heading from '~/components/heading';
import Loading from '~/components/loading';
import { NotificationSkeleton } from '~/components/skeletons/notification-skeleton';
import { Button, ScrollArea } from '~/components/ui';
import { getTranslations } from '~/i18n/translations';
import { cn, getKeys, groupBy } from '~/lib/utils';
Expand Down Expand Up @@ -83,7 +83,12 @@ export default async function Notifications({
)}
>
<ol className="space-y-2 sm:space-y-4 md:space-y-6">
<Suspense fallback={<Loading />} key={currentCategory}>
<Suspense
fallback={Array.from({ length: 5 }).map((_, index) => (
<NotificationSkeleton count={(index % 2) + 1} key={index} />
))}
key={currentCategory}
>
<NotificationsList category={currentCategory} locale={locale} />
</Suspense>
</ol>
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/student-activities/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FaArrowUp } from 'react-icons/fa6';
import { GalleryCarousel } from '~/components/carousels';
import Heading from '~/components/heading';
import ImageHeader from '~/components/image-header';
import Loading from '~/components/loading';
import StudentActivityCarouselSkeleton from '~/components/skeletons/studentactivity-carousel-skeleton';
import { Button, Card, CardDescription, CardTitle } from '~/components/ui';
import { getTranslations } from '~/i18n/translations';
import { cn } from '~/lib/utils';
Expand Down Expand Up @@ -43,7 +43,7 @@ export default async function StudentActivities({
/>

<section className="container mb-6 text-center">
<Suspense fallback={<Loading />}>
<Suspense fallback={<StudentActivityCarouselSkeleton />}>
<ClubsCarousel locale={locale} />
</Suspense>
<Button
Expand Down
30 changes: 30 additions & 0 deletions components/skeletons/curricula-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TableCell, TableRow } from '~/components/ui';
import { Skeleton } from '~/components/ui/skeleton';

const CurriculaSkeleton = () => {
return (
<>
<TableRow>
<TableCell>
<Skeleton className="h-4 w-[40px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[200px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[250px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[40px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[20px]" />
</TableCell>
<TableCell>
<Skeleton className="mx-auto h-4 w-[20px]" />
</TableCell>
</TableRow>
</>
);
};
export default CurriculaSkeleton;
37 changes: 37 additions & 0 deletions components/skeletons/department-card-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FaPhone } from 'react-icons/fa';
import { MdEmail } from 'react-icons/md';

import { Skeleton } from '../ui/skeleton';

const DepartmentCardSkeleton = () => {
return (
<li className="rounded border border-primary-700 bg-neutral-50 hover:drop-shadow-md">
<section className="flex gap-4 p-2 sm:p-3 md:p-4">
<Skeleton className="size-32 rounded lg:size-36 xl:size-40 2xl:size-44" />
<main>
<header className="mb-1 sm:mb-2 md:mb-3 lg:mb-4">
<h4>
<Skeleton className="h-5 w-[175px] lg:h-6 lg:w-[350px]" />
</h4>
<p>
<Skeleton className="h-3 w-[150px] lg:h-4 lg:w-[250px]" />
</p>
</header>

<ul className="mt-7">
<li className="flex items-center gap-3">
<MdEmail className="fill-primary-700" />
<Skeleton className="h-4 w-[150px]" />
</li>
<li className="flex items-center gap-3 space-y-3">
<FaPhone className="scale-x-[-1] fill-primary-700" />
<Skeleton className="h-4 w-[150px]" />
</li>
</ul>
</main>
</section>
</li>
);
};

export default DepartmentCardSkeleton;
26 changes: 26 additions & 0 deletions components/skeletons/department-name-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Skeleton } from '../ui/skeleton';

const DepartmentNameSkeleton = () => {
return (
<section className="space-y-5">
<Skeleton className="h-3 w-[300px]" />
<Skeleton className="h-3 w-[300px]" />
<Skeleton className="h-3 w-[250px]" />
<Skeleton className="h-3 w-[200px]" />
<Skeleton className="h-3 w-[275px]" />
<Skeleton className="h-3 w-[200px]" />
<Skeleton className="h-3 w-[225px]" />
<Skeleton className="h-3 w-[150px]" />
<Skeleton className="h-3 w-[300px]" />
<Skeleton className="h-3 w-[300px]" />
<Skeleton className="h-3 w-[250px]" />
<Skeleton className="h-3 w-[200px]" />
<Skeleton className="h-3 w-[275px]" />
<Skeleton className="h-3 w-[200px]" />
<Skeleton className="h-3 w-[225px]" />
<Skeleton className="h-3 w-[150px]" />
</section>
);
};

export default DepartmentNameSkeleton;
27 changes: 27 additions & 0 deletions components/skeletons/meetings-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TableCell, TableRow } from '~/components/ui';
import { Skeleton } from '~/components/ui/skeleton';

const MeetingsSkeleton = () => {
return (
<>
<TableRow>
<TableCell>
<Skeleton className="h-4 w-[30px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[150px]" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-[400px]" />
</TableCell>
<TableCell>
<Skeleton className="mx-auto h-4 w-[20px]" />
</TableCell>
<TableCell>
<Skeleton className="mx-auto h-4 w-[20px]" />
</TableCell>
</TableRow>
</>
);
};
export default MeetingsSkeleton;
22 changes: 22 additions & 0 deletions components/skeletons/notification-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MdOutlineKeyboardArrowRight } from 'react-icons/md';

import { Skeleton } from '../ui/skeleton';

export const NotificationSkeleton = ({ count }: { count: number }) => {
return (
<li className="mt-1">
<h5 className="text-primary-700">
<Skeleton className="h-5 w-[125px] bg-neutral-400" />
</h5>
<ul className="my-1 py-2 sm:py-4 md:py-6">
{[...Array<number>(count)].map((_, index) => (
<li className="inline-flex items-center" key={index}>
<MdOutlineKeyboardArrowRight className="my-auto size-4 text-primary-700 lg:size-6" />
<Skeleton className="h-3 w-[450px] bg-neutral-400 lg:h-4 lg:w-[650px]" />
</li>
))}
</ul>
<hr className="opacity-20" />
</li>
);
};
33 changes: 33 additions & 0 deletions components/skeletons/studentactivity-carousel-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { cn } from '~/lib/utils';

import { GalleryCarousel } from '../carousels/gallery';
import { Card, CardDescription, CardTitle } from '../ui';
import { Skeleton } from '../ui/skeleton';

const StudentActivityCarouselSkeleton = () => {
return (
<GalleryCarousel>
{Array.from({ length: 6 }).map((_, index) => (
<Card
className="mx-auto flex aspect-square size-48 flex-col p-3 drop-shadow hover:drop-shadow-xl sm:size-56 md:size-64"
key={index}
>
<CardTitle
className={cn(
'flex items-center justify-center gap-2 text-neutral-900',
'text-lg sm:text-xl md:text-2xl'
)}
>
<Skeleton className="aspect-square size-6 rounded-md sm:size-7 md:size-8" />
<Skeleton className="h-6 w-[300px] sm:h-7 md:h-8" />
</CardTitle>
<CardDescription className="grow">
<Skeleton className="size-full rounded-md object-cover" />
</CardDescription>
</Card>
))}
</GalleryCarousel>
);
};

export default StudentActivityCarouselSkeleton;
8 changes: 4 additions & 4 deletions components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { cn } from "~/lib/utils"
import { cn } from '~/lib/utils';

function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-gray-100 dark:bg-gray-800", className)}
className={cn('animate-pulse rounded-md bg-neutral-200', className)}
{...props}
/>
)
);
}

export { Skeleton }
export { Skeleton };

0 comments on commit cc9c5d8

Please sign in to comment.