refactor: fix some lintter erros

This commit is contained in:
Sonny
2024-05-25 17:19:26 +02:00
committed by Sonny
parent 09700a1916
commit 8b161dcf49
7 changed files with 31 additions and 21 deletions

View File

@@ -18,6 +18,7 @@ interface ModalProps {
children: ReactNode;
opened: boolean;
hideCloseBtn?: boolean;
className?: string;
close: () => void;
}
@@ -27,13 +28,14 @@ export default function Modal({
children,
opened = true,
hideCloseBtn = false,
className,
close,
}: ModalProps) {
const modalRef = useRef<HTMLDivElement>(null);
const { setGlobalHotkeysEnabled } = useGlobalHotkeys();
useClickOutside(modalRef, close);
useShortcut('ESCAPE_KEY', close);
useShortcut('ESCAPE_KEY', close, { disableGlobalCheck: true });
useEffect(() => setGlobalHotkeysEnabled(!opened), [opened]);
@@ -45,18 +47,17 @@ export default function Modal({
opened &&
createPortal(
<ModalWrapper>
<ModalContainer ref={modalRef}>
{!hideCloseBtn ||
(title && (
<ModalHeader>
{title && <TextEllipsis>{title}</TextEllipsis>}
{!hideCloseBtn && (
<ModalCloseBtn onClick={close}>
<IoClose size={20} />
</ModalCloseBtn>
)}
</ModalHeader>
))}
<ModalContainer className={className} ref={modalRef}>
{(!hideCloseBtn || title) && (
<ModalHeader>
{title && <TextEllipsis>{title}</TextEllipsis>}
{!hideCloseBtn && (
<ModalCloseBtn onClick={close}>
<IoClose size={20} />
</ModalCloseBtn>
)}
</ModalHeader>
)}
<ModalBody>{children}</ModalBody>
</ModalContainer>
</ModalWrapper>,

View File

@@ -6,9 +6,12 @@ import useShortcut from '~/hooks/use_shortcut';
import { appendCollectionId } from '~/lib/navigation';
export default function BackToDashboard({ children }: { children: ReactNode }) {
const collectionId = useSearchParam('collectionId');
useShortcut('ESCAPE_KEY', () =>
router.visit(appendCollectionId(route('dashboard').url, collectionId))
const collectionId = Number(useSearchParam('collectionId'));
useShortcut(
'ESCAPE_KEY',
() =>
router.visit(appendCollectionId(route('dashboard').url, collectionId)),
{ disableGlobalCheck: true }
);
return <>{children}</>;
}