From 43bcf911b8a1c2bf4dd7b6a7c871e6bc3c3c9c66 Mon Sep 17 00:00:00 2001 From: Amaar Chughtai Date: Sat, 24 Feb 2024 16:11:23 -0800 Subject: [PATCH 1/2] Implemented AutoAssign functionality to NextJS Admin Dashboard --- apps/nextjs/src/app/dashboard/Assignments.tsx | 24 +++++++++++++++++-- apps/nextjs/src/app/dashboard/page.tsx | 2 +- apps/nextjs/src/lib/utils/autoassign.js | 16 ++++++------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/apps/nextjs/src/app/dashboard/Assignments.tsx b/apps/nextjs/src/app/dashboard/Assignments.tsx index fb7a7f2..daedf3d 100644 --- a/apps/nextjs/src/app/dashboard/Assignments.tsx +++ b/apps/nextjs/src/app/dashboard/Assignments.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Metadata } from "next"; import Image from "next/image"; import { Button } from "@/components/ui/button"; @@ -19,6 +19,7 @@ import { import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { assignTasks } from "@/lib/utils/autoassign"; import { DndContext, DragOverlay, useDroppable } from "@dnd-kit/core"; import { AssignmentCard, MemberCard } from "./components/cards"; @@ -33,7 +34,19 @@ import { UserNav } from "./components/user-nav"; const tags = Array.from({ length: 50 }).map( (_, i, a) => `v1.2.0-beta.${a.length - i}`, ); - +function autoAssign( + assignments: string[], + members: { [key: string]: string[] }, + setMembers: (members: { [key: string]: string[] }) => void, + setAssignments: (assignments: string[]) => void, +) { + // useEffect(() => { + const autoassign = assignTasks(assignments, Object.keys(members)); + console.log(autoassign, typeof autoassign); + setMembers(autoassign); + setAssignments([]); + // }, []); +} export default function Assignments() { // XXX: Use real data via tRPC const [members, setMembers] = useState<{ [key: string]: string[] }>( @@ -137,6 +150,13 @@ export default function Assignments() { */} + ); } diff --git a/apps/nextjs/src/app/dashboard/page.tsx b/apps/nextjs/src/app/dashboard/page.tsx index eb72f4c..4272733 100644 --- a/apps/nextjs/src/app/dashboard/page.tsx +++ b/apps/nextjs/src/app/dashboard/page.tsx @@ -17,7 +17,7 @@ import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import Assignments from "./Assignments"; +import Assignments, { autoassign } from "./Assignments"; import { CalendarDateRangePicker } from "./components/date-range-picker"; import { MainNav } from "./components/main-nav"; import { Overview } from "./components/overview"; diff --git a/apps/nextjs/src/lib/utils/autoassign.js b/apps/nextjs/src/lib/utils/autoassign.js index 868e1af..edd962d 100644 --- a/apps/nextjs/src/lib/utils/autoassign.js +++ b/apps/nextjs/src/lib/utils/autoassign.js @@ -1,4 +1,4 @@ -function assignTasks(times, users) { +export function assignTasks(times, users) { // Sort the times for ordered assignment const sortedTimes = times.sort(); @@ -38,12 +38,12 @@ users.forEach(user => { return assignments; } - // Example usage: - const times = ['10:00', '10:30', '11:00', '11:30'].reduce((acc, time) => acc.concat(Array(6).fill(time)), []); - const users = ['Bryan', 'has', 'no', 'girls', 'also', 'the', 'scouting', 'app', 'works','on','his','computer']; + // // Example usage: + // const times = ['10:00', '10:30', '11:00', '11:30'].reduce((acc, time) => acc.concat(Array(6).fill(time)), []); + // const users = ['Bryan', 'has', 'no', 'girls', 'also', 'the', 'scouting', 'app', 'works','on','his','computer']; - const assignments = assignTasks(times, users); - for (const user in assignments) { - console.log(`${user}: ${assignments[user]}`); - } + // const assignments = assignTasks(times, users); + // for (const user in assignments) { + // console.log(`${user}: ${assignments[user]}`); + // } \ No newline at end of file From 18a0fea34f0573f1493e5d3543c68a8e645ffde8 Mon Sep 17 00:00:00 2001 From: Amaar Chughtai Date: Sat, 24 Feb 2024 16:12:30 -0800 Subject: [PATCH 2/2] Basic TRPC fetch for Team Events --- apps/nextjs/src/app/matches/page.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 apps/nextjs/src/app/matches/page.tsx diff --git a/apps/nextjs/src/app/matches/page.tsx b/apps/nextjs/src/app/matches/page.tsx new file mode 100644 index 0000000..7ab86c8 --- /dev/null +++ b/apps/nextjs/src/app/matches/page.tsx @@ -0,0 +1,19 @@ +import React from "react"; +import { createTRPCClient } from "@trpc/client"; +import { httpBatchLink } from "@trpc/client/links/httpBatchLink"; +import { createTRPCReact } from "@trpc/react-query"; + +import type { AppRouter } from "@acme/api"; + +const api = createTRPCReact(); + +export default async function getTeamEvents(teamKey: string, year: number) { + const teamEvents = await api.tba.teamEvents.useQuery({ + teamKey, + year, + }); + console.log(teamEvents); + return teamEvents; +} + +console.log("HAAAAAAA: ", getTeamEvents("frc254", 2023));