2025-02-23 16:54:11 +03:00
|
|
|
import { urls, useConceptNavigation } from '@/app';
|
|
|
|
import { useAuthSuspense } from '@/features/auth';
|
|
|
|
import { useRoleStore, UserRole } from '@/features/users';
|
|
|
|
|
2025-03-12 12:04:50 +03:00
|
|
|
import { Divider } from '@/components/container';
|
|
|
|
import { Button } from '@/components/control';
|
|
|
|
import { Dropdown, DropdownButton, useDropdown } from '@/components/dropdown';
|
|
|
|
import { IconDestroy, IconLibrary, IconMenu, IconNewItem, IconQR, IconShare } from '@/components/icons';
|
2025-02-23 16:54:11 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
|
|
|
import { generatePageQR, sharePage } from '@/utils/utils';
|
|
|
|
|
2025-03-12 11:55:43 +03:00
|
|
|
import { useMutatingOss } from '../../backend/use-mutating-oss';
|
2025-02-23 16:54:11 +03:00
|
|
|
|
2025-03-12 11:55:43 +03:00
|
|
|
import { useOssEdit } from './oss-edit-context';
|
2025-02-23 16:54:11 +03:00
|
|
|
|
|
|
|
export function MenuMain() {
|
|
|
|
const router = useConceptNavigation();
|
|
|
|
const { isMutable, deleteSchema } = useOssEdit();
|
|
|
|
const isProcessing = useMutatingOss();
|
|
|
|
|
|
|
|
const { isAnonymous } = useAuthSuspense();
|
|
|
|
|
|
|
|
const role = useRoleStore(state => state.role);
|
|
|
|
|
|
|
|
const showQR = useDialogsStore(state => state.showQR);
|
|
|
|
|
2025-03-20 19:47:08 +03:00
|
|
|
const menu = useDropdown();
|
2025-02-23 16:54:11 +03:00
|
|
|
|
|
|
|
function handleDelete() {
|
2025-03-20 19:47:08 +03:00
|
|
|
menu.hide();
|
2025-02-23 16:54:11 +03:00
|
|
|
deleteSchema();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleShare() {
|
2025-03-20 19:47:08 +03:00
|
|
|
menu.hide();
|
2025-02-23 16:54:11 +03:00
|
|
|
sharePage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleCreateNew() {
|
2025-02-26 16:28:29 +03:00
|
|
|
router.push({ path: urls.create_schema });
|
2025-02-23 16:54:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleShowQR() {
|
2025-03-20 19:47:08 +03:00
|
|
|
menu.hide();
|
2025-02-23 16:54:11 +03:00
|
|
|
showQR({ target: generatePageQR() });
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2025-03-20 19:47:08 +03:00
|
|
|
<div ref={menu.ref} onBlur={menu.handleBlur} className='relative'>
|
2025-02-23 16:54:11 +03:00
|
|
|
<Button
|
|
|
|
dense
|
|
|
|
noBorder
|
|
|
|
noOutline
|
|
|
|
tabIndex={-1}
|
|
|
|
title='Меню'
|
2025-03-20 19:47:08 +03:00
|
|
|
hideTitle={menu.isOpen}
|
2025-02-23 16:54:11 +03:00
|
|
|
icon={<IconMenu size='1.25rem' className='clr-text-controls' />}
|
|
|
|
className='h-full pl-2'
|
2025-03-20 19:47:08 +03:00
|
|
|
onClick={menu.toggle}
|
2025-02-23 16:54:11 +03:00
|
|
|
/>
|
2025-03-20 19:47:08 +03:00
|
|
|
<Dropdown isOpen={menu.isOpen} margin='mt-3'>
|
2025-02-23 16:54:11 +03:00
|
|
|
<DropdownButton
|
|
|
|
text='Поделиться'
|
2025-03-20 11:33:42 +03:00
|
|
|
title='Скопировать ссылку в буфер обмена'
|
2025-02-23 16:54:11 +03:00
|
|
|
icon={<IconShare size='1rem' className='icon-primary' />}
|
|
|
|
onClick={handleShare}
|
|
|
|
/>
|
|
|
|
<DropdownButton
|
|
|
|
text='QR-код'
|
|
|
|
title='Показать QR-код схемы'
|
|
|
|
icon={<IconQR size='1rem' className='icon-primary' />}
|
|
|
|
onClick={handleShowQR}
|
|
|
|
/>
|
|
|
|
{isMutable ? (
|
|
|
|
<DropdownButton
|
|
|
|
text='Удалить схему'
|
|
|
|
icon={<IconDestroy size='1rem' className='icon-red' />}
|
|
|
|
onClick={handleDelete}
|
2025-03-20 11:33:42 +03:00
|
|
|
disabled={isProcessing || role < UserRole.OWNER}
|
2025-02-23 16:54:11 +03:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
<Divider margins='mx-3 my-1' />
|
|
|
|
|
|
|
|
{!isAnonymous ? (
|
|
|
|
<DropdownButton
|
|
|
|
text='Создать новую схему'
|
|
|
|
icon={<IconNewItem size='1rem' className='icon-primary' />}
|
|
|
|
onClick={handleCreateNew}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<DropdownButton
|
|
|
|
text='Библиотека'
|
|
|
|
icon={<IconLibrary size='1rem' className='icon-primary' />}
|
2025-02-26 16:28:29 +03:00
|
|
|
onClick={() => router.push({ path: urls.library })}
|
2025-02-23 16:54:11 +03:00
|
|
|
/>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|