feat(ui): enhance mobile user experience and authentication handling
Add `UserNavMobile` component for improved mobile navigation. Update dashboard and profile pages to include authentication checks with loading states and login prompts. Introduce category-specific content tabs on the profile page. Apply sidebar enhancements, including new sections for user favorites and memes.
This commit is contained in:
@@ -2,6 +2,7 @@ import * as React from "react";
|
|||||||
import { AppSidebar } from "@/components/app-sidebar";
|
import { AppSidebar } from "@/components/app-sidebar";
|
||||||
import { MobileFilters } from "@/components/mobile-filters";
|
import { MobileFilters } from "@/components/mobile-filters";
|
||||||
import { SearchSidebar } from "@/components/search-sidebar";
|
import { SearchSidebar } from "@/components/search-sidebar";
|
||||||
|
import { UserNavMobile } from "@/components/user-nav-mobile";
|
||||||
import {
|
import {
|
||||||
SidebarInset,
|
SidebarInset,
|
||||||
SidebarProvider,
|
SidebarProvider,
|
||||||
@@ -16,13 +17,17 @@ export default function DashboardLayout({
|
|||||||
modal: React.ReactNode;
|
modal: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
|
<React.Suspense fallback={null}>
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
<SidebarInset className="flex flex-row overflow-hidden">
|
<SidebarInset className="flex flex-row overflow-hidden">
|
||||||
<div className="flex-1 flex flex-col min-w-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">
|
<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 />
|
<SidebarTrigger />
|
||||||
<div className="flex-1" />
|
<div className="flex-1 flex justify-center">
|
||||||
|
<span className="font-bold text-primary text-lg">MemeGoat</span>
|
||||||
|
</div>
|
||||||
|
<UserNavMobile />
|
||||||
</header>
|
</header>
|
||||||
<main className="flex-1 overflow-y-auto bg-zinc-50 dark:bg-zinc-950">
|
<main className="flex-1 overflow-y-auto bg-zinc-50 dark:bg-zinc-950">
|
||||||
{children}
|
{children}
|
||||||
@@ -37,5 +42,6 @@ export default function DashboardLayout({
|
|||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</SidebarInset>
|
</SidebarInset>
|
||||||
</SidebarProvider>
|
</SidebarProvider>
|
||||||
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Calendar, LogOut, Settings } from "lucide-react";
|
import { Calendar, LogIn, LogOut, Settings } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ContentList } from "@/components/content-list";
|
import { ContentList } from "@/components/content-list";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import { useAuth } from "@/providers/auth-provider";
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
import { ContentService } from "@/services/content.service";
|
import { ContentService } from "@/services/content.service";
|
||||||
import { FavoriteService } from "@/services/favorite.service";
|
import { FavoriteService } from "@/services/favorite.service";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
|
|
||||||
export default function ProfilePage() {
|
export default function ProfilePage() {
|
||||||
const { user, isAuthenticated, isLoading, logout } = useAuth();
|
const { user, isAuthenticated, isLoading, logout } = useAuth();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const tab = searchParams.get("tab") || "memes";
|
||||||
|
|
||||||
const fetchMyMemes = React.useCallback(
|
const fetchMyMemes = React.useCallback(
|
||||||
(params: { limit: number; offset: number }) =>
|
(params: { limit: number; offset: number }) =>
|
||||||
@@ -26,9 +30,36 @@ export default function ProfilePage() {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isLoading) return null;
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-[400px] items-center justify-center">
|
||||||
|
<Spinner className="h-8 w-8 text-primary" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAuthenticated || !user) {
|
if (!isAuthenticated || !user) {
|
||||||
redirect("/login");
|
return (
|
||||||
|
<div className="max-w-2xl mx-auto py-8 px-4 text-center">
|
||||||
|
<Card className="p-12">
|
||||||
|
<CardHeader>
|
||||||
|
<div className="mx-auto bg-primary/10 p-4 rounded-full w-fit mb-4">
|
||||||
|
<LogIn className="h-8 w-8 text-primary" />
|
||||||
|
</div>
|
||||||
|
<CardTitle>Profil inaccessible</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Vous devez être connecté pour voir votre profil, vos mèmes et vos
|
||||||
|
favoris.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Button asChild className="w-full sm:w-auto">
|
||||||
|
<Link href="/login">Se connecter</Link>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -79,10 +110,14 @@ export default function ProfilePage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Tabs defaultValue="memes" className="w-full">
|
<Tabs value={tab} className="w-full">
|
||||||
<TabsList className="grid w-full grid-cols-2 mb-8">
|
<TabsList className="grid w-full grid-cols-2 mb-8">
|
||||||
<TabsTrigger value="memes">Mes Mèmes</TabsTrigger>
|
<TabsTrigger value="memes" asChild>
|
||||||
<TabsTrigger value="favorites">Mes Favoris</TabsTrigger>
|
<Link href="/profile?tab=memes">Mes Mèmes</Link>
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="favorites" asChild>
|
||||||
|
<Link href="/profile?tab=favorites">Mes Favoris</Link>
|
||||||
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<TabsContent value="memes">
|
<TabsContent value="memes">
|
||||||
<ContentList fetchFn={fetchMyMemes} />
|
<ContentList fetchFn={fetchMyMemes} />
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Image as ImageIcon, Loader2, Upload, X } from "lucide-react";
|
import { Image as ImageIcon, Loader2, LogIn, Upload, X } from "lucide-react";
|
||||||
import NextImage from "next/image";
|
import NextImage from "next/image";
|
||||||
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -27,8 +28,10 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
import { CategoryService } from "@/services/category.service";
|
import { CategoryService } from "@/services/category.service";
|
||||||
import { ContentService } from "@/services/content.service";
|
import { ContentService } from "@/services/content.service";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import type { Category } from "@/types/content";
|
import type { Category } from "@/types/content";
|
||||||
|
|
||||||
const uploadSchema = z.object({
|
const uploadSchema = z.object({
|
||||||
@@ -42,6 +45,7 @@ type UploadFormValues = z.infer<typeof uploadSchema>;
|
|||||||
|
|
||||||
export default function UploadPage() {
|
export default function UploadPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { isAuthenticated, isLoading } = useAuth();
|
||||||
const [categories, setCategories] = React.useState<Category[]>([]);
|
const [categories, setCategories] = React.useState<Category[]>([]);
|
||||||
const [file, setFile] = React.useState<File | null>(null);
|
const [file, setFile] = React.useState<File | null>(null);
|
||||||
const [preview, setPreview] = React.useState<string | null>(null);
|
const [preview, setPreview] = React.useState<string | null>(null);
|
||||||
@@ -57,8 +61,42 @@ export default function UploadPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (isAuthenticated) {
|
||||||
CategoryService.getAll().then(setCategories).catch(console.error);
|
CategoryService.getAll().then(setCategories).catch(console.error);
|
||||||
}, []);
|
}
|
||||||
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-[400px] items-center justify-center">
|
||||||
|
<Spinner className="h-8 w-8 text-primary" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
return (
|
||||||
|
<div className="max-w-2xl mx-auto py-8 px-4">
|
||||||
|
<Card className="text-center p-12">
|
||||||
|
<CardHeader>
|
||||||
|
<div className="mx-auto bg-primary/10 p-4 rounded-full w-fit mb-4">
|
||||||
|
<LogIn className="h-8 w-8 text-primary" />
|
||||||
|
</div>
|
||||||
|
<CardTitle>Connexion requise</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Vous devez être connecté pour partager vos meilleurs mèmes avec la
|
||||||
|
communauté.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Button asChild className="w-full sm:w-auto">
|
||||||
|
<Link href="/login">Se connecter</Link>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const selectedFile = e.target.files?.[0];
|
const selectedFile = e.target.files?.[0];
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
import {
|
import {
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Clock,
|
Clock,
|
||||||
|
Heart,
|
||||||
HelpCircle,
|
HelpCircle,
|
||||||
|
History,
|
||||||
Home,
|
Home,
|
||||||
LayoutGrid,
|
LayoutGrid,
|
||||||
LogIn,
|
LogIn,
|
||||||
@@ -14,7 +16,7 @@ import {
|
|||||||
User as UserIcon,
|
User as UserIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import {
|
import {
|
||||||
@@ -68,6 +70,7 @@ const mainNav = [
|
|||||||
|
|
||||||
export function AppSidebar() {
|
export function AppSidebar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const { user, logout, isAuthenticated } = useAuth();
|
const { user, logout, isAuthenticated } = useAuth();
|
||||||
const [categories, setCategories] = React.useState<Category[]>([]);
|
const [categories, setCategories] = React.useState<Category[]>([]);
|
||||||
|
|
||||||
@@ -149,6 +152,36 @@ export function AppSidebar() {
|
|||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
|
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Ma Bibliothèque</SidebarGroupLabel>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
isActive={pathname === "/profile" && searchParams.get("tab") === "favorites"}
|
||||||
|
tooltip="Mes Favoris"
|
||||||
|
>
|
||||||
|
<Link href="/profile?tab=favorites">
|
||||||
|
<Heart />
|
||||||
|
<span>Mes Favoris</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
isActive={pathname === "/profile" && searchParams.get("tab") === "memes"}
|
||||||
|
tooltip="Mes Mèmes"
|
||||||
|
>
|
||||||
|
<Link href="/profile?tab=memes">
|
||||||
|
<History />
|
||||||
|
<span>Mes Mèmes</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroup>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter>
|
<SidebarFooter>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
|
|||||||
39
frontend/src/components/user-nav-mobile.tsx
Normal file
39
frontend/src/components/user-nav-mobile.tsx
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { LogIn, User as UserIcon } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import * as React from "react";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
|
|
||||||
|
export function UserNavMobile() {
|
||||||
|
const { user, isAuthenticated, isLoading } = useAuth();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <div className="h-8 w-8 rounded-full bg-zinc-200 animate-pulse" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAuthenticated || !user) {
|
||||||
|
return (
|
||||||
|
<Button variant="ghost" size="icon" asChild className="h-9 w-9">
|
||||||
|
<Link href="/login">
|
||||||
|
<LogIn className="h-5 w-5" />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button variant="ghost" size="icon" asChild className="h-9 w-9 p-0">
|
||||||
|
<Link href="/profile">
|
||||||
|
<Avatar className="h-8 w-8 border">
|
||||||
|
<AvatarImage src={user.avatarUrl} alt={user.username} />
|
||||||
|
<AvatarFallback>
|
||||||
|
{user.username.slice(0, 2).toUpperCase()}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user