Skip to content

Commit

Permalink
feat: loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Jul 26, 2024
1 parent ecac1ad commit 22429c5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD_SERVER_BASE_URL=
BUILD_SERVER_BASE_URL=https://playground.test.aelf.dev
GA_TAG=
6 changes: 4 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from "next";
import { Poppins } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@/components/theme-provider";
import { PropsWithChildren } from "react";
import { PropsWithChildren, Suspense } from "react";
import TopMenu from "@/components/top-menu";
import clsx from "clsx";
import { GoogleAnalytics } from "@next/third-parties/google";
Expand Down Expand Up @@ -32,7 +32,9 @@ export default function RootLayout({ children }: PropsWithChildren) {
disableTransitionOnChange
>
<TopMenu />
<main className="h-[calc(100vh-66px)] overflow-auto">{children}</main>
<main className="h-[calc(100vh-66px)] overflow-auto">
<Suspense>{children}</Suspense>
</main>
</ThemeProvider>
</body>
{gaId ? <GoogleAnalytics gaId={gaId} /> : null}
Expand Down
18 changes: 9 additions & 9 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "@radix-ui/react-icons";
import Link from "next/link";
import { ReactNode } from "react";
import { Skeleton } from "@/components/ui/skeleton";

function HomeCard({
title,
Expand All @@ -32,7 +33,6 @@ function HomeCard({
}

export default function Home() {

const links = [
{
title: "Hello World",
Expand Down Expand Up @@ -84,17 +84,17 @@ export default function Home() {
<h3 className="text-xl font-bold">... or generate from a prompt:</h3>
<div className="grid w-full max-w-3xl grid-cols-1 gap-6 md:grid-cols-2">
<div className="rounded-lg border bg-background p-6 shadow-sm">
<img
src="/placeholder.svg"
width={400}
height={225}
alt="Deepchat here"
className="aspect-video object-cover rounded-md"
/>
<div className="flex flex-col space-y-3">
<Skeleton className="h-[125px] w-[250px] rounded-xl" />
<div className="space-y-2">
<Skeleton className="h-4 w-[250px]" />
<Skeleton className="h-4 w-[200px]" />
</div>
</div>
</div>
<div className="space-y-4">
<h4 className="text-2xl font-bold">DeepChat AI</h4>
<p className="text-muted-foreground">Some description.</p>
<p className="text-muted-foreground">Coming soon.</p>
</div>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions app/workspaces/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Skeleton } from "@/components/ui/skeleton";

export default function Loading() {
return (
<div className="container grid grid-cols-1 gap-8 px-4 py-12 md:grid-cols-3 md:gap-12 md:px-6 lg:py-16">
<div>
<h1 className="text-2xl mb-2">Create a new workspace</h1>
<Skeleton className="h-4 w-12 mt-3" />
<Skeleton className="h-8 w-full mt-3" />
</div>
<div className="md:col-span-2">
<h1 className="text-2xl mb-2">Open an existing workspace</h1>
<Skeleton className="h-12 w-12 rounded-full" />
</div>
</div>
);
}
12 changes: 11 additions & 1 deletion components/new-workspace-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from "@/components/ui/select";
import { useRouter } from "next/navigation";
import { db } from "@/data/db";
import { Loader2 } from "lucide-react";

const FormSchema = z.object({
name: z.string().min(2, {
Expand Down Expand Up @@ -128,7 +129,16 @@ export function WorkspaceForm({
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
<Button type="submit" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Please wait
</>
) : (
"Submit"
)}
</Button>
</form>
</Form>
);
Expand Down
15 changes: 15 additions & 0 deletions components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { cn } from "@/lib/utils"

function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
)
}

export { Skeleton }

0 comments on commit 22429c5

Please sign in to comment.