2023-12-13 14:32:57 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-05-15 02:51:50 +03:00
|
|
|
import { useCallback, useState } from 'react';
|
|
|
|
|
2024-04-01 21:45:10 +03:00
|
|
|
import { urls } from '@/app/urls';
|
2023-12-26 14:23:51 +03:00
|
|
|
import { useConceptNavigation } from '@/context/NavigationContext';
|
2024-04-01 19:07:20 +03:00
|
|
|
import { useConceptOptions } from '@/context/OptionsContext';
|
2023-12-13 14:32:57 +03:00
|
|
|
import useQueryStrings from '@/hooks/useQueryStrings';
|
2024-05-15 02:51:50 +03:00
|
|
|
import { HelpTopic, topicParent } from '@/models/miscellaneous';
|
2023-11-26 02:24:16 +03:00
|
|
|
|
|
|
|
import TopicsList from './TopicsList';
|
|
|
|
import ViewTopic from './ViewTopic';
|
|
|
|
|
|
|
|
function ManualsPage() {
|
2023-12-13 14:32:57 +03:00
|
|
|
const router = useConceptNavigation();
|
|
|
|
const query = useQueryStrings();
|
2024-05-15 02:51:50 +03:00
|
|
|
const activeTopic = (query.get('topic') || HelpTopic.MAIN) as HelpTopic;
|
|
|
|
const [topicFolded, setFolded] = useState<Map<HelpTopic, boolean>>(
|
|
|
|
new Map(
|
|
|
|
Object.values(HelpTopic).map(value => {
|
|
|
|
const topic = value as HelpTopic;
|
|
|
|
return [
|
|
|
|
topic,
|
|
|
|
topicParent.get(activeTopic) !== topic && topicParent.get(topicParent.get(activeTopic)!) !== topic
|
|
|
|
];
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
2023-11-26 02:24:16 +03:00
|
|
|
|
2024-04-01 19:07:20 +03:00
|
|
|
const { mainHeight } = useConceptOptions();
|
2024-05-15 02:51:50 +03:00
|
|
|
const onFoldTopic = useCallback(
|
|
|
|
(target: HelpTopic, showChildren: boolean) => {
|
|
|
|
if (topicFolded.get(target) === !showChildren) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setFolded(
|
|
|
|
new Map(
|
|
|
|
Object.values(HelpTopic).map(value => {
|
|
|
|
const topic = value as HelpTopic;
|
|
|
|
if (topic === target) {
|
|
|
|
return [topic, !showChildren];
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!showChildren &&
|
|
|
|
(topicParent.get(topic) === target || topicParent.get(topicParent.get(topic)!) === target)
|
|
|
|
) {
|
|
|
|
return [topic, true];
|
|
|
|
}
|
|
|
|
const oldValue = topicFolded.get(topic)!;
|
|
|
|
return [topic, oldValue];
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[topicFolded]
|
|
|
|
);
|
2023-11-26 02:24:16 +03:00
|
|
|
|
2024-05-15 02:51:50 +03:00
|
|
|
const onSelectTopic = useCallback(
|
|
|
|
(newTopic: HelpTopic) => {
|
|
|
|
router.push(urls.help_topic(newTopic));
|
|
|
|
},
|
|
|
|
[router]
|
|
|
|
);
|
2023-11-26 02:24:16 +03:00
|
|
|
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<div className='flex w-full gap-2' style={{ minHeight: mainHeight }}>
|
2024-05-15 02:51:50 +03:00
|
|
|
<TopicsList
|
|
|
|
activeTopic={activeTopic}
|
|
|
|
onChangeTopic={topic => onSelectTopic(topic)}
|
|
|
|
topicFolded={topicFolded}
|
|
|
|
onFoldTopic={onFoldTopic}
|
|
|
|
/>
|
|
|
|
<ViewTopic topic={activeTopic} />
|
2023-12-28 14:04:44 +03:00
|
|
|
</div>
|
|
|
|
);
|
2023-11-26 02:24:16 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default ManualsPage;
|