-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStreakTrackerSection.tsx
More file actions
42 lines (33 loc) · 1.38 KB
/
StreakTrackerSection.tsx
File metadata and controls
42 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useState } from 'react';
import { StreakDetail, StreakGrid } from '@/page/history/component';
import * as styles from '@/page/history/StreakTrackerSection/StreakTrackerSection.css';
import { useGetStreak } from '@/api/domain/history/hook/useGetStreak';
import { useMandalartId } from '@/common/hook/useMandalartId';
import Loading from '@/common/component/Loading/Loading';
type StreakTrackerProps = {
selectedDay: number | null;
setSelectedDay: (day: number | null) => void;
};
const StreakTracker = ({ selectedDay, setSelectedDay }: StreakTrackerProps) => {
const [hoveredDay, setHoveredDay] = useState<number | null>(null);
const isLocked = selectedDay !== null;
const visibleDay = isLocked ? selectedDay : hoveredDay;
const mandalartId = useMandalartId();
const { data, isLoading } = useGetStreak(mandalartId);
if (isLoading || !data) {
return <Loading type="history" />;
}
const detailData =
visibleDay !== null
? data.streaks.find((streak) => streak.streakDay === visibleDay)
: undefined;
return (
<div className={styles.streakTrackerContainer}>
<div onClick={(e) => e.stopPropagation()} className={styles.streakGridContainer}>
<StreakGrid streaks={data.streaks} onHover={setHoveredDay} onSelect={setSelectedDay} />
</div>
<StreakDetail detailData={detailData} />
</div>
);
};
export default StreakTracker;