mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 22:14:08 +01:00
ui: show skeleton instead of loading message
This commit is contained in:
parent
5a246a9627
commit
3df1456c40
@ -7,7 +7,6 @@ import {
|
|||||||
BookOpen,
|
BookOpen,
|
||||||
Bot,
|
Bot,
|
||||||
Command,
|
Command,
|
||||||
Frame,
|
|
||||||
GalleryVerticalEnd,
|
GalleryVerticalEnd,
|
||||||
Map,
|
Map,
|
||||||
PieChart,
|
PieChart,
|
||||||
@ -47,6 +46,29 @@ interface AppSidebarProps extends React.ComponentProps<typeof Sidebar> {
|
|||||||
config?: SidebarConfig;
|
config?: SidebarConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function UserSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center space-x-2 animate-pulse">
|
||||||
|
<div className="w-8 h-8 bg-gray-300 rounded-full" />
|
||||||
|
<div className="w-24 h-4 bg-gray-300 rounded" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
function UserErrorFallback({ message }: { message: string }) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div className="w-8 h-8 bg-red-300 rounded-full flex items-center justify-center">
|
||||||
|
<span role="img" aria-label="error">
|
||||||
|
⚠️
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-red-600">Failed to load user</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function AppSidebar({ config, ...props }: AppSidebarProps) {
|
export function AppSidebar({ config, ...props }: AppSidebarProps) {
|
||||||
const defaultConfig: SidebarConfig = {
|
const defaultConfig: SidebarConfig = {
|
||||||
teams: [
|
teams: [
|
||||||
@ -90,8 +112,12 @@ export function AppSidebar({ config, ...props }: AppSidebarProps) {
|
|||||||
email: data.user.Email,
|
email: data.user.Email,
|
||||||
avatar: data.user.Avatar || "/avatars/avatar.webp",
|
avatar: data.user.Avatar || "/avatars/avatar.webp",
|
||||||
});
|
});
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
|
if (err instanceof Error) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
|
} else {
|
||||||
|
setError("An unexpected error occurred");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@ -110,7 +136,9 @@ export function AppSidebar({ config, ...props }: AppSidebarProps) {
|
|||||||
<NavCrops crops={sidebarConfig.crops} />
|
<NavCrops crops={sidebarConfig.crops} />
|
||||||
</div>
|
</div>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter>{loading ? "Loading..." : error ? error : <NavUser user={user} />}</SidebarFooter>
|
<SidebarFooter>
|
||||||
|
{loading ? <UserSkeleton /> : error ? <UserErrorFallback message={error} /> : <NavUser user={user} />}
|
||||||
|
</SidebarFooter>
|
||||||
<SidebarRail />
|
<SidebarRail />
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user