Skip to content

Commit 69ce1c0

Browse files
committed
Cardの表示修正
1 parent 549bb05 commit 69ce1c0

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

web/components/Card.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ const CardFront = ({ displayedUser, currentUser }: CardProps) => {
1717
const [isHiddenInterestExist, setHiddenInterestExist] = useState(false);
1818
const [isHiddenCourseExist, setHiddenCourseExist] = useState(false);
1919

20-
useEffect(() => {
21-
const container = containerRef.current;
22-
if (!container) return;
23-
24-
const resizeObserver = new ResizeObserver(() => {
25-
calculateVisibleInterests();
26-
calculateVisibleCourses();
27-
});
28-
29-
resizeObserver.observe(container);
30-
31-
calculateVisibleInterests(); // 初期計算
32-
calculateVisibleCourses(); // 初期計算
33-
34-
return () => resizeObserver.disconnect();
35-
}, []);
36-
3720
const calculateVisibleCourses = useCallback(() => {
3821
const courses = displayedUser.courses;
3922
const container = coursesContainerRef.current;
@@ -75,7 +58,7 @@ const CardFront = ({ displayedUser, currentUser }: CardProps) => {
7558
if (coursesContainer.offsetHeight + 30 <= containerHeight) {
7659
coursesContainer.appendChild(element);
7760
} else {
78-
setHiddenCourseExist;
61+
setHiddenCourseExist(true);
7962
}
8063
}
8164
}, [displayedUser, currentUser]);
@@ -132,6 +115,24 @@ const CardFront = ({ displayedUser, currentUser }: CardProps) => {
132115
}
133116
}, [displayedUser, currentUser]);
134117

118+
useEffect(() => {
119+
const container = containerRef.current;
120+
if (!container) return;
121+
122+
const resizeObserver = new ResizeObserver(() => {
123+
calculateVisibleInterests();
124+
calculateVisibleCourses();
125+
});
126+
127+
resizeObserver.observe(container);
128+
129+
// 初期計算を実行
130+
calculateVisibleInterests();
131+
calculateVisibleCourses();
132+
133+
return () => resizeObserver.disconnect();
134+
}, [calculateVisibleInterests, calculateVisibleCourses]);
135+
135136
return (
136137
<div className="flex h-full flex-col gap-5 overflow-clip border-2 border-primary bg-secondary p-5">
137138
<div className="grid h-[20%] grid-cols-3 items-center">

0 commit comments

Comments
 (0)