Skip to content

Commit 6391010

Browse files
committed
Test fix
1 parent aede29b commit 6391010

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Servers/UI/OJS.Servers.Ui/ClientApp/src/components/profile/profile-contest-participations/ProfileContestParticipations.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ const ProfileContestParticipations = ({
133133

134134
const categoryContestsMap = useMemo(() => {
135135
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+
}
142147
return map;
143148
}, [ allParticipatedContests ]);
144149

@@ -147,7 +152,10 @@ const ProfileContestParticipations = ({
147152
categoryContestsMap.forEach((contests, categoryId) => {
148153
map.set(categoryId, contests.map((c) => ({ id: c.id, name: `${c.name} (${c.category})` })));
149154
});
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+
: []);
151159
return map;
152160
}, [ categoryContestsMap, allParticipatedContests ]);
153161

@@ -160,11 +168,14 @@ const ProfileContestParticipations = ({
160168

161169
const categoryDropdownItems = useMemo(() => {
162170
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+
}
168179
return Array.from(map.entries())
169180
.map(([ id, name ]) => ({ id, name: `${name} (#${id})` }))
170181
.sort((a, b) => a.name.localeCompare(b.name));

0 commit comments

Comments
 (0)