[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #31 from Team3256/warrior-sad-refactor
Browse files Browse the repository at this point in the history
Warrior Sad Refactor
  • Loading branch information
ThatXliner committed Apr 1, 2024
2 parents 17f6556 + e90b4c0 commit 68cd96f
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 277 deletions.
73 changes: 58 additions & 15 deletions apps/nextjs/src/app/dashboard/Assignments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`, []])),
Expand All @@ -64,7 +102,7 @@ function Assignments({ selectedEvent }) {
console.log("HEEEEE: ", members);
}
fetchData();
}, []);
}, [members]);
const [assignments, setAssignments] = useState<string[]>([]); // Updated t
const [activeId, setActiveId] = useState<string | null>(null);
// Inverted members
Expand All @@ -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,
}));
Expand All @@ -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: <explanation>
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: <explanation>
Object.values(alliances).forEach((alliance: any) => {
Object.values(alliances).forEach((alliance: Alliance) => {
// Extract team keys from the alliance
const teamKeys = alliance.team_keys;

Expand All @@ -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++;
}
Expand All @@ -142,7 +180,7 @@ function Assignments({ selectedEvent }) {
// Update the state with the newAssignments array
setAssignments(newAssignments);
}
}, [isLoading, data]);
}, [isLoading, data, selectedEvent]);
return (
<>
{/* <ModalSelectComponent /> */}
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/dashboard/components/cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function AssignmentCard({ assignment }: { assignment: string }) {
</CardHeader>
<CardContent>
{" "}
I HAVE NO GIRLS
Quantitative Scouting
{/* </Button> */}
{/* <form>
<div className="grid w-full items-center gap-4">
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function RootLayout({
<div className="flex h-16 items-center px-4">
{/* <TeamSwitcher /> */}
{/* XXX: Dynamic MainNav */}
<MainNav className="mx-6" currentlySelected="Overview" />
<MainNav className="mx-6" currentlySelected="Assignments" />
<div className="ml-auto flex items-center space-x-4">
<Search />
<UserNav />
Expand Down
Loading

0 comments on commit 68cd96f

Please sign in to comment.