diff --git a/apps/nextjs/src/app/dashboard/Assignments.tsx b/apps/nextjs/src/app/dashboard/Assignments.tsx index 802eb66..2f408c2 100644 --- a/apps/nextjs/src/app/dashboard/Assignments.tsx +++ b/apps/nextjs/src/app/dashboard/Assignments.tsx @@ -43,13 +43,51 @@ function autoAssign( setAssignments: (assignments: string[]) => void, ) { // useEffect(() => { - const autoassign = assignTasks(assignments, Object.keys(members)); + const autoassign: { [key: string]: string[] } = assignTasks( + assignments, + Object.keys(members), + ); console.log(autoassign, typeof autoassign); setMembers(autoassign); + // {[key: string]: string[];} setAssignments([]); // }, []); } -function Assignments({ selectedEvent }) { + +type AssignmentsProps = { + selectedEvent: string; +}; + +type Match = { + match_num: number; + match_key: string; + alliances: { + blue: { + team_keys: string[]; + }; + red: { + team_keys: string[]; + }; + }; +}; + +type MatchSubset = { + match_num: number; + alliances: { + blue: { + team_keys: string[]; + }; + red: { + team_keys: string[]; + }; + }; +}; + +type Alliance = { + team_keys: string[]; +}; + +function Assignments({ selectedEvent }: AssignmentsProps) { // XXX: Use real data via tRPC // const [members, setMembers] = useState<{ [key: string]: string[] }>( // Object.fromEntries(tags.map((x) => [`${x}M`, []])), @@ -64,7 +102,7 @@ function Assignments({ selectedEvent }) { console.log("HEEEEE: ", members); } fetchData(); - }, []); + }, [members]); const [assignments, setAssignments] = useState([]); // Updated t const [activeId, setActiveId] = useState(null); // Inverted members @@ -88,12 +126,12 @@ function Assignments({ selectedEvent }) { useEffect(() => { if (!isLoading && data) { // Extract relevant information from the data and generate assignments - const matches = data.map((match: any) => ({ + const matches = data.map((match: Match) => ({ match_num: match.match_num, // match_key: match.match_key, alliances: match.alliances, })); - const matchKeys = data.map((match: any) => ({ + const matchKeys = data.map((match: Match) => ({ match_key: match.match_key, event: selectedEvent, })); @@ -104,18 +142,18 @@ function Assignments({ selectedEvent }) { for (let i = 0; i < matchKeys.length; i++) { addMatches({ match: matchKeys[i] }); } - let newAssignments: string[] = []; + const newAssignments: string[] = []; // Iterate over each match object let count = 0; let c2 = 1; // biome-ignore lint/complexity/noForEach: - matches.forEach((match: any) => { + matches.forEach((match: MatchSubset) => { // Extract match number and alliances - const { match_num, match_key, alliances } = match; + const { alliances } = match; // Iterate over each alliance (blue and red) // biome-ignore lint/complexity/noForEach: - Object.values(alliances).forEach((alliance: any) => { + Object.values(alliances).forEach((alliance: Alliance) => { // Extract team keys from the alliance const teamKeys = alliance.team_keys; @@ -126,7 +164,7 @@ function Assignments({ selectedEvent }) { const assignment = `Match ${c2} - Team ${teamKey}`; // const assignment = `Match ${match_key} - Team ${teamKey}`; count++; - if (count % 6 == 0) { + if (count % 6 === 0) { count = 0; c2++; } @@ -142,7 +180,7 @@ function Assignments({ selectedEvent }) { // Update the state with the newAssignments array setAssignments(newAssignments); } - }, [isLoading, data]); + }, [isLoading, data, selectedEvent]); return ( <> {/* */} @@ -179,7 +217,10 @@ function Assignments({ selectedEvent }) { } return false; // Return false if not found in either alliance }); - + if (!match) { + console.error("Match not found for the active team key."); + return; // Stop execution if match is not found + } // Check if the activeTeamKey is part of the blue alliance or the red alliance const allianceColor = match.alliances.blue.team_keys.includes( activeTeamKey, @@ -191,7 +232,7 @@ function Assignments({ selectedEvent }) { // Find the index of the match object within the data array // const index = data.indexOf(match); // Find the index of the team key within the blue or red alliance array - let index; + let index: number; if (allianceColor === "blue") { index = match.alliances.blue.team_keys.indexOf(activeTeamKey); } else { @@ -207,12 +248,14 @@ function Assignments({ selectedEvent }) { } const alliance = (allianceColor + (index + 1)) as string; - const matchNumber = parseInt(activeId.split(" ")[1]); + const matchNumber = Number.parseInt(activeId.split(" ")[1]); // Make sure index is within the valid range of data array const currentMatchKey = data[matchNumber - 1].match_key; - const currentTeam = parseInt(activeId.split(" ")[4].slice(-4)); + const currentTeam = Number.parseInt( + activeId.split(" ")[4].slice(-4), + ); addAssignment({ match: currentMatchKey, diff --git a/apps/nextjs/src/app/dashboard/components/cards.tsx b/apps/nextjs/src/app/dashboard/components/cards.tsx index 239d46b..d9e2d39 100644 --- a/apps/nextjs/src/app/dashboard/components/cards.tsx +++ b/apps/nextjs/src/app/dashboard/components/cards.tsx @@ -128,7 +128,7 @@ export function AssignmentCard({ assignment }: { assignment: string }) { {" "} - I HAVE NO GIRLS + Quantitative Scouting {/* */} {/*
diff --git a/apps/nextjs/src/app/dashboard/layout.tsx b/apps/nextjs/src/app/dashboard/layout.tsx index 2754c78..d4896a8 100644 --- a/apps/nextjs/src/app/dashboard/layout.tsx +++ b/apps/nextjs/src/app/dashboard/layout.tsx @@ -36,7 +36,7 @@ export default function RootLayout({
{/* */} {/* XXX: Dynamic MainNav */} - +
diff --git a/apps/nextjs/src/app/dashboard/page.tsx b/apps/nextjs/src/app/dashboard/page.tsx index 8e63558..46d8cde 100644 --- a/apps/nextjs/src/app/dashboard/page.tsx +++ b/apps/nextjs/src/app/dashboard/page.tsx @@ -1,30 +1,15 @@ "use client"; +import type { FC } from "react"; import { useEffect, useState } from "react"; -import { Metadata } from "next"; -import Image from "next/image"; import { Button } from "@/components/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; import { Dialog, DialogContent, - DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; -import { - ResizableHandle, - ResizablePanel, - ResizablePanelGroup, -} from "@/components/ui/resizable"; -import { ScrollArea } from "@/components/ui/scroll-area"; import { Select, SelectContent, @@ -32,33 +17,58 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { Separator } from "@/components/ui/separator"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { trpc } from "@/lib/utils/trpc"; -// import { allEvents } from "../matches/getEvents"; -import { allEvents } from "../matches/getEvents"; -import { addEvents } from "./actions"; import Assignments from "./Assignments"; -import { CalendarDateRangePicker } from "./components/date-range-picker"; -import { MainNav } from "./components/main-nav"; -import { Overview } from "./components/overview"; -import { RecentSales } from "./components/recent-sales"; -import { Search } from "./components/search"; -import TeamSwitcher from "./components/team-switcher"; -import { UserNav } from "./components/user-nav"; -// export const metadata: Metadata = { -// title: "Dashboard", -// description: "Example dashboard app built using the components.", -// }; +type Event = { + name: string; + key: string; +}; + +type ModalSelectComponentProps = { + events: Event[]; + selectedEvent: string; + setSelectedEvent: (value: string) => void; +}; + +function DashboardPage() { + const [selectedEvent, setSelectedEvent] = useState("Choose Event"); + + const { data, error, isLoading, refetch } = trpc.tba.teamEvents.useQuery( + { teamKey: "frc3256", year: 2024 }, + { + enabled: false, + }, + ); + useEffect(() => { + refetch(); + }, [refetch]); + + if (isLoading) { + return
Loading...
; + } + + if (error) { + return
An error occurred: {error.message}
; + } -const ModalSelectComponent = ({ events, selectedEvent, setSelectedEvent }) => { - const handleValueChange = (value) => { + const events = + data?.map((event) => ({ + name: event.name, + key: event.key, + })) ?? []; + + const handleValueChange = (value: string) => { setSelectedEvent(value); }; - return ( + const ModalSelectComponent: FC = ({ + events, + selectedEvent, + setSelectedEvent, + }) => (
@@ -72,11 +82,6 @@ const ModalSelectComponent = ({ events, selectedEvent, setSelectedEvent }) => { - {/* - - {selectedEvent ? selectedEvent : "Choose one"} - - */} {events.map((event) => ( { ))} -
); -}; - -function DashboardPage() { - const [events, setEvents] = useState([]); - // const [keys, setKeys] = useState([]); - const [selectedEvent, setSelectedEvent] = useState("Choose one"); - - useEffect(() => { - handleSubmit(); - }, []); - const { data, refetch } = trpc.tba.teamEvents.useQuery( - { - teamKey: "frc3256", - year: 2023, - }, - { enabled: false }, - ); - - const handleSubmit = async () => { - try { - refetch(); - setEvents(data.map((event) => ({ name: event.name, key: event.key }))); - - // setKeys(data.map((event) => event.key)); - console.log("I AM RIGH THERE: ", selectedEvent); - // addEvents({ events: { name: "test", key: "test" } }); - for (let i = 0; i < events.length; i++) { - console.log("EVENTS: ", events[i]); - addEvents({ event: events[i] }); - } - } catch (error) { - console.error("Error fetching events:", error); - } - }; return (
@@ -141,161 +109,15 @@ function DashboardPage() { selectedEvent={selectedEvent} setSelectedEvent={setSelectedEvent} /> - {/* */} - {/* */} - {/* */} - - {/*

DATA:

*/} - {/* {allEvents("frc3256", 2024)} */} - {/* */}
Scouting Assignments - - Attendance - - - Team Overview - - - Management - - {/* -
- - - - Total Revenue - - - - - - -
$45,231.89
-

- +20.1% from last month -

-
-
- - - - Subscriptions - - - - - - - - -
+2350
-

- +180.1% from last month -

-
-
- - - Sales - - - - - - -
+12,234
-

- +19% from last month -

-
-
- - - - Active Now - - - - - - -
+573
-

- +201 since last hour -

-
-
-
-
- - - Overview - - - - - - - - Recent Sales - - You made 265 sales this month. - - - - - - -
-
*/}
); diff --git a/apps/nextjs/src/app/page.tsx b/apps/nextjs/src/app/page.tsx index 18b5592..54f889f 100644 --- a/apps/nextjs/src/app/page.tsx +++ b/apps/nextjs/src/app/page.tsx @@ -10,20 +10,12 @@ import { cn } from "@/lib/utils"; import { signup } from "./actions"; -// export const metadata: Metadata = { -// title: "Authentication", -// description: "Authentication forms built using the components.", -// }; - export default function AuthenticationPage() { const searchParams = useSearchParams(); const code = searchParams.get("code"); if (code) { redirect("/signin?signup=true&code=" + code); } - // if (!noredir) { - // redirect("/signin"); - // } return ( <>
@@ -54,31 +46,6 @@ export default function AuthenticationPage() {
- {/*
- - - - Acme Inc -
*/} - {/*
-
-

- “This library has saved me countless hours of work and - helped me deliver stunning designs to my clients faster than - ever before.” -

-
Sofia Davis
-
-
*/}
diff --git a/apps/nextjs/src/lib/utils/autoassign.js b/apps/nextjs/src/lib/utils/autoassign.ts similarity index 85% rename from apps/nextjs/src/lib/utils/autoassign.js rename to apps/nextjs/src/lib/utils/autoassign.ts index a00f839..f889cdc 100644 --- a/apps/nextjs/src/lib/utils/autoassign.js +++ b/apps/nextjs/src/lib/utils/autoassign.ts @@ -1,13 +1,13 @@ -export function assignTasks(times, users) { +export function assignTasks(times: string[], users: string[]) { // Sort the times for ordered assignment const sortedTimes = times.sort(); // Initialize assignments, lastAssigned, and taskCount objects - const assignments = {}; - const lastAssigned = {}; - const taskCount = {}; + const assignments: { [key: string]: string[] } = {}; + const lastAssigned: { [key: string]: string | null } = {}; + const taskCount: { [key: string]: number } = {}; // biome-ignore lint/complexity/noForEach: -users.forEach(user => { + users.forEach((user) => { assignments[user] = []; lastAssigned[user] = null; taskCount[user] = 0;