2024-06-04 23:00:22 +03:00
|
|
|
'use client';
|
|
|
|
|
2025-02-15 18:33:05 +03:00
|
|
|
import { useLayoutEffect } from 'react';
|
2025-02-12 21:36:25 +03:00
|
|
|
import clsx from 'clsx';
|
2024-06-04 23:00:22 +03:00
|
|
|
|
2025-01-27 15:03:48 +03:00
|
|
|
import { useConceptNavigation } from '@/app/Navigation/NavigationContext';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Overlay } from '@/components/Container';
|
|
|
|
import { TabLabel, TabList, TabPanel, Tabs } from '@/components/Tabs';
|
2025-01-14 21:58:16 +03:00
|
|
|
import { useAppLayoutStore } from '@/stores/appLayout';
|
2024-06-04 23:00:22 +03:00
|
|
|
|
2025-02-19 23:30:35 +03:00
|
|
|
import { EditorOssCard } from './EditorOssCard';
|
|
|
|
import { EditorOssGraph } from './EditorOssGraph';
|
|
|
|
import { MenuOssTabs } from './MenuOssTabs';
|
2025-01-27 15:03:48 +03:00
|
|
|
import { OssTabID, useOssEdit } from './OssEditContext';
|
2024-06-04 23:00:22 +03:00
|
|
|
|
2025-01-30 19:23:15 +03:00
|
|
|
interface OssTabsProps {
|
|
|
|
activeTab: OssTabID;
|
|
|
|
}
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-19 23:30:35 +03:00
|
|
|
export function OssTabs({ activeTab }: OssTabsProps) {
|
2025-01-30 19:23:15 +03:00
|
|
|
const router = useConceptNavigation();
|
2025-01-27 15:03:48 +03:00
|
|
|
const { schema, navigateTab } = useOssEdit();
|
2024-06-04 23:00:22 +03:00
|
|
|
|
2025-01-14 21:58:16 +03:00
|
|
|
const hideFooter = useAppLayoutStore(state => state.hideFooter);
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-15 18:33:05 +03:00
|
|
|
useLayoutEffect(() => {
|
2025-01-27 15:03:48 +03:00
|
|
|
const oldTitle = document.title;
|
|
|
|
document.title = schema.title;
|
|
|
|
return () => {
|
|
|
|
document.title = oldTitle;
|
|
|
|
};
|
|
|
|
}, [schema.title]);
|
2024-06-04 23:00:22 +03:00
|
|
|
|
2025-02-15 18:33:05 +03:00
|
|
|
useLayoutEffect(() => {
|
2025-01-14 21:58:16 +03:00
|
|
|
hideFooter(activeTab === OssTabID.GRAPH);
|
|
|
|
}, [activeTab, hideFooter]);
|
2024-08-14 21:50:28 +03:00
|
|
|
|
2024-06-04 23:00:22 +03:00
|
|
|
function onSelectTab(index: number, last: number, event: Event) {
|
|
|
|
if (last === index) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.type == 'keydown') {
|
|
|
|
const kbEvent = event as KeyboardEvent;
|
|
|
|
if (kbEvent.altKey) {
|
|
|
|
if (kbEvent.code === 'ArrowLeft') {
|
|
|
|
router.back();
|
|
|
|
return;
|
|
|
|
} else if (kbEvent.code === 'ArrowRight') {
|
|
|
|
router.forward();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
navigateTab(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2025-01-27 15:03:48 +03:00
|
|
|
<Tabs
|
|
|
|
selectedIndex={activeTab}
|
|
|
|
onSelect={onSelectTab}
|
|
|
|
defaultFocus
|
|
|
|
selectedTabClassName='clr-selected'
|
2025-02-20 17:08:23 +03:00
|
|
|
className='flex flex-col mx-auto min-w-fit items-center'
|
2025-01-27 15:03:48 +03:00
|
|
|
>
|
|
|
|
<Overlay position='top-0 right-1/2 translate-x-1/2' layer='z-sticky'>
|
|
|
|
<TabList className={clsx('w-fit', 'flex items-stretch', 'border-b-2 border-x-2 divide-x-2', 'bg-prim-200')}>
|
|
|
|
<MenuOssTabs />
|
|
|
|
|
|
|
|
<TabLabel label='Карточка' title={schema.title ?? ''} />
|
|
|
|
<TabLabel label='Граф' />
|
|
|
|
</TabList>
|
|
|
|
</Overlay>
|
|
|
|
|
|
|
|
<div className='overflow-x-hidden'>
|
|
|
|
<TabPanel>
|
2025-02-19 23:30:35 +03:00
|
|
|
<EditorOssCard />
|
2025-01-27 15:03:48 +03:00
|
|
|
</TabPanel>
|
|
|
|
|
|
|
|
<TabPanel>
|
2025-02-19 23:30:35 +03:00
|
|
|
<EditorOssGraph />
|
2025-01-27 15:03:48 +03:00
|
|
|
</TabPanel>
|
|
|
|
</div>
|
|
|
|
</Tabs>
|
2024-06-04 23:00:22 +03:00
|
|
|
);
|
|
|
|
}
|