Spaces:
Runtime error
Runtime error
Download src/components/dashboard/CalendarView.tsx from damndeepesh-dev/RippleWorkers: direct link, hf CLI and curl.
- Browser
- Download file 9.45 kB
-
https://huggingface.co/spaces/damndeepesh-dev/RippleWorkers/resolve/main/src/components/dashboard/CalendarView.tsx
- Command line
-
hf download hf://spaces/damndeepesh-dev/RippleWorkers/src/components/dashboard/CalendarView.tsx
-
curl -L -o CalendarView.tsx https://huggingface.co/spaces/damndeepesh-dev/RippleWorkers/resolve/main/src/components/dashboard/CalendarView.tsx
9.45 kB
| "use client"; | |
| import { useState } from "react"; | |
| import { format, startOfWeek, endOfWeek, startOfMonth, endOfMonth, eachDayOfInterval, isSameMonth, isSameDay, addMonths, subMonths, addWeeks, subWeeks } from "date-fns"; | |
| import { ChevronLeft, ChevronRight, Calendar as CalendarIcon, Clock, CheckCircle } from "lucide-react"; | |
| import Image from "next/image"; | |
| type ViewMode = "month" | "week"; | |
| export default function CalendarView({ posts }: { posts: any[] }) { | |
| const [currentDate, setCurrentDate] = useState(new Date()); | |
| const [viewMode, setViewMode] = useState<ViewMode>("month"); | |
| // Navigation | |
| const next = () => { | |
| if (viewMode === "month") setCurrentDate(addMonths(currentDate, 1)); | |
| else setCurrentDate(addWeeks(currentDate, 1)); | |
| }; | |
| const prev = () => { | |
| if (viewMode === "month") setCurrentDate(subMonths(currentDate, 1)); | |
| else setCurrentDate(subWeeks(currentDate, 1)); | |
| }; | |
| // Calculate Days to Show | |
| const start = viewMode === "month" ? startOfWeek(startOfMonth(currentDate)) : startOfWeek(currentDate); | |
| const end = viewMode === "month" ? endOfWeek(endOfMonth(currentDate)) : endOfWeek(currentDate); | |
| // Ensure we don't have a massive range (safety) | |
| const days = eachDayOfInterval({ start, end }); | |
| return ( | |
| <div className="flex flex-col h-full bg-white dark:bg-zinc-900 rounded-2xl shadow-sm border border-gray-100 dark:border-zinc-800 overflow-hidden"> | |
| {/* Header */} | |
| <div className="p-6 border-b border-gray-100 dark:border-zinc-800 flex justify-between items-center"> | |
| <div className="flex items-center gap-4"> | |
| <h2 className="text-xl font-bold text-gray-900 dark:text-white capitalize"> | |
| {format(currentDate, "MMMM yyyy")} | |
| </h2> | |
| <div className="flex bg-gray-100 dark:bg-zinc-800 rounded-lg p-1"> | |
| <button | |
| onClick={() => setViewMode("month")} | |
| className={`px-3 py-1 text-xs font-medium rounded-md transition-all ${viewMode === "month" ? "bg-white dark:bg-zinc-700 shadow-sm text-gray-900 dark:text-white" : "text-gray-500 hover:text-gray-900 dark:hover:text-gray-200"}`} | |
| > | |
| Month | |
| </button> | |
| <button | |
| onClick={() => setViewMode("week")} | |
| className={`px-3 py-1 text-xs font-medium rounded-md transition-all ${viewMode === "week" ? "bg-white dark:bg-zinc-700 shadow-sm text-gray-900 dark:text-white" : "text-gray-500 hover:text-gray-900 dark:hover:text-gray-200"}`} | |
| > | |
| Week | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex items-center gap-2"> | |
| <button onClick={prev} className="p-2 hover:bg-gray-100 dark:hover:bg-zinc-800 rounded-full text-gray-600 dark:text-gray-400"> | |
| <ChevronLeft size={20} /> | |
| </button> | |
| <button onClick={() => setCurrentDate(new Date())} className="text-sm font-medium text-blue-600 px-3 hover:underline"> | |
| Today | |
| </button> | |
| <button onClick={next} className="p-2 hover:bg-gray-100 dark:hover:bg-zinc-800 rounded-full text-gray-600 dark:text-gray-400"> | |
| <ChevronRight size={20} /> | |
| </button> | |
| </div> | |
| </div> | |
| {/* Grid Header (Days of Week) */} | |
| <div className={`grid grid-cols-7 border-b border-gray-100 dark:border-zinc-800 bg-gray-50 dark:bg-zinc-900/50`}> | |
| {["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map(day => ( | |
| <div key={day} className="py-3 text-center text-xs font-semibold text-gray-500 uppercase tracking-wider"> | |
| {day} | |
| </div> | |
| ))} | |
| </div> | |
| {/* Calendar Grid */} | |
| <div className={`grid grid-cols-7 flex-1 auto-rows-fr overflow-y-auto bg-gray-100 dark:bg-zinc-800 gap-px`}> | |
| {days.map((day, dayIdx) => { | |
| const dayPosts = posts.filter(p => p.scheduledAt && isSameDay(new Date(p.scheduledAt), day)); | |
| const isOutsideMonth = viewMode === "month" && !isSameMonth(day, currentDate); | |
| const isToday = isSameDay(day, new Date()); | |
| return ( | |
| <div | |
| key={day.toISOString()} | |
| className={`min-h-[120px] bg-white dark:bg-zinc-900 p-2 flex flex-col gap-1 transition-colors hover:bg-gray-50 dark:hover:bg-zinc-800/80 ${isOutsideMonth ? "bg-gray-50/50 dark:bg-zinc-900/50 text-gray-400" : ""}`} | |
| > | |
| <div className="flex justify-between items-start"> | |
| <span className={`text-sm font-medium w-7 h-7 flex items-center justify-center rounded-full ${isToday ? "bg-blue-600 text-white" : "text-gray-700 dark:text-gray-300"}`}> | |
| {format(day, "d")} | |
| </span> | |
| {dayPosts.length > 0 && ( | |
| <span className="text-[10px] bg-gray-100 dark:bg-zinc-800 px-1.5 py-0.5 rounded text-gray-500"> | |
| {dayPosts.length} posts | |
| </span> | |
| )} | |
| </div> | |
| <div className="flex-1 flex flex-col gap-1 mt-1 overflow-y-auto custom-scrollbar"> | |
| {dayPosts.map(post => ( | |
| <div key={post.id} className="group relative bg-blue-50 dark:bg-blue-900/10 border border-blue-100 dark:border-blue-900/30 rounded p-1.5 flex gap-2 items-center cursor-pointer hover:border-blue-300 dark:hover:border-blue-700 transition-colors"> | |
| {/* Thumbnail */} | |
| <div className="w-8 h-8 rounded bg-gray-200 flex-shrink-0 overflow-hidden relative group/thumb"> | |
| {post.mediaType === "VIDEO" ? ( | |
| <video src={post.mediaUrl.split(',')[0]} className="w-full h-full object-cover" /> | |
| ) : ( | |
| <img src={post.mediaUrl.split(',')[0]} alt="" className="w-full h-full object-cover" /> | |
| )} | |
| {/* Account Avatar Overlay */} | |
| <div className="absolute bottom-0 right-0 w-3.5 h-3.5 rounded-full border border-white dark:border-zinc-900 bg-gray-200 dark:bg-zinc-800 overflow-hidden shadow-sm"> | |
| {post.accountProfilePictureUrl ? ( | |
| <img src={post.accountProfilePictureUrl} className="w-full h-full object-cover" alt="" /> | |
| ) : ( | |
| <div className="w-full h-full flex items-center justify-center text-[6px] font-bold text-gray-500"> | |
| {(post.accountUsername || "U")[0].toUpperCase()} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| {/* Info */} | |
| <div className="min-w-0 flex-1"> | |
| <div className="flex items-center gap-1.5 mb-0.5"> | |
| {post.status === "PUBLISHED" ? ( | |
| <CheckCircle size={10} className="text-green-500" /> | |
| ) : post.status === "SCHEDULED" ? ( | |
| <Clock size={10} className="text-blue-500" /> | |
| ) : ( | |
| <div className="w-2 h-2 rounded-full bg-gray-400" /> | |
| )} | |
| <span className="text-[10px] text-gray-500 font-mono truncate"> | |
| {format(new Date(post.scheduledAt), "p")} | |
| </span> | |
| </div> | |
| <p className="text-[11px] text-gray-900 dark:text-gray-200 truncate leading-tight"> | |
| {post.caption || "Untitled"} | |
| </p> | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| ); | |
| } | |