Skip to content

Commit 83409fc

Browse files
like contestも一緒に表示するトグルスイッチ追加
1 parent 52bba0c commit 83409fc

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
} from "reactstrap";
1515
import { HelpBadgeTooltip } from "../../components/HelpBadgeTooltip";
1616
import { ColorMode } from "../../utils/TableColor";
17+
import { ContestCategory } from "../../utils/ContestClassifier";
18+
import { getLikeContest } from "../../utils/LikeContestUtils";
1719

1820
interface Props {
1921
hideCompletedContest: boolean;
@@ -27,9 +29,22 @@ interface Props {
2729
selectableLanguages: Set<string>;
2830
selectedLanguages: Set<string>;
2931
toggleLanguage: (language: string) => void;
32+
active: ContestCategory;
33+
setSelectedContests: (contest: ContestCategory[]) => void;
34+
showableShowLikeContest: boolean;
35+
showLikeContest: boolean;
36+
setShowLikeContest: (showLikeContest: boolean) => void;
3037
}
3138

3239
export const Options: React.FC<Props> = (props) => {
40+
const changeShowLikeContest = (checked: boolean) => {
41+
const likeContest = getLikeContest(props.active);
42+
if (checked && likeContest) {
43+
props.setSelectedContests([props.active, likeContest]);
44+
} else {
45+
props.setSelectedContests([props.active]);
46+
}
47+
};
3348
return (
3449
<>
3550
<Row className="my-4">
@@ -59,6 +74,22 @@ export const Options: React.FC<Props> = (props) => {
5974
Internal rating to have 50% Solve Probability
6075
</HelpBadgeTooltip>
6176
</FormGroup>
77+
{props.showableShowLikeContest && (
78+
<FormGroup check inline class="my-4">
79+
<Label check>
80+
<CustomInput
81+
type="switch"
82+
id="showLikeContest"
83+
label="Show Like Contest"
84+
checked={props.showLikeContest}
85+
onChange={(e) => {
86+
changeShowLikeContest(e.target.checked);
87+
props.setShowLikeContest(!props.showLikeContest);
88+
}}
89+
/>
90+
</Label>
91+
</FormGroup>
92+
)}
6293
{props.colorMode === ColorMode.ContestResult && (
6394
<FormGroup check inline>
6495
<Label check>

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ import {
44
ContestCategories,
55
ContestCategory,
66
} from "../../utils/ContestClassifier";
7+
import { getLikeContest } from "../../utils/LikeContestUtils";
78

89
interface Props {
910
active: ContestCategory;
1011
setActive: (next: ContestCategory) => void;
12+
setSelectedContests: (contest: ContestCategory[]) => void;
13+
showLikeContest: boolean;
1114
}
1215

1316
export const TableTabButtons: React.FC<Props> = (props) => {
14-
const { active, setActive } = props;
17+
const { active, setActive, setSelectedContests, showLikeContest } = props;
18+
19+
const resetSelectedContests = (category: ContestCategory) => {
20+
const selectContests = [category];
21+
const likeContest = getLikeContest(category);
22+
if (likeContest && showLikeContest) selectContests.push(likeContest);
23+
setSelectedContests(selectContests);
24+
};
1525
return (
1626
<Row>
1727
<ButtonGroup className="table-tab">
@@ -21,6 +31,7 @@ export const TableTabButtons: React.FC<Props> = (props) => {
2131
color="secondary"
2232
onClick={(): void => {
2333
setActive(category);
34+
resetSelectedContests(category);
2435
}}
2536
active={active === category}
2637
>

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
classifyContest,
2222
ContestCategory,
2323
} from "../../utils/ContestClassifier";
24+
import { hasLikeContest, getLikeContest } from "../../utils/LikeContestUtils";
2425
import { TableTabButtons } from "./TableTab";
2526
import { Options } from "./Options";
2627
import { ContestTable } from "./ContestTable";
@@ -52,7 +53,17 @@ export const TablePage: React.FC<OuterProps> = (props) => {
5253
"showPenalties",
5354
false
5455
);
56+
const [showLikeContest, setShowLikeContest] = useLocalStorage(
57+
"showLikeContest",
58+
false
59+
);
5560
const [selectedLanguages, setSelectedLanguages] = useState(new Set<string>());
61+
const selectContests = [activeTab];
62+
const likeContest = getLikeContest(activeTab);
63+
if (likeContest && showLikeContest) selectContests.push(likeContest);
64+
const [selectedContests, setSelectedContests] = useState<ContestCategory[]>([
65+
...selectContests,
66+
]);
5667
const userRatingInfo = useRatingInfo(props.userId);
5768
const contestToProblems =
5869
useContestToMergedProblems() ?? new Map<ContestId, MergedProblem[]>();
@@ -77,7 +88,8 @@ export const TablePage: React.FC<OuterProps> = (props) => {
7788
props.userId
7889
);
7990
const filteredContests =
80-
contests?.filter((c) => classifyContest(c) === activeTab) ?? [];
91+
contests?.filter((c) => selectedContests.includes(classifyContest(c))) ??
92+
[];
8193

8294
return (
8395
<div>
@@ -99,8 +111,18 @@ export const TablePage: React.FC<OuterProps> = (props) => {
99111
newSet.has(language) ? newSet.delete(language) : newSet.add(language);
100112
setSelectedLanguages(newSet);
101113
}}
114+
active={activeTab}
115+
setSelectedContests={setSelectedContests}
116+
showableShowLikeContest={hasLikeContest(activeTab)}
117+
showLikeContest={showLikeContest}
118+
setShowLikeContest={setShowLikeContest}
119+
/>
120+
<TableTabButtons
121+
active={activeTab}
122+
setActive={setActiveTab}
123+
setSelectedContests={setSelectedContests}
124+
showLikeContest={showLikeContest}
102125
/>
103-
<TableTabButtons active={activeTab} setActive={setActiveTab} />
104126
{[
105127
"ABC",
106128
"ARC",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ContestCategory } from "./ContestClassifier";
2+
3+
export const getLikeContest = (
4+
contestCategory: ContestCategory
5+
): ContestCategory | undefined => {
6+
switch (contestCategory) {
7+
case "ABC":
8+
return "ABC-Like";
9+
case "ARC":
10+
return "ARC-Like";
11+
case "AGC":
12+
return "AGC-Like";
13+
default:
14+
break;
15+
}
16+
};
17+
18+
export const hasLikeContest = (contestCategory: ContestCategory): boolean => {
19+
return ["ABC", "ARC", "AGC"].includes(contestCategory);
20+
};

atcoder-problems-frontend/src/utils/LocalStorage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const LocalStorageKeys = [
1717
"recommendOption",
1818
"recommendExperimental",
1919
"recoomendExcludeOption",
20+
"showLikeContest",
2021
] as const;
2122
type LocalStorageKey = typeof LocalStorageKeys[number];
2223

0 commit comments

Comments
 (0)