mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-24 21:36:06 +00:00
feat: implement loading states in SpaceOAuthCallback and HomeSidebar components using Suspense
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from 'react';
|
import { useEffect, useState, useCallback, Suspense } from 'react';
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
import { httpClient } from '@/app/infra/http/HttpClient';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import langbotIcon from '@/app/assets/langbot-logo.webp';
|
import langbotIcon from '@/app/assets/langbot-logo.webp';
|
||||||
|
|
||||||
export default function SpaceOAuthCallback() {
|
function SpaceOAuthCallbackContent() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -216,3 +216,23 @@ export default function SpaceOAuthCallback() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LoadingFallback() {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-neutral-900">
|
||||||
|
<Card className="w-[400px] shadow-lg dark:shadow-white/10">
|
||||||
|
<CardContent className="flex flex-col items-center py-12">
|
||||||
|
<Loader2 className="h-12 w-12 animate-spin text-primary" />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SpaceOAuthCallback() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<LoadingFallback />}>
|
||||||
|
<SpaceOAuthCallbackContent />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import styles from './HomeSidebar.module.css';
|
import styles from './HomeSidebar.module.css';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, Suspense } from 'react';
|
||||||
import {
|
import {
|
||||||
SidebarChild,
|
SidebarChild,
|
||||||
SidebarChildVO,
|
SidebarChildVO,
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
Lightbulb,
|
Lightbulb,
|
||||||
LogOut,
|
LogOut,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
|
Loader2,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useTheme } from 'next-themes';
|
import { useTheme } from 'next-themes';
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ function compareVersions(v1: string, v2: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO 侧边导航栏要加动画
|
// TODO 侧边导航栏要加动画
|
||||||
export default function HomeSidebar({
|
function HomeSidebarContent({
|
||||||
onSelectedChangeAction,
|
onSelectedChangeAction,
|
||||||
}: {
|
}: {
|
||||||
onSelectedChangeAction: (sidebarChild: SidebarChildVO) => void;
|
onSelectedChangeAction: (sidebarChild: SidebarChildVO) => void;
|
||||||
@@ -482,3 +483,25 @@ export default function HomeSidebar({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SidebarLoadingFallback() {
|
||||||
|
return (
|
||||||
|
<div className={`${styles.sidebarContainer}`}>
|
||||||
|
<div className="flex items-center justify-center h-full">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function HomeSidebar({
|
||||||
|
onSelectedChangeAction,
|
||||||
|
}: {
|
||||||
|
onSelectedChangeAction: (sidebarChild: SidebarChildVO) => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<SidebarLoadingFallback />}>
|
||||||
|
<HomeSidebarContent onSelectedChangeAction={onSelectedChangeAction} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user