diff --git a/app/Dashboard/page.tsx b/app/Dashboard/page.tsx index 86da3e8..bb47069 100644 --- a/app/Dashboard/page.tsx +++ b/app/Dashboard/page.tsx @@ -1,38 +1,74 @@ "use client"; import React, { useState } from "react"; -import { useRouter } from "next/navigation"; -import Link from 'next/link'; +// import { useRouter } from "next/navigation"; // Removed Next.js import +// import Link from 'next/link'; // Removed Next.js import -function Dashboard() { // 2. Changed from 'export default function' - const router = useRouter(); +export default function Dashboard() { + // const router = useRouter(); // Removed Next.js hook const [query, setQuery] = useState(""); const [sideBarOpen, setSidebarOpen] = useState(true); + // 1. Add state to track sort order + const [sortOrder, setSortOrder] = useState("newest"); // 'newest' or 'oldest' const projects = [ { name: "Alpha Project", createdAt: "2025-01-01" }, { name: "Beta Board", createdAt: "2025-02-15" }, { name: "Gamma Tasl", createdAt: "2025-03-10" }, ]; - const filtered = projects.filter((p) => + + // 2. Update sorting logic to use the sortOrder state + const sortedProjects = [...projects].sort((a, b) => { + // Get numeric timestamps to avoid TypeScript error + const dateA = new Date(a.createdAt).getTime(); + const dateB = new Date(b.createdAt).getTime(); + + if (sortOrder === "newest") { + return dateB - dateA; // Newest first + } else { + return dateA - dateB; // Oldest first + } + }); + + // 3. Filter the *sorted* array based on the query + const filtered = sortedProjects.filter((p) => p.name.toLowerCase().includes(query.toLowerCase()) ); + // Helper function to handle navigation for the "Create" button + const handleCreateClick = () => { + // Use standard window navigation instead of Next.js router + // Also corrected typo from "dashbaord" to "dashboard" + window.location.href = "/dashboard/create"; + }; + + // 4. Function to toggle the sort order + const toggleSortOrder = () => { + setSortOrder(currentOrder => (currentOrder === "newest" ? "oldest" : "newest")); + }; + return ( -