feat(ui): add responsive mobile header and footer components
- Implemented `MobileHeader` with support for displaying unread messages. - Created `MobileFooter` with navigation to key sections (home, explore, publish, trends, profile). - Replaced legacy mobile header with new `MobileHeader` and `MobileFooter` in the dashboard layout. - Optimized mobile sidebar rendering for improved responsiveness.
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import * as React from "react";
|
||||
import { AppSidebar } from "@/components/app-sidebar";
|
||||
import { MobileFilters } from "@/components/mobile-filters";
|
||||
import { ModeToggle } from "@/components/mode-toggle";
|
||||
import { MobileFooter } from "@/components/mobile-footer";
|
||||
import { MobileHeader } from "@/components/mobile-header";
|
||||
import { SearchSidebar } from "@/components/search-sidebar";
|
||||
import {
|
||||
SidebarInset,
|
||||
SidebarProvider,
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
import { UserNavMobile } from "@/components/user-nav-mobile";
|
||||
|
||||
export default function DashboardLayout({
|
||||
children,
|
||||
@@ -22,20 +18,9 @@ export default function DashboardLayout({
|
||||
<React.Suspense fallback={null}>
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<SidebarInset className="flex flex-row overflow-hidden">
|
||||
<SidebarInset className="flex flex-row overflow-hidden pb-16 lg:pb-0">
|
||||
<div className="flex-1 flex flex-col min-w-0">
|
||||
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4 lg:hidden sticky top-0 bg-background z-40">
|
||||
<SidebarTrigger />
|
||||
<div className="flex-1 flex justify-center">
|
||||
<span className="font-bold text-primary text-xl tracking-tight">
|
||||
MemeGoat
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ModeToggle />
|
||||
<UserNavMobile />
|
||||
</div>
|
||||
</header>
|
||||
<MobileHeader />
|
||||
<main className="flex-1 overflow-y-auto bg-zinc-50 dark:bg-zinc-950">
|
||||
{children}
|
||||
{modal}
|
||||
@@ -43,6 +28,7 @@ export default function DashboardLayout({
|
||||
<React.Suspense fallback={null}>
|
||||
<MobileFilters />
|
||||
</React.Suspense>
|
||||
<MobileFooter />
|
||||
</div>
|
||||
<React.Suspense fallback={null}>
|
||||
<SearchSidebar />
|
||||
|
||||
@@ -3,16 +3,19 @@
|
||||
import {
|
||||
Calendar,
|
||||
Camera,
|
||||
HelpCircle,
|
||||
LogIn,
|
||||
LogOut,
|
||||
Settings,
|
||||
Share2,
|
||||
ShieldCheck,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import { ContentList } from "@/components/content-list";
|
||||
import { ModeToggle } from "@/components/mode-toggle";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -157,6 +160,19 @@ export default function ProfilePage() {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap justify-center md:justify-start gap-2 pt-2">
|
||||
{user.role === "admin" && (
|
||||
<Button
|
||||
asChild
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9 px-4 border-primary/20 hover:bg-primary/5 text-primary"
|
||||
>
|
||||
<Link href="/admin">
|
||||
<ShieldCheck className="h-4 w-4 mr-2" />
|
||||
Administration
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
<Button asChild variant="outline" size="sm" className="h-9 px-4">
|
||||
<Link href="/settings">
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
@@ -181,6 +197,14 @@ export default function ProfilePage() {
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
Déconnexion
|
||||
</Button>
|
||||
|
||||
<Button asChild variant="outline" size="sm" className="h-9 px-4">
|
||||
<Link href="/help">
|
||||
<HelpCircle className="h-4 w-4 mr-2" />
|
||||
Aide
|
||||
</Link>
|
||||
</Button>
|
||||
<ModeToggle />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
SidebarRail,
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
import { useSocket } from "@/providers/socket-provider";
|
||||
import { CategoryService } from "@/services/category.service";
|
||||
@@ -79,6 +80,7 @@ const mainNav = [
|
||||
];
|
||||
|
||||
export function AppSidebar() {
|
||||
const isMobile = useIsMobile();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const { user, logout, isAuthenticated } = useAuth();
|
||||
@@ -129,6 +131,8 @@ export function AppSidebar() {
|
||||
: "/memegoat-black.svg";
|
||||
}, [resolvedTheme, mounted]);
|
||||
|
||||
if (isMobile) return null;
|
||||
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarHeader className="flex flex-row items-center justify-between py-4 group-data-[collapsible=icon]:justify-center">
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { Filter, Search } from "lucide-react";
|
||||
import { Search } from "lucide-react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -13,7 +12,6 @@ import {
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
SheetTrigger,
|
||||
} from "@/components/ui/sheet";
|
||||
import { CategoryService } from "@/services/category.service";
|
||||
import { TagService } from "@/services/tag.service";
|
||||
@@ -29,6 +27,16 @@ export function MobileFilters() {
|
||||
const [query, setQuery] = React.useState(searchParams.get("query") || "");
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (searchParams.get("openSearch") === "true") {
|
||||
setOpen(true);
|
||||
// Nettoyer l'URL sans recharger
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.delete("openSearch");
|
||||
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
}
|
||||
}, [searchParams, pathname, router]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (open) {
|
||||
CategoryService.getAll().then(setCategories).catch(console.error);
|
||||
@@ -61,13 +69,8 @@ export function MobileFilters() {
|
||||
const currentCategory = searchParams.get("category");
|
||||
|
||||
return (
|
||||
<div className="lg:hidden fixed top-4 right-4 z-50">
|
||||
<div className="lg:hidden">
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger asChild>
|
||||
<Button size="icon" className="rounded-full shadow-lg h-12 w-12">
|
||||
<Filter className="h-6 w-6" />
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="right" className="w-[300px] sm:w-[400px]">
|
||||
<SheetHeader>
|
||||
<SheetTitle>Recherche & Filtres</SheetTitle>
|
||||
|
||||
80
frontend/src/components/mobile-footer.tsx
Normal file
80
frontend/src/components/mobile-footer.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
|
||||
import { Home, PlusCircle, Search, TrendingUp, User } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
|
||||
export function MobileFooter() {
|
||||
const pathname = usePathname();
|
||||
const { user, isAuthenticated } = useAuth();
|
||||
|
||||
const navItems = [
|
||||
{
|
||||
title: "Accueil",
|
||||
url: "/",
|
||||
icon: Home,
|
||||
},
|
||||
{
|
||||
title: "Explorer",
|
||||
url: "/trends?openSearch=true",
|
||||
icon: Search,
|
||||
},
|
||||
{
|
||||
title: "Publier",
|
||||
url: "/upload",
|
||||
icon: PlusCircle,
|
||||
},
|
||||
{
|
||||
title: "Tendances",
|
||||
url: "/trends",
|
||||
icon: TrendingUp,
|
||||
},
|
||||
{
|
||||
title: "Profil",
|
||||
url: "/profile",
|
||||
icon: User,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<footer className="lg:hidden fixed bottom-0 left-0 right-0 border-t bg-background z-40 h-16">
|
||||
<nav className="flex h-full items-center justify-around px-2">
|
||||
{navItems.map((item) => {
|
||||
const isActive = pathname === item.url.split("?")[0];
|
||||
const isProfile = item.title === "Profil";
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={item.url}
|
||||
href={item.url}
|
||||
className={cn(
|
||||
"flex flex-1 flex-col items-center justify-center gap-1 transition-colors min-h-[44px]",
|
||||
isActive ? "text-primary" : "text-muted-foreground hover:text-primary",
|
||||
)}
|
||||
>
|
||||
{isProfile && isAuthenticated && user ? (
|
||||
<Avatar
|
||||
className={cn(
|
||||
"h-6 w-6 border",
|
||||
isActive && "ring-2 ring-primary ring-offset-2",
|
||||
)}
|
||||
>
|
||||
<AvatarImage src={user.avatarUrl} alt={user.username} />
|
||||
<AvatarFallback className="text-[8px]">
|
||||
{user.username.slice(0, 2).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
) : (
|
||||
<item.icon className={cn("h-6 w-6", isActive && "fill-current")} />
|
||||
)}
|
||||
<span className="text-[10px] font-medium">{item.title}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
66
frontend/src/components/mobile-header.tsx
Normal file
66
frontend/src/components/mobile-header.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { MessageCircle } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
import { useSocket } from "@/providers/socket-provider";
|
||||
import { MessageService } from "@/services/message.service";
|
||||
|
||||
export function MobileHeader() {
|
||||
const pathname = usePathname();
|
||||
const { isAuthenticated } = useAuth();
|
||||
const { socket } = useSocket();
|
||||
const [unreadMessages, setUnreadMessages] = React.useState(0);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
MessageService.getUnreadCount().then(setUnreadMessages).catch(console.error);
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (socket && isAuthenticated) {
|
||||
const handleNewMessage = () => {
|
||||
if (pathname !== "/messages") {
|
||||
setUnreadMessages((prev) => prev + 1);
|
||||
}
|
||||
};
|
||||
socket.on("new_message", handleNewMessage);
|
||||
return () => {
|
||||
socket.off("new_message", handleNewMessage);
|
||||
};
|
||||
}
|
||||
}, [socket, isAuthenticated, pathname]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (pathname === "/messages") {
|
||||
setUnreadMessages(0);
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<header className="flex h-16 shrink-0 items-center justify-between border-b px-4 lg:hidden sticky top-0 bg-background z-40">
|
||||
<Link href="/" className="flex items-center gap-2">
|
||||
<span className="font-bold text-primary text-xl tracking-tight">
|
||||
MemeGoat
|
||||
</span>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="ghost" size="icon" asChild className="h-9 w-9 relative">
|
||||
<Link href="/messages">
|
||||
<MessageCircle className="h-5 w-5" />
|
||||
{unreadMessages > 0 && (
|
||||
<span className="absolute top-1 right-1 flex h-4 w-4 items-center justify-center rounded-full bg-red-500 text-[10px] text-white">
|
||||
{unreadMessages > 9 ? "9+" : unreadMessages}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user