// DashboardPage.jsx // Main dashboard component import React, { useState, useEffect } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { Button } from '@progress/kendo-react-buttons'; import { Card, CardImage, CardBody, GridLayout } from '@progress/kendo-react-layout'; import PostCard from '../components/Cards/PostCard'; import { getPublishedPosts, getDraftPosts } from '../data/postsCache'; const Dashboard = React.forwardRef((props, ref) => { // State management for blog post data and loading states const [publishedPosts, setPublishedPosts] = useState([]); const [draftPosts, setDraftPosts] = useState([]); const [isLoading, setIsLoading] = useState(true); const navigate = useNavigate(); const location = useLocation(); // Load blog post data on component mount useEffect(() => { const loadData = async () => { setIsLoading(true); try { // Parallel data loading for better performance const [published, drafts] = await Promise.all([ getPublishedPosts(), getDraftPosts() ]); setPublishedPosts(published); setDraftPosts(drafts); } catch (error) { console.error('Error loading posts:', error); } finally { setIsLoading(false); } }; loadData(); }, []); const handleEdit = (slug) => { navigate(`/editor/${slug}`); }; // Determine filter from URL path const getFilterFromPath = () => { if (location.pathname === '/posts') return 'published'; if (location.pathname === '/drafts') return 'drafts'; return null; // Show both }; const filter = getFilterFromPath(); // Show sections based on URL filter or show both if no filter const showPublished = !filter || filter === 'published'; const showDrafts = !filter || filter === 'drafts'; if (isLoading) { return (
No published posts.
)}No drafts.
)}