Skip to content

Commit

Permalink
Added loading to period cards (#157)
Browse files Browse the repository at this point in the history
* added loading to period cards

* Added skeleton loader to PeriodCard

---------

Co-authored-by: fredrir <[email protected]>
  • Loading branch information
julian-ao and fredrir authored Jul 24, 2024
1 parent d057086 commit a595074
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions components/PeriodCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PeriodCard = ({ period }: Props) => {
const { data: session } = useSession();
const router = useRouter();
const [hasApplied, setHasApplied] = useState(false);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const checkApplicationStatus = async () => {
Expand All @@ -24,6 +25,7 @@ const PeriodCard = ({ period }: Props) => {
if (response.ok) {
const data = await response.json();
setHasApplied(data.exists);
setIsLoading(false);
}
}
};
Expand All @@ -33,6 +35,17 @@ const PeriodCard = ({ period }: Props) => {
}
}, [period._id, session?.user?.owId]);

if (isLoading) {
return (
<div className="w-full max-w-md p-4 border border-gray-200 rounded shadow animate-pulse md:p-6 dark:border-gray-700 ">
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
</div>
);
}

return (
<div className="relative w-full max-w-md mx-auto break-words border rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 dark:text-white">
<div className="flex flex-col justify-between h-full p-4">
Expand Down
2 changes: 1 addition & 1 deletion pages/apply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Apply = () => {
<h3 className="text-4xl font-bold tracking-tight text-center dark:text-white">
Nåværende opptaksperioder
</h3>
<div className="flex flex-wrap justify-center max-w-full gap-5">
<div className="flex flex-col items-center max-w-full gap-5">
{currentPeriods.map((period: periodType, index: number) => (
<PeriodCard key={index} period={period} />
))}
Expand Down

0 comments on commit a595074

Please sign in to comment.