Refactoring on image and component loading.

This commit is contained in:
charlesgauthereau
2025-12-22 14:23:52 +01:00
parent 3b356e33e7
commit 08f2ad0521
4 changed files with 51 additions and 19 deletions
@@ -1,48 +1,64 @@
"use client"
"use client";
import { useSidebar } from "@/components/ui/sidebar";
import Link from "next/link";
import { useTheme } from "next-themes";
import Image from "next/image";
import { useEffect, useState } from "react";
import {Skeleton} from "@/components/ui/skeleton";
export const SidebarLogo = ({projectName}: {
projectName: string;
}) => {
export const SidebarLogo = ({ projectName }: { projectName: string }) => {
const { state, isMobile } = useSidebar();
const { resolvedTheme } = useTheme();
const [mounted, setMounted] = useState(false);
const [loaded, setLoaded] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) return null;
if (!mounted) return(
<div className="m-4 w-[190px] h-[45px]">
<Skeleton className="w-full h-full bg-transparent" />
</div>
);
const imageTheme = resolvedTheme === "dark" ? "/images/logo-white.png" : "/images/logo-black.png";
const imageTheme =
resolvedTheme === "dark" ? "/images/logo-white.png" : "/images/logo-black.png";
const handleLoad = () => setLoaded(true);
const style = {
transition: "opacity 0.3s ease-in-out",
opacity: loaded ? 1 : 0,
};
return (
<div className="ml-1 flex items-center justify-center">
<Link href={"/dashboard/home"}>
{state === 'collapsed' && !isMobile ? (
<Link href="/dashboard/home">
{state === "collapsed" && !isMobile ? (
<Image
loading="eager"
src={"/images/logo.png"}
src="/images/logo.png"
alt={`Logo ${projectName}`}
className="h-10 w-10 object-contain"
height={10}
width={10}
width={40}
height={40}
loading="eager"
priority
style={style}
onLoad={handleLoad}
/>
) : (
<div className="m-4">
<div className="m-4 w-[190px] h-[45px] ">
<Image
loading="eager"
src={imageTheme}
alt={`Logo ${projectName}`}
className="object-contain"
width={190}
height={90}
loading="eager"
priority
style={style}
onLoad={handleLoad}
/>
</div>
)}
@@ -13,9 +13,12 @@ export function OrganizationCombobox() {
const {data: activeOrganization, refetch: refetchActiveOrga} = authClient.useActiveOrganization();
const [openModal, setOpenModal] = useState(false);
if (!organizations) return null;
// if (!organizations) return null;
// const values = organizations.map(org => ({ value: org.slug, label: org.name }));
const values = organizations?.map(org => ({ value: org.slug, label: org.name })) ?? [];
const values = organizations.map(org => ({ value: org.slug, label: org.name }));
const onValueChange = async (slug: string) => {
await authClient.organization.setActive({ organizationSlug: slug });