-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMandal.tsx
More file actions
61 lines (54 loc) · 1.78 KB
/
Mandal.tsx
File metadata and controls
61 lines (54 loc) · 1.78 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useMandalView } from './hook/useMandalView';
import * as styles from './Mandal.css';
import Toggle from './component/Toggle/Toggle';
import EntireMandal from './component/EntireMandal/EntireMandal';
import EditBtn from './component/EditBtn/EditBtn';
import { useMandalAll } from '@/api/domain/mandalAll/hook';
import { useMandalartId } from '@/common/hook/useMandalartId';
import Mandalart from '@/common/component/Mandalart/Mandalart';
const Mandal = () => {
const { viewType, handleViewChange } = useMandalView();
const mandalartId = useMandalartId();
const { data: mandalartData } = useMandalAll(mandalartId);
if (!mandalartData) {
return null;
}
const mainGoalData = {
id: 0,
position: 0,
title: mandalartData.title,
subGoals: Array.from({ length: 8 }, (_, i) => i + 1).map((position) => {
const goalsWithPosition = mandalartData.coreGoals
.filter((goal) => goal.position === position)
.sort((a, b) => b.id - a.id);
const latestGoal = goalsWithPosition[0];
return latestGoal
? {
id: latestGoal.id,
title: latestGoal.title,
position: latestGoal.position,
subGoals: latestGoal.subGoals || [],
}
: {
id: 0,
title: '',
position,
subGoals: [],
};
}),
};
return (
<div className={styles.viewContainer}>
<Toggle defaultValue="onlygoal" onChange={handleViewChange} />
{viewType === 'onlygoal' ? (
<Mandalart type="MY_MANDAL" data={mainGoalData} />
) : (
<EntireMandal coreGoals={mandalartData.coreGoals} mainTitle={mandalartData.title} />
)}
<div className={styles.editBtnContainer}>
<EditBtn />
</div>
</div>
);
};
export default Mandal;