Files
readest/apps/readest-app/src/app/reader/components/NotebookToggler.tsx
T
2024-12-26 23:29:54 +01:00

42 lines
1.2 KiB
TypeScript

import React from 'react';
import { TbLayoutSidebarRight, TbLayoutSidebarRightFilled } from 'react-icons/tb';
import { useSidebarStore } from '@/store/sidebarStore';
import { useNotebookStore } from '@/store/notebookStore';
import { useTranslation } from '@/hooks/useTranslation';
import Button from '@/components/Button';
interface NotebookTogglerProps {
bookKey: string;
}
const NotebookToggler: React.FC<NotebookTogglerProps> = ({ bookKey }) => {
const _ = useTranslation();
const { sideBarBookKey, setSideBarBookKey } = useSidebarStore();
const { isNotebookVisible, toggleNotebook } = useNotebookStore();
const handleToggleSidebar = () => {
if (sideBarBookKey === bookKey) {
toggleNotebook();
} else {
setSideBarBookKey(bookKey);
if (!isNotebookVisible) toggleNotebook();
}
};
return (
<Button
icon={
sideBarBookKey == bookKey && isNotebookVisible ? (
<TbLayoutSidebarRightFilled size={20} className='text-base-content' />
) : (
<TbLayoutSidebarRight size={20} className='text-base-content' />
)
}
onClick={handleToggleSidebar}
tooltip={_('Notebook')}
tooltipDirection='bottom'
></Button>
);
};
export default NotebookToggler;