Portal/rsconcept/frontend/src/pages/LibraryPage/ViewSideLocation.tsx

76 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-06-19 22:09:31 +03:00
import clsx from 'clsx';
2024-06-20 22:17:01 +03:00
import { motion } from 'framer-motion';
2024-07-25 23:32:09 +03:00
import { useCallback, useMemo } from 'react';
2024-06-20 21:10:59 +03:00
import { toast } from 'react-toastify';
2024-06-19 22:09:31 +03:00
2024-06-26 18:59:49 +03:00
import { IconFolderTree } from '@/components/Icons';
2024-06-20 11:28:22 +03:00
import BadgeHelp from '@/components/info/BadgeHelp';
2024-06-19 22:09:31 +03:00
import { CProps } from '@/components/props';
2024-06-26 18:59:49 +03:00
import SelectLocation from '@/components/select/SelectLocation';
2024-06-19 22:09:31 +03:00
import MiniButton from '@/components/ui/MiniButton';
2024-07-25 23:32:09 +03:00
import useWindowSize from '@/hooks/useWindowSize';
2024-06-19 22:09:31 +03:00
import { FolderNode, FolderTree } from '@/models/FolderTree';
2024-06-20 11:28:22 +03:00
import { HelpTopic } from '@/models/miscellaneous';
2024-07-25 23:32:09 +03:00
import { animateSideMinWidth } from '@/styling/animations';
2024-06-20 22:06:07 +03:00
import { PARAMETER, prefixes } from '@/utils/constants';
2024-06-26 18:59:49 +03:00
import { information } from '@/utils/labels';
2024-06-19 22:09:31 +03:00
2024-06-27 11:34:52 +03:00
interface ViewSideLocationProps {
folderTree: FolderTree;
active: string;
setActive: React.Dispatch<React.SetStateAction<string>>;
2024-06-19 22:09:31 +03:00
toggleFolderMode: () => void;
}
2024-06-27 11:34:52 +03:00
function ViewSideLocation({ folderTree, active, setActive: setActive, toggleFolderMode }: ViewSideLocationProps) {
2024-07-25 23:32:09 +03:00
const windowSize = useWindowSize();
2024-06-20 21:10:59 +03:00
const handleClickFolder = useCallback(
2024-06-19 22:09:31 +03:00
(event: CProps.EventMouse, target: FolderNode) => {
event.preventDefault();
event.stopPropagation();
2024-06-21 11:16:47 +03:00
if (event.ctrlKey || event.metaKey) {
2024-06-20 21:10:59 +03:00
navigator.clipboard
.writeText(target.getPath())
.then(() => toast.success(information.pathReady))
.catch(console.error);
} else {
2024-06-27 11:34:52 +03:00
setActive(target.getPath());
2024-06-20 21:10:59 +03:00
}
2024-06-19 22:09:31 +03:00
},
2024-06-27 11:34:52 +03:00
[setActive]
2024-06-19 22:09:31 +03:00
);
2024-07-25 23:32:09 +03:00
const animations = useMemo(() => animateSideMinWidth(windowSize.isSmall ? '10rem' : '15rem'), [windowSize]);
2024-06-19 22:09:31 +03:00
return (
<motion.div
2024-07-25 23:32:09 +03:00
className={clsx('max-w-[10rem] sm:max-w-[15rem]', 'flex flex-col', 'text:xs sm:text-sm', 'select-none')}
initial={{ ...animations.initial }}
animate={{ ...animations.animate }}
exit={{ ...animations.exit }}
2024-06-19 22:09:31 +03:00
>
2024-07-19 20:42:54 +03:00
<div className='h-[2.08rem] flex justify-between items-center pr-1 pl-[0.125rem]'>
2024-06-20 11:28:22 +03:00
<BadgeHelp
topic={HelpTopic.UI_LIBRARY}
className={clsx(PARAMETER.TOOLTIP_WIDTH, 'text-sm')}
offset={5}
place='right-start'
/>
2024-06-19 22:09:31 +03:00
<MiniButton
icon={<IconFolderTree size='1.25rem' className='icon-green' />}
2024-06-20 11:50:26 +03:00
title='Переключение в режим Поиск'
2024-06-19 22:09:31 +03:00
onClick={toggleFolderMode}
/>
</div>
2024-06-26 18:59:49 +03:00
<SelectLocation
2024-06-27 11:34:52 +03:00
value={active}
folderTree={folderTree}
2024-06-26 18:59:49 +03:00
prefix={prefixes.folders_list}
onClick={handleClickFolder}
/>
2024-06-19 22:09:31 +03:00
</motion.div>
);
}
2024-06-27 11:34:52 +03:00
export default ViewSideLocation;