Skip to content

Commit

Permalink
Abscract loading spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jun 14, 2024
1 parent eef1d46 commit 51d9178
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/app/paperless/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import {
import { Input } from "@/components/ui/input";
import { zodResolver } from "@hookform/resolvers/zod";
import { useCallback } from "react";
import { ExternalLink, LoaderCircle } from "lucide-react";
import { ExternalLink } from "lucide-react";
import { useEffect } from "react";
import {
useQuery,
QueryClientProvider,
QueryClient,
} from "@tanstack/react-query";
import LoadingSpinner from "@/components/loading-spinner";

function DocumentsSearch() {
const formSchema = z.object({
Expand Down Expand Up @@ -138,10 +139,7 @@ function DocumentsPage() {
return (
<div>
{QueryResult.isLoading ? (
<div className="flex flex-row place-content-center gap-1">
<LoaderCircle className="animate-spin" />
Loading...
</div>
<LoadingSpinner>Loading...</LoadingSpinner>
) : QueryResult.data?.data ? (
<div className="flex flex-col gap-4">
<h1 className="text-2xl font-bold">Search Results</h1>
Expand Down
9 changes: 2 additions & 7 deletions src/app/setup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useForm } from "react-hook-form";
import { Dispatch, SetStateAction } from "react";
import { useUser } from "@clerk/nextjs";
import { redirect, usePathname } from "next/navigation";
import { LoaderCircle } from "lucide-react";
import LoadingSpinner from "@/components/loading-spinner";

function FullName({
setActiveTab,
Expand All @@ -31,12 +31,7 @@ function FullName({

if (!isLoaded) {
// Handle loading state however you like
return (
<div className="flex flex-row place-content-center gap-1">
<LoaderCircle className="animate-spin" />
Loading...
</div>
);
return <LoadingSpinner>Loading...</LoadingSpinner>;
}

if (!user) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import LoadingSpinner from "@/components/loading-spinner";
import { RedirectToSignIn, SignedIn, SignedOut } from "@clerk/nextjs";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
Expand All @@ -11,7 +12,7 @@ export default function SignIn() {
return (
<div className="text-xl">
<SignedOut>
Signing you in...
<LoadingSpinner>Signing you in...</LoadingSpinner>
<RedirectToSignIn signInForceRedirectUrl={redirect} />
</SignedOut>
<SignedIn>
Expand Down
14 changes: 14 additions & 0 deletions src/components/loading-spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LoaderCircle } from "lucide-react";

interface LoadingSpinnerProps {
children: React.ReactNode;
}

export default function LoadingSpinner({ children }: LoadingSpinnerProps) {
return (
<div className="flex flex-row place-content-center gap-1">
<LoaderCircle className="animate-spin" />
{children}
</div>
);
}

0 comments on commit 51d9178

Please sign in to comment.