Skip to content

Commit f5e6562

Browse files
committed
refactor(web): use-set-to-store-favorite-case-ids
1 parent 2d3fa5b commit f5e6562

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

web/src/components/CaseStarButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const StyledButton = styled(Button)<{ starred: boolean }>`
3636
const CaseStarButton: React.FC<{ id: string }> = ({ id }) => {
3737
const { starredCases, starCase } = useStarredCases();
3838
const isDesktop = useIsDesktop();
39-
const starred = useMemo(() => Boolean(starredCases.get(id)), [id, starredCases]);
39+
const starred = useMemo(() => Boolean(starredCases.has(id)), [id, starredCases]);
4040
const text = starred ? "Remove from favorite" : "Add to favorite";
4141
return (
4242
<Tooltip {...{ text }} place={isDesktop ? "top" : "bottom"}>

web/src/hooks/useStarredCases.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { useMemo } from "react";
33
import { useLocalStorage } from "./useLocalStorage";
44

55
const useStarredCases = () => {
6-
const initialValue = new Map<string, boolean>();
6+
const initialValue = new Set<string>();
77

88
const [localStarredCases, setLocalStarredCases] = useLocalStorage("starredCases", Array.from(initialValue));
99

10-
const starredCases = useMemo(() => new Map<string, boolean>(localStarredCases), [localStarredCases]);
10+
const starredCases = useMemo(() => new Set<string>(localStarredCases), [localStarredCases]);
1111
const starredCaseIds = Array.from(starredCases.keys());
1212

1313
const starCase = (id: string) => {
14-
if (starredCases.get(id)) starredCases.delete(id);
15-
else starredCases.set(id, true);
14+
if (starredCases.has(id)) starredCases.delete(id);
15+
else starredCases.add(id);
1616

1717
setLocalStarredCases(Array.from(starredCases));
1818
};

0 commit comments

Comments
 (0)