@@ -133,12 +133,17 @@ const ProfileContestParticipations = ({
133
133
134
134
const categoryContestsMap = useMemo ( ( ) => {
135
135
const map = new Map < number , IIndexContestsType [ ] > ( ) ;
136
- allParticipatedContests ?. forEach ( ( contest ) => {
137
- if ( contest . categoryId ) {
138
- if ( ! map . has ( contest . categoryId ) ) { map . set ( contest . categoryId , [ ] ) ; }
139
- map . get ( contest . categoryId ) ! . push ( contest ) ;
140
- }
141
- } ) ;
136
+ // Ensure allParticipatedContests is an array before using forEach
137
+ if ( Array . isArray ( allParticipatedContests ) ) {
138
+ allParticipatedContests . forEach ( ( contest ) => {
139
+ if ( contest . categoryId ) {
140
+ if ( ! map . has ( contest . categoryId ) ) { map . set ( contest . categoryId , [ ] ) ; }
141
+ map . get ( contest . categoryId ) ! . push ( contest ) ;
142
+ }
143
+ } ) ;
144
+ } else if ( allParticipatedContests ) {
145
+ console . error ( 'Expected allParticipatedContests to be an array but got:' , typeof allParticipatedContests ) ;
146
+ }
142
147
return map ;
143
148
} , [ allParticipatedContests ] ) ;
144
149
@@ -147,7 +152,10 @@ const ProfileContestParticipations = ({
147
152
categoryContestsMap . forEach ( ( contests , categoryId ) => {
148
153
map . set ( categoryId , contests . map ( ( c ) => ( { id : c . id , name : `${ c . name } (${ c . category } )` } ) ) ) ;
149
154
} ) ;
150
- map . set ( 0 , allParticipatedContests ?. map ( ( c ) => ( { id : c . id , name : `${ c . name } (${ c . category } )` } ) ) || [ ] ) ;
155
+ // Ensure allParticipatedContests is an array before using map
156
+ map . set ( 0 , Array . isArray ( allParticipatedContests )
157
+ ? allParticipatedContests . map ( ( c ) => ( { id : c . id , name : `${ c . name } (${ c . category } )` } ) )
158
+ : [ ] ) ;
151
159
return map ;
152
160
} , [ categoryContestsMap , allParticipatedContests ] ) ;
153
161
@@ -160,11 +168,14 @@ const ProfileContestParticipations = ({
160
168
161
169
const categoryDropdownItems = useMemo ( ( ) => {
162
170
const map = new Map < number , string > ( ) ;
163
- allParticipatedContests ?. forEach ( ( contest ) => {
164
- if ( contest . categoryId && contest . category ) {
165
- map . set ( contest . categoryId , contest . category ) ;
166
- }
167
- } ) ;
171
+ // Ensure allParticipatedContests is an array before using forEach
172
+ if ( Array . isArray ( allParticipatedContests ) ) {
173
+ allParticipatedContests . forEach ( ( contest ) => {
174
+ if ( contest . categoryId && contest . category ) {
175
+ map . set ( contest . categoryId , contest . category ) ;
176
+ }
177
+ } ) ;
178
+ }
168
179
return Array . from ( map . entries ( ) )
169
180
. map ( ( [ id , name ] ) => ( { id, name : `${ name } (#${ id } )` } ) )
170
181
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
0 commit comments