Spaces:
Sleeping
Sleeping
Download src/components/OverviewPanel.tsx from shahzaib24681012/teamsync: direct link, hf CLI and curl.
- Browser
- Download file 8.61 kB
-
https://huggingface.co/spaces/shahzaib24681012/teamsync/resolve/main/src/components/OverviewPanel.tsx
- Command line
-
hf download hf://spaces/shahzaib24681012/teamsync/src/components/OverviewPanel.tsx
-
curl -L -o OverviewPanel.tsx https://huggingface.co/spaces/shahzaib24681012/teamsync/resolve/main/src/components/OverviewPanel.tsx
8.61 kB
| 'use client'; | |
| /** Right-hand dashboard column (like the reference design): | |
| * Tasks preview, shared files in this chat, and an Upcoming card. */ | |
| import { useEffect, useState } from 'react'; | |
| import Link from 'next/link'; | |
| import { useParams } from 'next/navigation'; | |
| import { CalendarDays, CheckCircle2, Circle, FileText, Flag, Paperclip, SquareKanban, Image as ImageIcon } from 'lucide-react'; | |
| import { api } from '@/lib/client/api'; | |
| import { Avatar, timeAgo } from './ui'; | |
| import { BOARD_BGS, dueMeta } from '@/lib/client/board-ui'; | |
| type BoardRow = { id: string; name: string; background: number; totalCards: number; doneCards: number }; | |
| type MyTask = { | |
| id: string; title: string; dueDate?: string | null; completedAt?: string | null; | |
| board: { id: string; name: string; background: number }; | |
| list: { name: string }; | |
| }; | |
| type FileRow = { | |
| id: string; fileName: string; fileUrl: string; fileType: string; size: number; createdAt: string; | |
| message: { sender: { id: string; name: string; avatarUrl?: string | null } }; | |
| }; | |
| type Holiday = { id: string; date: string; name: string }; | |
| function fileSize(bytes: number): string { | |
| if (bytes < 1048576) return `${(bytes / 1024).toFixed(0)} KB`; | |
| return `${(bytes / 1048576).toFixed(1)} MB`; | |
| } | |
| export default function OverviewPanel({ channelId, conversationId }: { channelId?: string; conversationId?: string }) { | |
| const { wsId } = useParams<{ wsId: string }>(); | |
| const [boards, setBoards] = useState<BoardRow[]>([]); | |
| const [tasks, setTasks] = useState<MyTask[]>([]); | |
| const [files, setFiles] = useState<FileRow[]>([]); | |
| const [holidays, setHolidays] = useState<Holiday[]>([]); | |
| useEffect(() => { | |
| api<{ boards: BoardRow[] }>(`/api/workspaces/${wsId}/boards`).then((r) => setBoards(r.boards.slice(0, 1))).catch(() => {}); | |
| api<{ tasks: MyTask[] }>(`/api/workspaces/${wsId}/my-tasks`).then((r) => setTasks(r.tasks.filter((t) => !t.completedAt).slice(0, 4))).catch(() => {}); | |
| api<{ holidays: Holiday[] }>(`/api/workspaces/${wsId}/holidays`).then((r) => { | |
| const today = new Date().toISOString().slice(0, 10); | |
| setHolidays(r.holidays.filter((h) => h.date >= today).slice(0, 2)); | |
| }).catch(() => {}); | |
| }, [wsId]); | |
| useEffect(() => { | |
| const qs = channelId ? `channelId=${channelId}` : conversationId ? `conversationId=${conversationId}` : null; | |
| if (!qs) return; | |
| api<{ files: FileRow[] }>(`/api/resources?${qs}`).then((r) => setFiles(r.files.slice(0, 4))).catch(() => {}); | |
| }, [channelId, conversationId]); | |
| const board = boards[0]; | |
| return ( | |
| <aside className="hidden w-[300px] shrink-0 space-y-3 overflow-y-auto border-l border-gray-100 p-3 2xl:block"> | |
| {/* tasks */} | |
| <div className="rounded-2xl border border-gray-100 p-3.5"> | |
| <div className="mb-2.5 flex items-center justify-between"> | |
| <h3 className="flex items-center gap-1.5 text-sm font-bold text-gray-800"><SquareKanban className="h-4 w-4 text-gray-400" /> Tasks</h3> | |
| <Link href={`/w/${wsId}/tasks${board ? `/${board.id}` : ''}`} className="text-xs font-semibold text-primary-600 hover:underline"> | |
| Board view | |
| </Link> | |
| </div> | |
| {board && ( | |
| <Link href={`/w/${wsId}/tasks/${board.id}`} className="mb-2.5 block overflow-hidden rounded-xl border border-gray-100 transition-all hover:shadow-sm"> | |
| <div className="h-9 px-3 py-2 text-xs font-bold text-white" style={{ background: BOARD_BGS[board.background] ?? BOARD_BGS[0] }}> | |
| {board.name} | |
| </div> | |
| <div className="flex items-center gap-2 p-2.5"> | |
| <div className="h-1.5 flex-1 overflow-hidden rounded-full bg-gray-100"> | |
| <div className="h-full rounded-full bg-accent-500" style={{ width: board.totalCards ? `${(board.doneCards / board.totalCards) * 100}%` : '0%' }} /> | |
| </div> | |
| <span className="text-[11px] font-semibold text-gray-500">{board.doneCards}/{board.totalCards}</span> | |
| </div> | |
| </Link> | |
| )} | |
| {tasks.length === 0 && <p className="py-2 text-center text-xs text-gray-400">Nothing assigned to you.</p>} | |
| <div className="space-y-1.5"> | |
| {tasks.map((t) => { | |
| const due = dueMeta(t.dueDate, false); | |
| return ( | |
| <Link key={t.id} href={`/w/${wsId}/tasks/${t.board.id}?card=${t.id}`} | |
| className="flex items-center gap-2 rounded-lg border border-gray-100 px-2.5 py-2 transition-colors hover:bg-gray-50"> | |
| <Circle className="h-3.5 w-3.5 shrink-0 text-gray-300" /> | |
| <span className="min-w-0 flex-1"> | |
| <span className="block truncate text-xs font-semibold text-gray-800">{t.title}</span> | |
| <span className="block text-[10px] text-gray-400">{t.list.name}</span> | |
| </span> | |
| {due && <span className={`rounded-full border px-1.5 py-px text-[9px] font-semibold ${due.cls}`}>{due.label}</span>} | |
| </Link> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| {/* shared files */} | |
| <div className="rounded-2xl border border-gray-100 p-3.5"> | |
| <div className="mb-2.5 flex items-center justify-between"> | |
| <h3 className="flex items-center gap-1.5 text-sm font-bold text-gray-800"><Paperclip className="h-4 w-4 text-gray-400" /> Shared Files</h3> | |
| <Link href={`/w/${wsId}/files`} className="text-xs font-semibold text-primary-600 hover:underline">View all</Link> | |
| </div> | |
| {files.length === 0 && <p className="py-2 text-center text-xs text-gray-400">No files in this chat yet.</p>} | |
| <div className="space-y-1.5"> | |
| {files.map((f) => ( | |
| <a key={f.id} href={f.fileUrl} target="_blank" rel="noreferrer" | |
| className="flex items-center gap-2.5 rounded-lg border border-gray-100 px-2.5 py-2 transition-colors hover:bg-gray-50"> | |
| <span className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-white ${f.fileType.includes('pdf') ? 'bg-red-500' : f.fileType.startsWith('image/') ? 'bg-violet-500' : f.fileType.includes('sheet') || f.fileType.includes('csv') ? 'bg-green-600' : 'bg-amber-500'}`}> | |
| {f.fileType.startsWith('image/') ? <ImageIcon className="h-4 w-4" /> : <FileText className="h-4 w-4" />} | |
| </span> | |
| <span className="min-w-0 flex-1"> | |
| <span className="block truncate text-xs font-semibold text-gray-800">{f.fileName}</span> | |
| <span className="block text-[10px] text-gray-400">{fileSize(f.size)} · {timeAgo(f.createdAt)}</span> | |
| </span> | |
| <Avatar name={f.message.sender.name} url={f.message.sender.avatarUrl} size={18} /> | |
| </a> | |
| ))} | |
| </div> | |
| </div> | |
| {/* upcoming */} | |
| <div className="grad rounded-2xl p-3.5"> | |
| <h3 className="mb-2.5 text-sm font-bold text-white">Upcoming</h3> | |
| <div className="space-y-1.5"> | |
| {holidays.map((h) => ( | |
| <div key={h.id} className="flex items-center gap-2.5 rounded-lg bg-white/10 px-2.5 py-2"> | |
| <span className="flex h-8 w-8 items-center justify-center rounded-lg bg-white/15 text-white"><CalendarDays className="h-4 w-4" /></span> | |
| <span className="min-w-0"> | |
| <span className="block truncate text-xs font-bold text-white">{h.name}</span> | |
| <span className="block text-[10px] text-white/60">{new Date(`${h.date}T00:00:00`).toLocaleDateString([], { month: 'long', day: 'numeric' })} · Holiday</span> | |
| </span> | |
| </div> | |
| ))} | |
| {tasks.filter((t) => t.dueDate).slice(0, 2).map((t) => ( | |
| <div key={t.id} className="flex items-center gap-2.5 rounded-lg bg-white/10 px-2.5 py-2"> | |
| <span className="flex h-8 w-8 items-center justify-center rounded-lg bg-white/15 text-white"><Flag className="h-4 w-4" /></span> | |
| <span className="min-w-0"> | |
| <span className="block truncate text-xs font-bold text-white">{t.title}</span> | |
| <span className="block text-[10px] text-white/60">Due {new Date(t.dueDate!).toLocaleDateString([], { month: 'short', day: 'numeric' })}</span> | |
| </span> | |
| </div> | |
| ))} | |
| {holidays.length === 0 && tasks.filter((t) => t.dueDate).length === 0 && ( | |
| <div className="flex items-center gap-2 rounded-lg bg-white/10 px-2.5 py-2 text-xs text-white/70"> | |
| <CheckCircle2 className="h-4 w-4" /> Nothing coming up | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </aside> | |
| ); | |
| } | |