-
-
Notifications
You must be signed in to change notification settings - Fork 578
Expand file tree
/
Copy pathSettingsDrawer.tsx
More file actions
104 lines (89 loc) · 3.57 KB
/
SettingsDrawer.tsx
File metadata and controls
104 lines (89 loc) · 3.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-disable react/no-multi-comp */
import React from 'react';
import dynamic from 'next/dynamic';
import useTranslation from 'next-translate/useTranslation';
import { useDispatch, useSelector } from 'react-redux';
import drawerStyles from '../Drawer/Drawer.module.scss';
import SettingsBodySkeleton from './SettingsBodySkeleton';
import styles from './SettingsDrawer.module.scss';
import Drawer, { DrawerType } from '@/components/Navbar/Drawer';
import { useOnboarding } from '@/components/Onboarding/OnboardingProvider';
import Button, { ButtonVariant } from '@/dls/Button/Button';
import BackIcon from '@/icons/west.svg';
import { selectNavbar, setSettingsView, SettingsView } from '@/redux/slices/navbar';
import { selectStudyModeIsOpen } from '@/redux/slices/QuranReader/studyMode';
import { logValueChange } from '@/utils/eventLogger';
const SettingsBody = dynamic(() => import('./SettingsBody'), {
ssr: false,
loading: () => <SettingsBodySkeleton />,
});
const ReciterSelectionBody = dynamic(() => import('./ReciterSelectionBody'), {
ssr: false,
});
const TranslationSelectionBody = dynamic(() => import('./TranslationSelectionBody'), {
ssr: false,
});
const TafsirSelectionBody = dynamic(() => import('./TafsirSelectionBody'), {
ssr: false,
});
const SettingsDrawer = () => {
const { t } = useTranslation('common');
const dispatch = useDispatch();
const { isSettingsDrawerOpen, settingsView } = useSelector(selectNavbar);
const isStudyModeOpen = useSelector(selectStudyModeIsOpen);
const { isActive } = useOnboarding();
const onGoBackClicked = () => {
dispatch(setSettingsView(SettingsView.Body));
logValueChange('settings_view', SettingsView.Body, settingsView);
};
let header;
if (settingsView === SettingsView.Body) header = <> </>;
if (settingsView !== SettingsView.Body) {
header = (
<div className={styles.headerContainer}>
<Button variant={ButtonVariant.Ghost} onClick={onGoBackClicked}>
<BackIcon />
</Button>
{settingsView === SettingsView.Translation && t('translations')}
{settingsView === SettingsView.Reciter && t('reciter')}
{settingsView === SettingsView.Tafsir && t('tafsir.title')}
</div>
);
}
const isTranslationView = settingsView === SettingsView.Translation;
const isReciterView = settingsView === SettingsView.Reciter;
const getDrawerClassName = () => {
return [
isTranslationView ? drawerStyles.translationView : undefined,
isReciterView ? drawerStyles.reciterView : undefined,
isStudyModeOpen ? drawerStyles.studyModeOverlayLevel : undefined,
]
.filter(Boolean)
.join(' ');
};
return (
<Drawer
id="settings-drawer"
data-testid="settings-drawer"
type={DrawerType.Settings}
header={header}
closeOnNavigation={false}
canCloseDrawer={!isActive}
bodyId="settings-drawer-body"
removeHeaderWrapper={settingsView === SettingsView.Body}
hideCloseButton={settingsView === SettingsView.Body}
removeBodySpacing={settingsView === SettingsView.Body}
className={getDrawerClassName()}
>
{isSettingsDrawerOpen && (
<div data-testid="settings-drawer-body" className={styles.bodyWrapper}>
{settingsView === SettingsView.Body && <SettingsBody />}
{settingsView === SettingsView.Translation && <TranslationSelectionBody />}
{settingsView === SettingsView.Reciter && <ReciterSelectionBody />}
{settingsView === SettingsView.Tafsir && <TafsirSelectionBody />}
</div>
)}
</Drawer>
);
};
export default SettingsDrawer;