import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import { useNotifications } from '../context/NotificationContext'; import { getStarredBoards, unstarBoard, StarredBoard } from '../lib/starredBoards'; import { getBoardScreenshot, removeBoardScreenshot } from '../lib/screenshotService'; export function Dashboard() { const { session } = useAuth(); const { addNotification } = useNotifications(); const [starredBoards, setStarredBoards] = useState([]); const [isLoading, setIsLoading] = useState(true); // Note: We don't redirect automatically - let the component show auth required message // Load starred boards useEffect(() => { if (session.authed && session.username) { const boards = getStarredBoards(session.username); setStarredBoards(boards); setIsLoading(false); } }, [session.authed, session.username]); const handleUnstarBoard = (slug: string) => { if (!session.username) return; const success = unstarBoard(session.username, slug); if (success) { setStarredBoards(prev => prev.filter(board => board.slug !== slug)); removeBoardScreenshot(slug); // Remove screenshot when unstarring addNotification('Board removed from starred boards', 'success'); } else { addNotification('Failed to remove board from starred boards', 'error'); } }; const formatDate = (timestamp: number) => { return new Date(timestamp).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', }); }; if (session.loading) { return (
Loading dashboard...
); } if (!session.authed) { return (

Authentication Required

Please log in to access your dashboard.

Go Home
); } return (

My Dashboard

Welcome back, {session.username}!

Starred Boards

{starredBoards.length} board{starredBoards.length !== 1 ? 's' : ''}
{isLoading ? (
Loading starred boards...
) : starredBoards.length === 0 ? (

No starred boards yet

Star boards you want to save for quick access.

Browse Boards
) : (
{starredBoards.map((board) => { const screenshot = getBoardScreenshot(board.slug); return (
{screenshot && (
{`Screenshot
)}

{board.title}

/{board.slug}

Starred: {formatDate(board.starredAt)} {board.lastVisited && ( Last visited: {formatDate(board.lastVisited)} )}
Open Board
); })}
)}
); }