Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : SPB Private Cloud8 * File : app/dashboard/favorites/page.tsx9 * Module : app10 * Repository : https://git.spboucher.ai/spb-cloud11 * Project Website : https://cloud.spboucher.ai12 * Created : 2026-02-1813 * Last Modified : 2026-09-0714 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142"use client";4344import { useState, useEffect, useCallback } from "react";45import { Star, LayoutGrid, List } from "lucide-react";46import AppShell from "@/components/layout/AppShell";47import FileCard from "@/components/files/FileCard";48import PreviewEngine from "@/components/preview/PreviewEngine";49import PageHeader, { EmptyState } from "@/components/ui/PageHeader";50import PageTransition from "@/components/ui/PageTransition";51import type { FileData } from "@/types/files";5253function GridSkeleton() {54 return (55 <div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3">56 {Array.from({ length: 10 }).map((_, i) => (57 <div key={i} className="card p-0 overflow-hidden animate-pulse">58 <div className="aspect-square bg-gray-100 dark:bg-white/[0.06]" />59 <div className="p-2.5 space-y-1.5">60 <div className="h-3 w-3/4 rounded bg-gray-200 dark:bg-white/10" />61 <div className="h-2 w-1/2 rounded bg-gray-200 dark:bg-white/10" />62 </div>63 </div>64 ))}65 </div>66 );67}6869export default function FavoritesPage() {70 const [files, setFiles] = useState<FileData[]>([]);71 const [previewFile, setPreviewFile] = useState<FileData | null>(null);72 const [loading, setLoading] = useState(true);73 const [viewMode, setViewMode] = useState<"grid" | "list">("grid");7475 const fetchFavorites = useCallback(async () => {76 setLoading(true);77 try {78 const res = await fetch("/api/files?favorite=true&limit=200");79 if (res.ok) {80 const data = await res.json();81 setFiles(Array.isArray(data) ? data : data.files || []);82 }83 } catch {}84 setLoading(false);85 }, []);8687 useEffect(() => { fetchFavorites(); }, [fetchFavorites]);8889 return (90 <AppShell>91 <div className="flex flex-col h-full lg:flex-row">92 <PageTransition className="flex-1 flex flex-col min-w-0">93 <div className="px-4 lg:px-6">94 <PageHeader95 title="Favoris"96 subtitle={loading ? "Chargement…" : `${files.length} fichier${files.length !== 1 ? "s" : ""} marqué${files.length !== 1 ? "s" : ""} d'une étoile`}97 icon={Star}98 tone="text-amber-500 bg-amber-500/10"99 compact100 actions={101 <div className="flex items-center gap-0.5 p-1 rounded-xl bg-gray-100 dark:bg-white/[0.06]">102 {([["grid", LayoutGrid], ["list", List]] as const).map(([m, Icon]) => (103 <button104 key={m}105 onClick={() => setViewMode(m)}106 className={`w-9 h-8 flex items-center justify-center rounded-lg transition-colors ${viewMode === m ? "bg-surface dark:bg-white/10 text-gray-900 dark:text-white shadow-card dark:shadow-none" : "text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"}`}107 aria-label={m === "grid" ? "Vue grille" : "Vue liste"}108 aria-pressed={viewMode === m}109 >110 <Icon className="w-4 h-4" />111 </button>112 ))}113 </div>114 }115 />116 </div>117118 <div className="flex-1 overflow-auto px-4 lg:px-6 pb-6">119 {loading ? (120 <GridSkeleton />121 ) : files.length === 0 ? (122 <EmptyState icon={Star} title="Aucun favori" description="Marquez des fichiers d'une étoile pour les retrouver ici en un clin d'œil." />123 ) : viewMode === "grid" ? (124 <div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3">125 {files.map((file) => (126 <FileCard key={file.id} file={file} onPreview={setPreviewFile} onRefresh={fetchFavorites} viewMode="grid" />127 ))}128 </div>129 ) : (130 <div className="card p-0 overflow-hidden divide-y divide-line dark:divide-white/[0.06]">131 {files.map((file) => (132 <FileCard key={file.id} file={file} onPreview={setPreviewFile} onRefresh={fetchFavorites} viewMode="list" />133 ))}134 </div>135 )}136 </div>137 </PageTransition>138139 {previewFile && (140 <div className="fixed inset-0 z-50 lg:relative lg:inset-auto lg:w-[420px] lg:border-l lg:border-line dark:lg:border-white/[0.07]">141 <PreviewEngine file={previewFile} files={files} onClose={() => setPreviewFile(null)} onNavigate={setPreviewFile} />142 </div>143 )}144 </div>145 </AppShell>146 );147}148