Skip to content

Commit

Permalink
fix: rework skeleton loader for the thumbnail loading (#117)
Browse files Browse the repository at this point in the history
### TL;DR

Switches the old pdf skeleton loader to a more accurate thumbnail shaped skeleton loader.
  • Loading branch information
aamirazad authored Aug 7, 2024
1 parent c4dd370 commit b42ddfe
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/components/document-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
QueryClientProvider,
QueryClient,
} from "@tanstack/react-query";
import type { AdviceAPIType } from "@/types";
import type { UsersTableType } from "@/server/db/schema";
import { Button, buttonVariants } from "@/components/ui/button";
import { ChevronLeft } from "lucide-react";
Expand Down Expand Up @@ -40,30 +39,11 @@ export async function getPaperlessThumbnail(
}

function SkeletonLoader() {
const { data: advice, isLoading } = useQuery({
queryKey: ["advice"],
queryFn: async () => {
const response = await fetch("https://api.adviceslip.com/advice");
return (await response.json()) as AdviceAPIType;
},
});

return (
<div className="m-4 flex h-full flex-grow flex-col justify-center gap-8 md:m-8 md:flex-row md:gap-16">
{/* PDF Skeleton */}
<div className="relative flex h-full flex-shrink flex-grow items-center justify-center rounded-lg">
<div className="m-4 flex h-full flex-grow flex-col justify-center gap-8 bg-gray-200 md:m-8 md:flex-row md:gap-16">
<div className="relative flex h-full w-full flex-shrink flex-grow items-center justify-center rounded-lg">
{/* Pulsing Background */}
<div className="absolute inset-0 animate-pulse rounded-lg bg-gray-400" />
{/* Text Overlay */}
<div className="z-10 flex items-center justify-center">
<div className="text-center text-black">
{isLoading
? "Loading advice..."
: advice?.slip.advice === null
? "Unable to fetch advice"
: advice?.slip.advice}
</div>
</div>
<div className="absolute inset-0 h-full w-full animate-pulse rounded-lg bg-gray-300" />
</div>
</div>
);
Expand Down

0 comments on commit b42ddfe

Please sign in to comment.