Skip to content

Commit 3dd0ec6

Browse files
committed
Added Loading UI when switching page (#1400)
1 parent 724eda8 commit 3dd0ec6

File tree

10 files changed

+395
-392
lines changed

10 files changed

+395
-392
lines changed

app/[lng]/chat/chat.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,16 @@ export default function Chat(props: Props) {
341341
}
342342
>
343343
<div className="flex items-center space-x-2">
344-
<ModelSelector
345-
placeholder={t("model")}
346-
lng={lng}
347-
premium={hasGpt4Access()}
348-
avModels={avModels}
349-
model={model}
350-
setModel={setModel}
351-
/>
344+
<span>
345+
<ModelSelector
346+
placeholder={t("model")}
347+
lng={lng}
348+
premium={hasGpt4Access()}
349+
avModels={avModels}
350+
model={model}
351+
setModel={setModel}
352+
/>
353+
</span>
352354
{messages.length === 1 && (
353355
<Dialog>
354356
<DialogTrigger>

app/[lng]/chat/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Chat from "./chat";
2-
import React from "react";
2+
import React, { Suspense } from "react";
33
import type { Metadata } from "next";
44
import {
55
getUser,
@@ -9,6 +9,7 @@ import {
99
} from "@/utils/supabase/queries";
1010
import { createClient } from "@/utils/supabase/server";
1111
import { DefaultLanguageParams } from "@/lib/languages";
12+
import LoadingUI from "@/components/loading";
1213

1314
export const metadata: Metadata = {
1415
title: "Chat",
@@ -63,6 +64,8 @@ export default async function ChatPage({
6364
}
6465
const q = await getQuotas();
6566
return (
66-
<Chat subscriptions={subscriptions} user={user} lng={lng} quotas={q} />
67+
<Suspense fallback={<LoadingUI />}>
68+
<Chat subscriptions={subscriptions} user={user} lng={lng} quotas={q} />
69+
</Suspense>
6770
);
6871
}

app/[lng]/create/page.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
import Create from "./create";
99
import { createClient } from "@/utils/supabase/server";
1010
import { DefaultLanguageParams } from "@/lib/languages";
11+
import { Suspense } from "react";
12+
import LoadingUI from "@/components/loading";
1113

1214
export default async function CreatePage({
1315
params,
@@ -58,12 +60,14 @@ export default async function CreatePage({
5860
}
5961
const q = await getQuotas();
6062
return (
61-
<Create
62-
products={products}
63-
subscriptions={subscriptions}
64-
user={user}
65-
lng={lng}
66-
quotas={q}
67-
/>
63+
<Suspense fallback={<LoadingUI />}>
64+
<Create
65+
products={products}
66+
subscriptions={subscriptions}
67+
user={user}
68+
lng={lng}
69+
quotas={q}
70+
/>
71+
</Suspense>
6872
);
6973
}

app/[lng]/generations/edit/page.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
"use client";
22
import { Suspense } from "react";
3-
import { Skeleton } from "@/components/ui/skeleton";
43
import GenerationEditPage from "./editpage";
54
import { DefaultLanguageParams } from "@/lib/languages";
5+
import LoadingUI from "@/components/loading";
66

77
export default function ViewPage({
88
params,
99
}: {
1010
params: DefaultLanguageParams;
1111
}) {
1212
return (
13-
<Suspense fallback={LoadingUI()}>
13+
<Suspense fallback={<LoadingUI />}>
1414
<GenerationEditPage params={params} />
1515
</Suspense>
1616
);
1717
}
18-
function LoadingUI() {
19-
return (
20-
<div className="flex h-screen w-screen flex-col items-center justify-center">
21-
<p>Loading...</p>
22-
<div className="space-y-2">
23-
<Skeleton className="h-4 w-[250px]" />
24-
<Skeleton className="h-4 w-[200px]" />
25-
<Skeleton className="h-16 w-[240px]" />
26-
</div>
27-
</div>
28-
);
29-
}

app/[lng]/generations/page.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
"use client";
22
import { Suspense } from "react";
3-
import { Skeleton } from "@/components/ui/skeleton";
43
import GenerationsPage from "./genpage";
54
import { DefaultLanguageParams } from "@/lib/languages";
5+
import LoadingUI from "@/components/loading";
66

77
export default function ViewPage({
88
params,
99
}: {
1010
params: DefaultLanguageParams;
1111
}) {
1212
return (
13-
<Suspense fallback={LoadingUI()}>
13+
<Suspense fallback={<LoadingUI />}>
1414
<GenerationsPage params={params} />
1515
</Suspense>
1616
);
1717
}
18-
function LoadingUI() {
19-
return (
20-
<div className="flex h-screen w-screen flex-col items-center justify-center">
21-
<p>Loading...</p>
22-
<div className="space-y-2">
23-
<Skeleton className="h-4 w-[250px]" />
24-
<Skeleton className="h-4 w-[200px]" />
25-
<Skeleton className="h-16 w-[240px]" />
26-
</div>
27-
</div>
28-
);
29-
}

app/[lng]/generations/view/page.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
"use client";
22
import { Suspense } from "react";
33
import GenerationViewPage from "./viewpage";
4-
import { Skeleton } from "@/components/ui/skeleton";
54
import { DefaultLanguageParams } from "@/lib/languages";
5+
import LoadingUI from "@/components/loading";
66

77
export default function ViewPage({
88
params,
99
}: {
1010
params: DefaultLanguageParams;
1111
}) {
1212
return (
13-
<Suspense fallback={LoadingUI()}>
13+
<Suspense fallback={<LoadingUI />}>
1414
<GenerationViewPage params={params} />
1515
</Suspense>
1616
);
1717
}
18-
function LoadingUI() {
19-
return (
20-
<div className="flex h-screen w-screen flex-col items-center justify-center">
21-
<p>Loading...</p>
22-
<div className="space-y-2">
23-
<Skeleton className="h-4 w-[250px]" />
24-
<Skeleton className="h-4 w-[200px]" />
25-
<Skeleton className="h-16 w-[240px]" />
26-
</div>
27-
</div>
28-
);
29-
}

app/[lng]/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import MobileNavBar from "@/components/mobile-nav";
1010
import { Toaster } from "@/components/ui/toaster";
1111
import { Suspense, use } from "react";
1212
import { DefaultLanguageParams } from "@/lib/languages";
13+
import LoadingUI from "@/components/loading";
1314

1415
const manrope = Manrope({ subsets: ["latin"] });
1516
export async function generateStaticParams() {
@@ -93,7 +94,7 @@ export default function RootLayout({
9394
>
9495
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
9596
<NavBar lng={lng} />
96-
{children}
97+
<Suspense fallback={<LoadingUI />}>{children}</Suspense>
9798
<MobileNavBar lng={lng} />
9899
</ThemeProvider>
99100
<Suspense>

0 commit comments

Comments
 (0)