@@ -23,7 +23,7 @@ import { assignTasks } from "@/lib/utils/autoassign";
23
23
import { trpc } from "@/lib/utils/trpc" ;
24
24
import { DndContext , DragOverlay , useDroppable } from "@dnd-kit/core" ;
25
25
26
- import { addMatches , getEmails } from "./actions" ;
26
+ import { addAssignment , addMatches , getEmails } from "./actions" ;
27
27
import { AssignmentCard , MemberCard } from "./components/cards" ;
28
28
import { CalendarDateRangePicker } from "./components/date-range-picker" ;
29
29
import { MainNav } from "./components/main-nav" ;
@@ -54,9 +54,7 @@ function Assignments({ selectedEvent }) {
54
54
// const [members, setMembers] = useState<{ [key: string]: string[] }>(
55
55
// Object.fromEntries(tags.map((x) => [`${x}M`, []])),
56
56
// );
57
- const [ members , setMembers ] = useState < { [ key : string ] : string [ ] } > ( {
58
- "" : [ ] ,
59
- } ) ;
57
+ const [ members , setMembers ] = useState < { [ key : string ] : string [ ] } > ( { } ) ;
60
58
// Object.fromEntries(tags.map((x) => [`${x}M`, []])),
61
59
62
60
//use useEffect to make a supabase request from the auth tabke to fill it with emails
@@ -92,6 +90,7 @@ function Assignments({ selectedEvent }) {
92
90
// Extract relevant information from the data and generate assignments
93
91
const matches = data . map ( ( match : any ) => ( {
94
92
match_num : match . match_num ,
93
+ // match_key: match.match_key,
95
94
alliances : match . alliances ,
96
95
} ) ) ;
97
96
const matchKeys = data . map ( ( match : any ) => ( {
@@ -112,7 +111,7 @@ function Assignments({ selectedEvent }) {
112
111
// biome-ignore lint/complexity/noForEach: <explanation>
113
112
matches . forEach ( ( match : any ) => {
114
113
// Extract match number and alliances
115
- const { match_num, alliances } = match ;
114
+ const { match_num, match_key , alliances } = match ;
116
115
117
116
// Iterate over each alliance (blue and red)
118
117
// biome-ignore lint/complexity/noForEach: <explanation>
@@ -125,6 +124,7 @@ function Assignments({ selectedEvent }) {
125
124
teamKeys . forEach ( ( teamKey : string ) => {
126
125
// Construct the assignment string with match number and team number
127
126
const assignment = `Match ${ c2 } - Team ${ teamKey } ` ;
127
+ // const assignment = `Match ${match_key} - Team ${teamKey}`;
128
128
count ++ ;
129
129
if ( count % 6 == 0 ) {
130
130
count = 0 ;
@@ -155,7 +155,73 @@ function Assignments({ selectedEvent }) {
155
155
} }
156
156
onDragEnd = { function handleDragEnd ( event ) {
157
157
const overId = event . over ?. id ;
158
- console . log ( "end" , overId , activeId , members , assignments ) ;
158
+ console . log (
159
+ "end" ,
160
+ "OVERID: " ,
161
+ overId ,
162
+ "ACTIVE ID: " ,
163
+ activeId ,
164
+ members ,
165
+ assignments ,
166
+ ) ;
167
+
168
+ // Find the match object corresponding to the activeTeamKey
169
+ if ( activeId && data ) {
170
+ const activeTeamKey = activeId . split ( " " ) [ 4 ] ;
171
+ const match = data . find ( ( match ) => {
172
+ // Check if activeTeamKey is part of the blue alliance
173
+ if ( match . alliances . blue . team_keys . includes ( activeTeamKey ) ) {
174
+ return true ; // Return true if found in blue alliance
175
+ }
176
+ // Check if activeTeamKey is part of the red alliance
177
+ if ( match . alliances . red . team_keys . includes ( activeTeamKey ) ) {
178
+ return true ; // Return true if found in red alliance
179
+ }
180
+ return false ; // Return false if not found in either alliance
181
+ } ) ;
182
+
183
+ // Check if the activeTeamKey is part of the blue alliance or the red alliance
184
+ const allianceColor = match . alliances . blue . team_keys . includes (
185
+ activeTeamKey ,
186
+ )
187
+ ? "blue"
188
+ : "red" ;
189
+ console . log ( "Alliance color:" , allianceColor ) ;
190
+
191
+ // Find the index of the match object within the data array
192
+ // const index = data.indexOf(match);
193
+ // Find the index of the team key within the blue or red alliance array
194
+ let index ;
195
+ if ( allianceColor === "blue" ) {
196
+ index = match . alliances . blue . team_keys . indexOf ( activeTeamKey ) ;
197
+ } else {
198
+ index = match . alliances . red . team_keys . indexOf ( activeTeamKey ) ;
199
+ }
200
+
201
+ // If the team key is found, return the corresponding index + 1
202
+ if ( index !== - 1 ) {
203
+ const correspondingIndex = index + 1 ;
204
+ console . log ( "Corresponding index:" , correspondingIndex ) ;
205
+ } else {
206
+ console . log ( "Team key not found in data." ) ;
207
+ }
208
+
209
+ const alliance = ( allianceColor + ( index + 1 ) ) as string ;
210
+ const matchNumber = parseInt ( activeId . split ( " " ) [ 1 ] ) ;
211
+
212
+ // Make sure index is within the valid range of data array
213
+
214
+ const currentMatchKey = data [ matchNumber - 1 ] . match_key ;
215
+ const currentTeam = parseInt ( activeId . split ( " " ) [ 4 ] . slice ( - 4 ) ) ;
216
+
217
+ addAssignment ( {
218
+ match : currentMatchKey ,
219
+ team : currentTeam ,
220
+ alliance : alliance ,
221
+ assignee : overId ,
222
+ } ) ;
223
+ }
224
+
159
225
if ( overId === undefined ) {
160
226
// Drag action was cancelled
161
227
return ;
0 commit comments