feat: enhance Header component to display user initials and refactor ThemeSwitcher for improved button handling
This commit is contained in:
parent
b4d054de36
commit
e6d8a9ae9e
@ -12,9 +12,25 @@ import {
|
|||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { ThemeSwitcher } from "../ThemeSwitcher/ThemeSwitcher";
|
import { ThemeSwitcher } from "../ThemeSwitcher/ThemeSwitcher";
|
||||||
|
|
||||||
|
const getInitials = (name: string) => {
|
||||||
|
if (!name) return "";
|
||||||
|
|
||||||
|
const nameParts = name.split(" ");
|
||||||
|
if (nameParts.length === 1) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstInitial = nameParts[0]?.[0] || "";
|
||||||
|
const secondInitial = nameParts[1]?.[0] || nameParts[0]?.[1] || "";
|
||||||
|
|
||||||
|
return firstInitial + secondInitial;
|
||||||
|
};
|
||||||
|
|
||||||
export const Header = () => {
|
export const Header = () => {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
|
||||||
|
const initials = session?.user?.name ? getInitials(session.user.name) : "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar className="mb-2">
|
<Navbar className="mb-2">
|
||||||
<NavbarBrand>
|
<NavbarBrand>
|
||||||
@ -29,7 +45,7 @@ export const Header = () => {
|
|||||||
as="button"
|
as="button"
|
||||||
className="transition-transform"
|
className="transition-transform"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
name={session?.user?.name}
|
name={initials}
|
||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</DropdownTrigger>
|
</DropdownTrigger>
|
||||||
|
@ -13,11 +13,12 @@ export const ThemeSwitcher = () => {
|
|||||||
if (!mounted) return null;
|
if (!mounted) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`fixed bottom-4 right-4 rounded-lg ${theme === "light" ? "bg-black" : "bg-white"} p-2`}>
|
<button
|
||||||
{theme === "light" ? (
|
className={`fixed bottom-4 right-4 rounded-lg ${theme === "light" ? "bg-black" : "bg-white"
|
||||||
<button onClick={() => setTheme("dark")}>🌙</button>) : (
|
} p-2`}
|
||||||
<button onClick={() => setTheme("light")}>☀️</button>
|
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
||||||
)}
|
>
|
||||||
</div>
|
{theme === "light" ? "🌙" : "☀️"}
|
||||||
|
</button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user