Skip to content

Commit c7423be

Browse files
committed
fix: merge variables into function
1 parent c6f8e40 commit c7423be

File tree

1 file changed

+15
-10
lines changed
  • atcoder-problems-frontend/src/pages/TablePage

1 file changed

+15
-10
lines changed

atcoder-problems-frontend/src/pages/TablePage/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useMemo, useState } from "react";
22
import { List } from "immutable";
33
import {
44
useContests,
@@ -82,15 +82,20 @@ export const TablePage: React.FC<OuterProps> = (props) => {
8282
props.userId
8383
);
8484

85-
const selectedContestCategories = [activeTab];
86-
const likeContestCategory = getLikeContestCategory(activeTab);
87-
if (likeContestCategory && mergeLikeContest) {
88-
selectedContestCategories.push(likeContestCategory);
89-
}
90-
const filteredContests =
91-
contests?.filter((c) =>
92-
selectedContestCategories.includes(classifyContest(c))
93-
) ?? [];
85+
const filteredContests = useMemo(() => {
86+
if (!contests) {
87+
return [];
88+
}
89+
return contests.filter((contest) => {
90+
const contestType = classifyContest(contest);
91+
if (contestType === activeTab) {
92+
return true;
93+
}
94+
return (
95+
mergeLikeContest && getLikeContestCategory(activeTab) === contestType
96+
);
97+
});
98+
}, [contests, activeTab, mergeLikeContest]);
9499

95100
return (
96101
<div>

0 commit comments

Comments
 (0)