diff --git a/.gitignore b/.gitignore index 5ef6a52..45254b6 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +/app/generated/prisma diff --git a/README.md b/README.md index e215bc4..9baee9a 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,4 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. +Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. \ No newline at end of file diff --git a/app/[id]/page.tsx b/app/[id]/page.tsx new file mode 100644 index 0000000..6298ec4 --- /dev/null +++ b/app/[id]/page.tsx @@ -0,0 +1,330 @@ +'use client'; + +import { + CalendarDays, + Copy, + Download, + Eye, + FileText, + Plus, +} from 'lucide-react'; +import { useRouter } from 'next/navigation'; +import { useEffect, useRef, useState } from 'react'; + +import Prism from 'prismjs'; +import 'prismjs/components/prism-bash'; +import 'prismjs/components/prism-javascript'; +import 'prismjs/components/prism-json'; +import 'prismjs/components/prism-python'; +import 'prismjs/components/prism-typescript'; +import 'prismjs/themes/prism-tomorrow.css'; + +import 'prismjs/plugins/line-numbers/prism-line-numbers.css'; +import 'prismjs/plugins/line-numbers/prism-line-numbers.js'; + +/** ---------- Loader animé (spinner + skeletons) ---------- */ +function LoadingPaste() { + return ( +
+ {/* Zone code (skeleton lignes) */} +
+
+
+
+ Chargement du paste… +
+
+ {Array.from({ length: 28 }).map((_, i) => ( +
+ ))} +
+
+
+ + {/* Sidebar (skeleton cartes + boutons) */} +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ {Array.from({ length: 4 }).map((_, i) => ( +
+ ))} +
+ +
+
+
+ ); +} +/** -------------------------------------------------------- */ + +export default function PastePage({ params }: { params: { id: string } }) { + const [paste, setPaste] = useState(null); + const [error, setError] = useState(''); + const [loading, setLoading] = useState(true); + const [language, setLanguage] = useState('language-javascript'); + const [copied, setCopied] = useState(false); + + const codeRef = useRef(null); + const router = useRouter(); + + const fetchPaste = async (pwd?: string) => { + setLoading(true); + const res = await fetch(`/api/paste/${params.id}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ password: pwd || '' }), + }); + + if (res.status === 403) { + setError('Invalid password.'); + setLoading(false); + return; + } + if (res.status === 404) { + setError('Paste not found or expired.'); + setLoading(false); + return; + } + + const data = await res.json(); + setPaste(data); + + if (data.content.includes('function') || data.content.includes('const')) { + setLanguage('language-javascript'); + } else if (data.content.includes('import') || data.content.includes('export')) { + setLanguage('language-typescript'); + } else if (data.content.includes('{') && data.content.includes('}')) { + setLanguage('language-json'); + } else { + setLanguage('language-bash'); + } + + setLoading(false); + }; + + useEffect(() => { + fetchPaste(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + useEffect(() => { + if (paste?.content) { + Prism.highlightAll(); + } + }, [paste]); + + // 👉 Remplace l'ancien message "Loading..." par le loader animé + if (loading) return ; + + if (error || (paste?.protected && !paste?.content)) { + return ( +
+
{ + e.preventDefault(); + fetchPaste((e.currentTarget as any).password.value); + }} + className=" + w-full max-w-sm rounded-2xl p-6 space-y-4 + backdrop-blur-xl shadow-2xl + bg-[linear-gradient(to_bottom_right,rgba(20,24,38,0.9),rgba(14,16,24,0.9))] + ring-1 ring-white/10 + " + > +

+ 🔒 Protected Paste +

+ {error &&

{error}

} + + + + +
+
+ ); + } + + return ( +
+
+
+          
+            {paste.content}
+          
+        
+
+ +
+
+
+

+ AltBin +

+ +
+ {paste.title && ( +

+ {paste.title} +

+ )} +
+ +
+
+ +
+
Views
+
{paste.views}
+
+
+
+ +
+
Created
+
+ {new Date(paste.createdAt).toLocaleDateString()} +
+
+
+
+ +
+ +
+ + + + + + + +
+ +
+ Copied! +
+
+
+ ); +} \ No newline at end of file diff --git a/app/about/page.tsx b/app/about/page.tsx new file mode 100644 index 0000000..4eced33 --- /dev/null +++ b/app/about/page.tsx @@ -0,0 +1,173 @@ +"use client"; + +import { Player } from "@lordicon/react"; +import { motion } from "framer-motion"; +import { ArrowLeft } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { forwardRef, useEffect, useRef, useState } from "react"; + +// URLs d’icônes Lordicon +const icons = { + simplicity: "https://cdn.lordicon.com/tsrgicte.json", // simplicité + shield: "https://cdn.lordicon.com/sjoccsdj.json", // sécurité + community: "https://cdn.lordicon.com/ubpgwkmy.json", // communauté / open source + github: "https://cdn.lordicon.com/jjxzcivr.json", // GitHub + discord: "https://cdn.lordicon.com/zvnxzuwv.json", // Discord +}; + +// Wrapper pour Lordicon +const LordIcon = forwardRef(function LordIcon( + { url, size = 30, colorize = "#3b82f6" }: { url: string; size?: number; colorize?: string }, + ref: any +) { + const [iconData, setIconData] = useState(null); + + useEffect(() => { + fetch(url).then((res) => res.json()).then(setIconData); + }, [url]); + + if (!iconData) return null; + return ; +}); + +// Carte Feature +function FeatureCard({ + title, + desc, + icon, +}: { + title: string; + desc: string; + icon: string; +}) { + const iconRef = useRef(null); + + return ( + iconRef.current?.playFromBeginning()} + onMouseLeave={() => iconRef.current?.goToFirstFrame()} + > +
+
+ +
+

{title}

+
+

{desc}

+
+ ); +} + +// Bouton Contact +function ContactButton({ + href, + icon, + text, + gradient, + shadow, + color = "#fff", +}: { + href: string; + icon: string; + text: string; + gradient: string; + shadow: string; + color?: string; +}) { + const iconRef = useRef(null); + + return ( + iconRef.current?.playFromBeginning()} + onMouseLeave={() => iconRef.current?.goToFirstFrame()} + > + + {text} + + ); +} + +export default function AboutPage() { + const router = useRouter(); + + const features = [ + { + title: "Simplicity", + desc: "Create a paste in seconds, distraction-free.", + icon: icons.simplicity, + }, + { + title: "Security", + desc: "Protect your posts with a password or limited number of views.", + icon: icons.shield, + }, + { + title: "Open Source", + desc: "Contribute to the project and improve the platform.", + icon: icons.community, + }, + ]; + + return ( +
+ {/* Navbar */} +
+ router.back()} + className="cursor-pointer inline-flex items-center gap-2 px-5 py-2 rounded-xl text-sm font-medium + text-white bg-gradient-to-r from-blue-600 to-blue-500 shadow-lg shadow-blue-500/30 + hover:shadow-blue-500/50 transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-blue-400/60" + > + + Back + + +

AltBin

+
+ + {/* Features */} +
+ {features.map((f, i) => ( + + ))} +
+ + {/* Contact */} +
+

Contact

+

+ Any questions or{" "} + suggestions? + Join the community or check out the source code +

+ +
+ + +
+
+
+ ); +} \ No newline at end of file diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..9f3894a --- /dev/null +++ b/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,25 @@ +import NextAuth, { NextAuthOptions } from 'next-auth'; +import DiscordProvider from 'next-auth/providers/discord'; + +export const authOptions: NextAuthOptions = { + providers: [ + DiscordProvider({ + clientId: process.env.DISCORD_CLIENT_ID!, + clientSecret: process.env.DISCORD_CLIENT_SECRET!, + }), + ], + callbacks: { + async session({ session, token }) { + if (session.user && token.sub) { + session.user.id = token.sub; + } else { + session.user.id = ''; + } + return session; + }, +} +}; + +const handler = NextAuth(authOptions); + +export { handler as GET, handler as POST }; diff --git a/app/api/paste/[id]/page.tsx b/app/api/paste/[id]/page.tsx new file mode 100644 index 0000000..f7a21c9 --- /dev/null +++ b/app/api/paste/[id]/page.tsx @@ -0,0 +1,30 @@ +import { prisma } from '@/lib/prisma'; + +interface Props { + params: { id: string }; +} + +export default async function PastePage({ params }: Props) { + const paste = await prisma.paste.findUnique({ + where: { id: params.id }, + select: { title: true, content: true, createdAt: true, views: true }, + }); + + if (!paste) return
Paste not found
; + + return ( +
+

+ {paste.title || 'Untitled'} +

+ +
+        {paste.content}
+      
+ +

+ Views: {paste.views} · Created at: {new Date(paste.createdAt).toLocaleString()} +

+
+ ); +} diff --git a/app/api/paste/[id]/route.ts b/app/api/paste/[id]/route.ts new file mode 100644 index 0000000..2c46997 --- /dev/null +++ b/app/api/paste/[id]/route.ts @@ -0,0 +1,68 @@ +import { prisma } from '@/lib/prisma'; +import bcrypt from 'bcryptjs'; +import { NextRequest, NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; +export const revalidate = 0; + +export async function POST( + request: NextRequest, + context: { params: { id: string } } +) { + const { params } = context; + const pasteId = params.id; + + const { password = '' } = await request.json(); + + if (!pasteId) { + return NextResponse.json({ error: 'Invalid ID' }, { status: 400 }); + } + + const paste = await prisma.paste.findUnique({ where: { id: pasteId } }); + if (!paste) { + return NextResponse.json({ error: 'Not found' }, { status: 404 }); + } + + if (paste.maxViews !== null && paste.views >= paste.maxViews) { + await prisma.paste.delete({ where: { id: paste.id } }); + return NextResponse.json({ error: 'Max views exceeded' }, { status: 404 }); + } + + if (paste.password) { + const valid = await bcrypt.compare(password, paste.password); + if (!valid) { + return NextResponse.json({ error: 'Invalid password' }, { status: 403 }); + } + } + + const updated = await prisma.paste.update({ + where: { id: paste.id }, + data: { views: { increment: 1 } }, + select: { + id: true, + title: true, + content: true, + createdAt: true, + views: true, + maxViews: true, + password: true, + }, + }); + + const payload = { + id: updated.id, + title: updated.title, + content: updated.content, + createdAt: updated.createdAt, + views: updated.views, + protected: !!updated.password, + }; + + if (updated.maxViews !== null && updated.views >= updated.maxViews) { + prisma.paste.delete({ where: { id: updated.id } }).catch(() => {}); + } + + return NextResponse.json(payload, { + headers: { 'Cache-Control': 'no-store' }, + }); +} diff --git a/app/api/paste/route.ts b/app/api/paste/route.ts new file mode 100644 index 0000000..a830ff7 --- /dev/null +++ b/app/api/paste/route.ts @@ -0,0 +1,61 @@ +import { prisma } from '@/lib/prisma'; +import bcrypt from 'bcryptjs'; +import { getServerSession } from 'next-auth'; +import { NextResponse } from 'next/server'; +import { authOptions } from '../auth/[...nextauth]/route'; + +import { customAlphabet } from 'nanoid'; +const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 7); + +export async function POST(req: Request) { + const body = await req.json(); + const session = await getServerSession(authOptions); + + let hashedPassword = null; + if (body.password) { + hashedPassword = await bcrypt.hash(body.password, 10); + } + + const paste = await prisma.paste.create({ + data: { + id: nanoid(), + title: body.title || null, + content: body.content, + password: hashedPassword, + maxViews: body.maxViews ? parseInt(body.maxViews, 10) : null, + createdBy: session?.user?.id ?? null, + size: Buffer.byteLength(body.content, 'utf8'), + }, + }); + + return NextResponse.json(paste); +} + +export async function DELETE(req: Request) { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const { searchParams } = new URL(req.url); + const id = searchParams.get("id"); + + if (!id) { + return NextResponse.json({ error: "Missing id" }, { status: 400 }); + } + + try { + const paste = await prisma.paste.findUnique({ where: { id } }); + + if (!paste || paste.createdBy !== session.user.id) { + return NextResponse.json({ error: "Not found" }, { status: 404 }); + } + + await prisma.paste.delete({ where: { id } }); + + return NextResponse.json({ success: true }); + } catch (error) { + console.error(error); + return NextResponse.json({ error: "Server error" }, { status: 500 }); + } +} diff --git a/app/api/stats/route.ts b/app/api/stats/route.ts new file mode 100644 index 0000000..2ed2489 --- /dev/null +++ b/app/api/stats/route.ts @@ -0,0 +1,10 @@ +import { getDashboardStats } from '@/lib/stats'; +import { getServerSession } from 'next-auth'; +import { NextResponse } from 'next/server'; +import { authOptions } from '../auth/[...nextauth]/route'; + +export async function GET() { + const session = await getServerSession(authOptions); + const stats = await getDashboardStats(session?.user?.id); + return NextResponse.json(stats); +} diff --git a/app/api/user-pastes/route.ts b/app/api/user-pastes/route.ts new file mode 100644 index 0000000..d2490f0 --- /dev/null +++ b/app/api/user-pastes/route.ts @@ -0,0 +1,45 @@ +import { authOptions } from '@/app/api/auth/[...nextauth]/route'; +import { prisma } from '@/lib/prisma'; +import { getServerSession } from 'next-auth'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json([], { status: 401 }); + } + + const { searchParams } = new URL(req.url); + + const page = parseInt(searchParams.get('page') || '1', 10); + const perPage = parseInt(searchParams.get('perPage') || '10', 10); + const skip = (page - 1) * perPage; + + const search = searchParams.get('q') || ''; + + const filter = { + createdBy: session.user.id, + ...(search + ? { + title: { + contains: search, + mode: 'insensitive', + }, + } + : {}), + }; + + const [pastes, total] = await Promise.all([ + prisma.paste.findMany({ + where: filter, + orderBy: { createdAt: 'desc' }, + skip, + take: perPage, + }), + prisma.paste.count({ + where: filter, + }), + ]); + + return NextResponse.json({ pastes, total }); +} diff --git a/app/dashboard/layout.tsx b/app/dashboard/layout.tsx new file mode 100644 index 0000000..8b5de89 --- /dev/null +++ b/app/dashboard/layout.tsx @@ -0,0 +1,9 @@ +import type { Metadata } from 'next'; + +export const metadata: Metadata = { + title: 'AltBin - Dashboard', +}; + +export default function DashboardLayout({ children }: { children: React.ReactNode }) { + return <>{children}; +} \ No newline at end of file diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..e45ae71 --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,142 @@ +"use client"; + +import { useSession } from "next-auth/react"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import { toast } from "react-hot-toast"; + +import Header from "@/components/dashboard/Header"; +import LoadingDashboard from "@/components/dashboard/LoadingDashboard"; +import Pagination from "@/components/dashboard/Pagination"; +import PasteCard from "@/components/dashboard/PasteCard"; +import SearchBar from "@/components/dashboard/SearchBar"; +import Sidebar from "@/components/dashboard/Sidebar"; +import StatCard from "@/components/dashboard/StatCard"; +import ConfirmDeleteModal from "@/components/modals/ConfirmDeleteModal"; + +import { formatBytes } from "@/lib/format-bytes"; + +const PER_PAGE = 6; + +const dashboardIcons = { + clipboard: "https://cdn.lordicon.com/gvtjlyjf.json", + views: "https://cdn.lordicon.com/dicvhxpz.json", + calendar: "https://cdn.lordicon.com/uphbloed.json", + code: "https://cdn.lordicon.com/xqdfobxg.json", + storage: "https://cdn.lordicon.com/kikjlzqr.json", + chart: "https://cdn.lordicon.com/abwrkdvl.json", + flame: "https://cdn.lordicon.com/thtrcqvk.json", + file: "https://cdn.lordicon.com/fikcyfpp.json", + paste: "https://cdn.lordicon.com/hmpomorl.json", +}; + +export default function DashboardPage() { + const { data: session, status } = useSession(); + const router = useRouter(); + + const [searchTerm, setSearchTerm] = useState(""); + const [stats, setStats] = useState(null); + const [pastes, setPastes] = useState([]); + const [page, setPage] = useState(1); + const [totalPastes, setTotalPastes] = useState(0); + const [deleteId, setDeleteId] = useState(null); + + const handleDelete = async (id: string) => { + const res = await fetch(`/api/paste?id=${id}`, { method: "DELETE" }); + if (res.ok) { + setPastes((prev) => prev.filter((p) => p.id !== id)); + setTotalPastes((prev) => prev - 1); + toast.success("Paste deleted successfully 🚀"); + } else { + toast.error("Failed to delete paste ❌"); + } + }; + + useEffect(() => { + if (status === "unauthenticated") router.push("/"); + }, [status, router]); + + useEffect(() => { + if (status === "authenticated") { + const fetchStats = async () => { + const res = await fetch("/api/stats"); + if (res.ok) setStats(await res.json()); + }; + + const fetchPastes = async () => { + const res = await fetch( + `/api/user-pastes?page=${page}&perPage=${PER_PAGE}&q=${encodeURIComponent(searchTerm)}` + ); + if (!res.ok) return setPastes([]); + try { + const data = await res.json(); + setPastes(data.pastes ?? []); + setTotalPastes(data.total ?? 0); + } catch { + setPastes([]); + setTotalPastes(0); + } + }; + + fetchStats(); + fetchPastes(); + } + }, [status, page, searchTerm]); + + if (status === "loading" || !stats) return ; + + const totalPages = Math.ceil(totalPastes / PER_PAGE); + + return ( +
+ + +
+
+ + {/* Stats */} +
+ {[ + { label: "Total Pastes", value: stats.totalPastes, icon: dashboardIcons.clipboard }, + { label: "Total Views", value: stats.totalViews, icon: dashboardIcons.views }, + { label: "Last 30 Days", value: stats.recentPastes, icon: dashboardIcons.calendar }, + { label: "API Usage", value: stats.apiUsage, icon: dashboardIcons.code }, + { label: "Storage Used", value: formatBytes(stats.storageUsed), icon: dashboardIcons.storage }, + { label: "Avg Views", value: stats.avgViews, icon: dashboardIcons.chart }, + { label: "Most Viewed", value: stats.mostViewed, icon: dashboardIcons.flame }, + { label: "Avg Paste Size", value: formatBytes(stats.avgSize), icon: dashboardIcons.file }, + ].map((stat, i) => ( + + ))} +
+ + { setSearchTerm(v); setPage(1); }} /> + + {/* Pastes */} +

Your Pastes

+ {pastes.length === 0 ? ( +
No pastes found.
+ ) : ( +
+ {pastes.map((paste) => ( + + ))} +
+ )} + + + + !open && setDeleteId(null)} + onConfirm={() => { if (deleteId) { handleDelete(deleteId); setDeleteId(null); } }} + /> +
+
+ ); +} \ No newline at end of file diff --git a/app/favicon.ico b/app/favicon.ico deleted file mode 100644 index 718d6fe..0000000 Binary files a/app/favicon.ico and /dev/null differ diff --git a/app/globals.css b/app/globals.css index e3734be..95510be 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,42 +1,22 @@ -:root { - --background: #ffffff; - --foreground: #171717; +@import "tailwindcss"; + +.hljs, +code[class*="language-"], +pre[class*="language-"] { + background: transparent !important; } -@media (prefers-color-scheme: dark) { - :root { - --background: #0a0a0a; - --foreground: #ededed; - } -} - -html, -body { - max-width: 100vw; - overflow-x: hidden; -} - -body { - color: var(--foreground); - background: var(--background); - font-family: Arial, Helvetica, sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -* { - box-sizing: border-box; - padding: 0; - margin: 0; -} - -a { - color: inherit; - text-decoration: none; -} - -@media (prefers-color-scheme: dark) { - html { - color-scheme: dark; +/* ➡️ Hors du @layer */ +code[class*="language-"], +pre[class*="language-"] { + white-space: pre-wrap !important; + word-break: break-word !important; +} + +@layer utilities { + .neon-border { + box-shadow: + 0 0 0 1.5px oklch(0.65 0.2 250 / 0.5), + 0 0 10px oklch(0.65 0.2 250 / 0.2); } } diff --git a/app/layout.tsx b/app/layout.tsx index 42fc323..45243d0 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,32 +1,52 @@ -import type { Metadata } from "next"; -import { Geist, Geist_Mono } from "next/font/google"; -import "./globals.css"; +import AuthProvider from '@/components/SessionProvider'; +import ToasterProvider from '@/components/ui/ToasterProvider'; +import { ReactNode } from 'react'; +import './globals.css'; -const geistSans = Geist({ - variable: "--font-geist-sans", - subsets: ["latin"], -}); - -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", - subsets: ["latin"], -}); +import type { Metadata, Viewport } from "next"; export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "AltBin - Modern text and code sharing", + description: + "AltBin is a fast and modern pastebin for sharing text and code snippets with ease. Secure, minimal, and developer-friendly.", + metadataBase: new URL("https://altbin.dev"), + openGraph: { + title: "AltBin - Modern text and code sharing", + description: + "Easily share text and code snippets with AltBin. A sleek and secure pastebin for developers.", + url: "https://altbin.dev", + siteName: "AltBin", + images: ["/og-image.png"], + locale: "en_US", + type: "website", + }, + twitter: { + card: "summary_large_image", + title: "AltBin - Modern text and code sharing", + description: + "Share and manage text/code snippets effortlessly with AltBin. Secure and developer-friendly.", + images: ["/og-image.png"], + creator: "@AltBinApp", + }, + icons: { + icon: "/favicon.png", + shortcut: "/favicon.png", + }, }; -export default function RootLayout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { +export const viewport: Viewport = { + themeColor: "#0f172a", +}; + +export default function RootLayout({ children }: { children: ReactNode }) { return ( - - {children} + + + + {children} + ); -} +} \ No newline at end of file diff --git a/app/not-found.tsx b/app/not-found.tsx new file mode 100644 index 0000000..a2d0303 --- /dev/null +++ b/app/not-found.tsx @@ -0,0 +1,54 @@ +'use client'; + +import { motion } from 'framer-motion'; +import { Plus } from 'lucide-react'; +import { useRouter } from 'next/navigation'; + +export default function NotFoundPage() { + const router = useRouter(); + + return ( +
+ +

+ 404 +

+ +

+ Page Not Found +

+ +

+ The paste you're looking for might have been deleted, expired, or the + URL is incorrect. +

+ + router.push('/')} + className="cursor-pointer group inline-flex items-center gap-2 px-6 py-3 rounded-xl text-base font-medium + text-white bg-gradient-to-r from-blue-600 to-blue-500 shadow-lg shadow-blue-500/30 + hover:shadow-blue-500/50 transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-blue-400/60" + > + + Create New Paste + +
+
+ ); +} diff --git a/app/page.module.css b/app/page.module.css deleted file mode 100644 index 58c71af..0000000 --- a/app/page.module.css +++ /dev/null @@ -1,167 +0,0 @@ -.page { - --gray-rgb: 0, 0, 0; - --gray-alpha-200: rgba(var(--gray-rgb), 0.08); - --gray-alpha-100: rgba(var(--gray-rgb), 0.05); - - --button-primary-hover: #383838; - --button-secondary-hover: #f2f2f2; - - display: grid; - grid-template-rows: 20px 1fr 20px; - align-items: center; - justify-items: center; - min-height: 100svh; - padding: 80px; - gap: 64px; - font-family: var(--font-geist-sans); -} - -@media (prefers-color-scheme: dark) { - .page { - --gray-rgb: 255, 255, 255; - --gray-alpha-200: rgba(var(--gray-rgb), 0.145); - --gray-alpha-100: rgba(var(--gray-rgb), 0.06); - - --button-primary-hover: #ccc; - --button-secondary-hover: #1a1a1a; - } -} - -.main { - display: flex; - flex-direction: column; - gap: 32px; - grid-row-start: 2; -} - -.main ol { - font-family: var(--font-geist-mono); - padding-left: 0; - margin: 0; - font-size: 14px; - line-height: 24px; - letter-spacing: -0.01em; - list-style-position: inside; -} - -.main li:not(:last-of-type) { - margin-bottom: 8px; -} - -.main code { - font-family: inherit; - background: var(--gray-alpha-100); - padding: 2px 4px; - border-radius: 4px; - font-weight: 600; -} - -.ctas { - display: flex; - gap: 16px; -} - -.ctas a { - appearance: none; - border-radius: 128px; - height: 48px; - padding: 0 20px; - border: 1px solid transparent; - transition: - background 0.2s, - color 0.2s, - border-color 0.2s; - cursor: pointer; - display: flex; - align-items: center; - justify-content: center; - font-size: 16px; - line-height: 20px; - font-weight: 500; -} - -a.primary { - background: var(--foreground); - color: var(--background); - gap: 8px; -} - -a.secondary { - border-color: var(--gray-alpha-200); - min-width: 158px; -} - -.footer { - grid-row-start: 3; - display: flex; - gap: 24px; -} - -.footer a { - display: flex; - align-items: center; - gap: 8px; -} - -.footer img { - flex-shrink: 0; -} - -/* Enable hover only on non-touch devices */ -@media (hover: hover) and (pointer: fine) { - a.primary:hover { - background: var(--button-primary-hover); - border-color: transparent; - } - - a.secondary:hover { - background: var(--button-secondary-hover); - border-color: transparent; - } - - .footer a:hover { - text-decoration: underline; - text-underline-offset: 4px; - } -} - -@media (max-width: 600px) { - .page { - padding: 32px; - padding-bottom: 80px; - } - - .main { - align-items: center; - } - - .main ol { - text-align: center; - } - - .ctas { - flex-direction: column; - } - - .ctas a { - font-size: 14px; - height: 40px; - padding: 0 16px; - } - - a.secondary { - min-width: auto; - } - - .footer { - flex-wrap: wrap; - align-items: center; - justify-content: center; - } -} - -@media (prefers-color-scheme: dark) { - .logo { - filter: invert(); - } -} diff --git a/app/page.tsx b/app/page.tsx index 52bd15e..ac5584d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,95 +1,11 @@ -import Image from "next/image"; -import styles from "./page.module.css"; +'use client'; -export default function Home() { +import PasteForm from '@/components/PasteForm'; + +export default function HomePage() { return ( -
-
- Next.js logo -
    -
  1. - Get started by editing app/page.tsx. -
  2. -
  3. Save and see your changes instantly.
  4. -
- - -
- +
+
); } diff --git a/app/utils/fetcher.ts b/app/utils/fetcher.ts new file mode 100644 index 0000000..bffe8de --- /dev/null +++ b/app/utils/fetcher.ts @@ -0,0 +1,4 @@ +export async function fetchPastes() { + const res = await fetch('/api/paste'); + return await res.json(); +} diff --git a/components/PasteForm.tsx b/components/PasteForm.tsx new file mode 100644 index 0000000..b6ceddf --- /dev/null +++ b/components/PasteForm.tsx @@ -0,0 +1,76 @@ +"use client"; + +import AuthSection from "@/components/paste-form/AuthSection"; +import Editor from "@/components/paste-form/Editor"; +import SidebarPanel from "@/components/paste-form/SidebarPanel"; +import { useSession } from "next-auth/react"; +import { useRouter } from "next/navigation"; +import { useCallback, useEffect, useState } from "react"; + +export default function PasteForm() { + const router = useRouter(); + const { data: session } = useSession(); + + const [title, setTitle] = useState(""); + const [content, setContent] = useState(""); + const [password, setPassword] = useState(""); + const [maxViews, setMaxViews] = useState(""); + const [isSaving, setIsSaving] = useState(false); + const [advanced, setAdvanced] = useState(true); + + const handleSave = useCallback(async () => { + if (!content.trim()) return; + setIsSaving(true); + + const res = await fetch("/api/paste", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + title: title.trim() || null, + content, + password: password || null, + maxViews: maxViews ? parseInt(maxViews, 10) : null, + createdBy: session?.user?.id || null, + }), + }); + + if (res.ok) { + const data = await res.json(); + router.push(`/${data.id}`); + } + + setIsSaving(false); + }, [title, content, password, maxViews, session, router]); + + // Raccourci clavier Ctrl+S + useEffect(() => { + const onKeyDown = (e: KeyboardEvent) => { + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") { + e.preventDefault(); + if (!isSaving && content.trim()) handleSave(); + } + }; + window.addEventListener("keydown", onKeyDown); + return () => window.removeEventListener("keydown", onKeyDown); + }, [handleSave, isSaving, content]); + + return ( +
+ + + +
+ ); +} \ No newline at end of file diff --git a/components/SessionProvider.tsx b/components/SessionProvider.tsx new file mode 100644 index 0000000..69051d0 --- /dev/null +++ b/components/SessionProvider.tsx @@ -0,0 +1,8 @@ +'use client'; + +import { SessionProvider } from 'next-auth/react'; +import { ReactNode } from 'react'; + +export default function AuthProvider({ children }: { children: ReactNode }) { + return {children}; +} \ No newline at end of file diff --git a/components/dashboard/Header.tsx b/components/dashboard/Header.tsx new file mode 100644 index 0000000..7d61cb7 --- /dev/null +++ b/components/dashboard/Header.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { motion } from "framer-motion"; +import { useRouter } from "next/navigation"; +import { useRef } from "react"; +import LordIcon from "./LordIcon"; + +export default function Header({ user }: { user?: string | null }) { + const plusIconRef = useRef(null); + const router = useRouter(); + + return ( +
+

+ Welcome back, {user || "User"} +

+ + router.push("/")} + className="cursor-pointer flex items-center gap-2 px-6 py-3 rounded-xl text-base font-medium + text-white bg-gradient-to-r from-blue-600 to-blue-500 shadow-lg shadow-blue-500/30 + hover:shadow-blue-500/50 transition-all duration-300" + onMouseEnter={() => plusIconRef.current?.playFromBeginning()} + onMouseLeave={() => plusIconRef.current?.goToFirstFrame()} + > +
+ +
+ Create New Paste +
+
+ ); +} \ No newline at end of file diff --git a/components/dashboard/LoadingDashboard.tsx b/components/dashboard/LoadingDashboard.tsx new file mode 100644 index 0000000..e522eb0 --- /dev/null +++ b/components/dashboard/LoadingDashboard.tsx @@ -0,0 +1,77 @@ +"use client"; + +export default function LoadingDashboard() { + const StatSkeleton = () => ( +
+
+
+
+
+
+
+
+
+ ); + + const PasteSkeleton = () => ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ); + + return ( +
+ {/* Sidebar skeleton */} + + +
+ {/* Header skeleton + spinner */} +
+
+
+
+ Loading dashboard... +
+
+ + {/* Stat cards skeleton */} +
+ {Array.from({ length: 8 }).map((_, i) => ( + + ))} +
+ + {/* Search skeleton */} +
+
+
+ + {/* Pastes skeleton grid */} +
+ {Array.from({ length: 6 }).map((_, i) => ( + + ))} +
+
+
+ ); +} \ No newline at end of file diff --git a/components/dashboard/LordIcon.tsx b/components/dashboard/LordIcon.tsx new file mode 100644 index 0000000..9553efc --- /dev/null +++ b/components/dashboard/LordIcon.tsx @@ -0,0 +1,20 @@ +"use client"; + +import { Player } from "@lordicon/react"; +import { forwardRef, useEffect, useState } from "react"; + +const LordIcon = forwardRef(function LordIcon( + { url, size = 28, colorize = "#3b82f6" }: { url: string; size?: number; colorize?: string }, + ref: any +) { + const [iconData, setIconData] = useState(null); + + useEffect(() => { + fetch(url).then((res) => res.json()).then(setIconData); + }, [url]); + + if (!iconData) return null; + return ; +}); + +export default LordIcon; diff --git a/components/dashboard/Pagination.tsx b/components/dashboard/Pagination.tsx new file mode 100644 index 0000000..c530a13 --- /dev/null +++ b/components/dashboard/Pagination.tsx @@ -0,0 +1,31 @@ +"use client"; + +export default function Pagination({ + totalPages, + currentPage, + onPageChange, +}: { + totalPages: number; + currentPage: number; + onPageChange: (page: number) => void; +}) { + if (totalPages <= 1) return null; + + return ( +
+ {Array.from({ length: totalPages }, (_, i) => ( + + ))} +
+ ); +} \ No newline at end of file diff --git a/components/dashboard/PasteCard.tsx b/components/dashboard/PasteCard.tsx new file mode 100644 index 0000000..20deecd --- /dev/null +++ b/components/dashboard/PasteCard.tsx @@ -0,0 +1,60 @@ +"use client"; + +import { motion } from "framer-motion"; +import { useRef } from "react"; +import LordIcon from "./LordIcon"; + +export default function PasteCard({ + paste, + onDelete, + pasteIconUrl, +}: { + paste: any; + onDelete: (id: string) => void; + pasteIconUrl: string; +}) { + const pasteIconRef = useRef(null); + + return ( + pasteIconRef.current?.playFromBeginning()} + onMouseLeave={() => pasteIconRef.current?.goToFirstFrame()} + > +
+
+ +
+
+ {paste.title || 'Untitled'} +
+
+
+ {paste.content || 'No content'} +
+
+ {new Date(paste.createdAt).toLocaleString()} + + {paste.views} views + +
+
+ + View + + +
+
+ ); +} \ No newline at end of file diff --git a/components/dashboard/SearchBar.tsx b/components/dashboard/SearchBar.tsx new file mode 100644 index 0000000..d14ec35 --- /dev/null +++ b/components/dashboard/SearchBar.tsx @@ -0,0 +1,20 @@ +"use client"; + +import { Search } from "lucide-react"; + +export default function SearchBar({ value, onChange }: { value: string; onChange: (v: string) => void }) { + return ( +
+ + onChange(e.target.value)} + className="cursor-text w-full pl-10 pr-4 py-2 rounded-xl bg-[#0f1320]/70 text-white + placeholder:text-neutral-500 outline-none ring-1 ring-white/10 + focus:ring-2 focus:ring-blue-500/50 transition-all" + /> +
+ ); +} diff --git a/components/dashboard/Sidebar.tsx b/components/dashboard/Sidebar.tsx new file mode 100644 index 0000000..6b73dcd --- /dev/null +++ b/components/dashboard/Sidebar.tsx @@ -0,0 +1,51 @@ +"use client"; + +import LogoutButton from "@/components/ui/LogoutButton"; +import { FileText } from "lucide-react"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; + +export default function Sidebar() { + const pathname = usePathname(); + + const navItems = [ + { label: "My Pastes", href: "/dashboard", icon: FileText }, + ]; + + return ( + + ); +} \ No newline at end of file diff --git a/components/dashboard/StatCard.tsx b/components/dashboard/StatCard.tsx new file mode 100644 index 0000000..f156fc1 --- /dev/null +++ b/components/dashboard/StatCard.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { motion } from "framer-motion"; +import { useRef } from "react"; +import LordIcon from "./LordIcon"; + +export default function StatCard({ + label, + value, + icon, +}: { + label: string; + value: any; + icon: string; +}) { + const iconRef = useRef(null); + + return ( + iconRef.current?.playFromBeginning()} + onMouseLeave={() => iconRef.current?.goToFirstFrame()} + > +
+
+ +
+
+
{label}
+
{value}
+
+
+
+ ); +} diff --git a/components/modals/ConfirmDeleteModal.tsx b/components/modals/ConfirmDeleteModal.tsx new file mode 100644 index 0000000..201ca2f --- /dev/null +++ b/components/modals/ConfirmDeleteModal.tsx @@ -0,0 +1,75 @@ +"use client"; + +import * as Dialog from "@radix-ui/react-dialog"; +import { motion } from "framer-motion"; +import { X } from "lucide-react"; + +interface ConfirmDeleteModalProps { + open: boolean; + onOpenChange: (open: boolean) => void; + onConfirm: () => void; + title?: string; + description?: string; +} + +export default function ConfirmDeleteModal({ + open, + onOpenChange, + onConfirm, + title = "Delete paste?", + description = "This action cannot be undone. Are you sure you want to delete this paste?", +}: ConfirmDeleteModalProps) { + return ( + + + {/* Overlay noir semi-transparent */} + + + {/* Contenu centré */} + +
+ + {/* Header */} +
+ + {title} + + + + +
+ + {/* Description */} + + {description} + + + {/* Actions */} +
+ + + + +
+
+
+
+
+
+ ); +} \ No newline at end of file diff --git a/components/paste-form/AuthSection.tsx b/components/paste-form/AuthSection.tsx new file mode 100644 index 0000000..249e433 --- /dev/null +++ b/components/paste-form/AuthSection.tsx @@ -0,0 +1,61 @@ +"use client"; + +import { Info, Shield } from "lucide-react"; +import { signIn, signOut, useSession } from "next-auth/react"; + +export default function AuthSection() { + const { data: session, status } = useSession(); + + if (status === "loading") return null; + + return ( +
+ {!session?.user ? ( +
+ {/* Bouton About */} + + + About + + + {/* Bouton Login */} + +
+ ) : ( +
+
+ + Connected as + + {session.user.name || "User"} + +
+ +
+ + Dashboard + + +
+
+ )} +
+ ); +} \ No newline at end of file diff --git a/components/paste-form/Editor.tsx b/components/paste-form/Editor.tsx new file mode 100644 index 0000000..8639806 --- /dev/null +++ b/components/paste-form/Editor.tsx @@ -0,0 +1,48 @@ +"use client"; + +import { ChevronRight } from "lucide-react"; +import { useRef } from "react"; + +interface EditorProps { + content: string; + setContent: (v: string) => void; +} + +export default function Editor({ content, setContent }: EditorProps) { + const textareaRef = useRef(null); + const lineNumbersRef = useRef(null); + + const handleScroll = () => { + if (lineNumbersRef.current && textareaRef.current) { + lineNumbersRef.current.scrollTop = textareaRef.current.scrollTop; + } + }; + + return ( +
+ {/* Numéros de lignes */} +
+ {content.split("\n").map((_, i) => ( +
+ {i === 0 && } + {i + 1} +
+ ))} +
+ + {/* Zone d’édition */} +