Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skeleton loaders instead of spinner #49

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"dev": "next dev",
"dev": "next dev --turbo",
"lint": "next lint",
"start": "next start"
},
Expand Down
6 changes: 5 additions & 1 deletion src/app/paperless/document/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ export default function ModalDocumentPage({
}: {
params: { id: number };
}) {
return <DocumentViewer id={params.id} />;
return (
<main className="h-full w-full">
<DocumentViewer id={params.id} />
</main>
);
}
33 changes: 24 additions & 9 deletions src/components/document-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ export default function DocumentViewer(props: { id: number }) {
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
const [loading, setLoading] = useState(true);

const SkeletonLoader = () => (
<div className="flex h-4/5 w-full justify-center">
<div className="flex h-full min-w-0 justify-center md:w-1/2">
<div className="flex h-full w-full flex-col rounded-xl bg-slate-600/50">
<div className="m-4 flex flex-grow animate-pulse flex-col justify-center gap-8 md:m-8 md:flex-row md:gap-16">
{/* PDF Skeleton */}
<div className="h-full flex-shrink flex-grow rounded-lg bg-gray-400"></div>
{/* Button Skeleton */}
<div className="flex flex-shrink-0 flex-col gap-8">
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
<div className="h-10 w-24 rounded-md bg-gray-400"></div>
</div>
</div>
</div>
</div>
</div>
);

useEffect(() => {
const fetchData = async () => {
setLoading(true);
Expand All @@ -65,15 +88,7 @@ export default function DocumentViewer(props: { id: number }) {
}, [props.id]); // Dependency array to refetch if id changes

if (loading) {
return (
<div className="flex justify-center">
<div className="mx-auto max-w-sm rounded-lg bg-black p-4 shadow-md">
<LoadingSpinner className="w-min rounded-full text-xl font-bold">
Loading...
</LoadingSpinner>
</div>
</div>
);
return <SkeletonLoader />;
}

if (!pdfUrl) {
Expand Down
1 change: 0 additions & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Config } from "tailwindcss";
const { fontFamily } = require("tailwindcss/defaultTheme");

const config = {
darkMode: ["class"],
Expand Down
Loading