refactor(Layouts): optimize imports and enhance UserInfo component
- Moved the useIsMobile hook import to the correct position in conditional-layout.tsx. - Added type="button" to the ThemeToggleSwitch button for better accessibility. - Introduced truncateString utility in UserInfo component to limit email display length. - Set Image component in UserInfo to unoptimized for performance improvement.
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { AuthGuard, LoginGuard } from "@/contexts";
|
import { AuthGuard, LoginGuard } from "@/contexts";
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import { Header } from "./header";
|
import { Header } from "./header";
|
||||||
import Notification from "./notification";
|
import Notification from "./notification";
|
||||||
import { Sidebar } from "./sidebar";
|
import { Sidebar } from "./sidebar";
|
||||||
import { useIsMobile } from "@/hooks/use-mobile";
|
|
||||||
|
|
||||||
function MainLayout({ children }: PropsWithChildren) {
|
function MainLayout({ children }: PropsWithChildren) {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export function ThemeToggleSwitch() {
|
|||||||
<button
|
<button
|
||||||
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
||||||
className="group rounded-full bg-gray-3 p-[5px] text-[#111928] outline-1 outline-primary focus-visible:outline dark:bg-[#020D1A] dark:text-current"
|
className="group rounded-full bg-gray-3 p-[5px] text-[#111928] outline-1 outline-primary focus-visible:outline dark:bg-[#020D1A] dark:text-current"
|
||||||
|
type="button"
|
||||||
>
|
>
|
||||||
<span className="sr-only">
|
<span className="sr-only">
|
||||||
Switch to {theme === "light" ? "dark" : "light"} mode
|
Switch to {theme === "light" ? "dark" : "light"} mode
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "@/components/ui/dropdown";
|
} from "@/components/ui/dropdown";
|
||||||
import { useUser } from "@/contexts";
|
import { useUser } from "@/contexts";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { truncateString } from "@/utils/shared";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -53,6 +54,7 @@ export function UserInfo() {
|
|||||||
<Image
|
<Image
|
||||||
src={user.profile_image}
|
src={user.profile_image}
|
||||||
className="size-12"
|
className="size-12"
|
||||||
|
unoptimized
|
||||||
alt={`Avatar for ${user.full_name}`}
|
alt={`Avatar for ${user.full_name}`}
|
||||||
role="presentation"
|
role="presentation"
|
||||||
width={200}
|
width={200}
|
||||||
@@ -69,7 +71,9 @@ export function UserInfo() {
|
|||||||
{user?.full_name}
|
{user?.full_name}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="leading-none text-gray-6">{user?.email}</div>
|
<div className="leading-none text-gray-6">
|
||||||
|
{truncateString(user?.email ?? "")}
|
||||||
|
</div>
|
||||||
</figcaption>
|
</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
@@ -107,7 +111,6 @@ export function UserInfo() {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
logout();
|
logout();
|
||||||
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LogOutIcon />
|
<LogOutIcon />
|
||||||
|
|||||||
Reference in New Issue
Block a user