-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathAppNavBar.tsx
More file actions
54 lines (47 loc) · 2.02 KB
/
AppNavBar.tsx
File metadata and controls
54 lines (47 loc) · 2.02 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
import { Box, Text } from '@mantine/core';
import { useMemo } from 'react';
import { ReactMarkdownWrapper } from '../ReactMarkdownWrapper';
import { useStudyConfig } from '../../store/hooks/useStudyConfig';
import { useStoredAnswer } from '../../store/hooks/useStoredAnswer';
import { ResponseBlock } from '../response/ResponseBlock';
import { useCurrentComponent } from '../../routes/utils';
import { getComponentName, studyComponentToIndividualComponent } from '../../utils/handleComponentInheritance';
export function AppNavBar({ width, top, sidebarOpen }: { width: number, top: number, sidebarOpen: boolean }) {
// Get the config for the current step
const studyConfig = useStudyConfig();
const currentComponent = useCurrentComponent();
const stepConfig = studyConfig.components[getComponentName(currentComponent)];
const currentConfig = useMemo(() => {
if (stepConfig) {
return studyComponentToIndividualComponent(stepConfig, studyConfig);
}
return null;
}, [stepConfig, studyConfig]);
const status = useStoredAnswer();
const instruction = currentConfig?.instruction || '';
const instructionLocation = useMemo(() => currentConfig?.instructionLocation ?? studyConfig.uiConfig.instructionLocation ?? 'sidebar', [currentConfig, studyConfig]);
const instructionInSideBar = instructionLocation === 'sidebar';
return currentConfig ? (
<Box className="sidebar" bg="gray.1" display={sidebarOpen ? 'block' : 'none'} style={{ zIndex: 0, marginTop: top, position: 'relative' }} w={width} miw={width}>
{instructionInSideBar && instruction !== '' && (
<Box
bg="gray.3"
p="md"
>
<Text span c="orange.8" fw={700} inherit>
Task:
</Text>
<ReactMarkdownWrapper text={instruction} />
</Box>
)}
<Box p="md">
<ResponseBlock
key={`${currentComponent}-sidebar-response-block`}
status={status}
config={currentConfig}
location="sidebar"
/>
</Box>
</Box>
) : null;
}