🔄 Left/Right arrow navigation between file preview
This commit is contained in:
@@ -163,7 +163,7 @@ export default memo(
|
|||||||
{viewId == 'shared-with-me' ? (
|
{viewId == 'shared-with-me' ? (
|
||||||
<>
|
<>
|
||||||
<Suspense fallback={<></>}>
|
<Suspense fallback={<></>}>
|
||||||
<DrivePreview />
|
<DrivePreview items={documents} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
<SharedFilesTable />
|
<SharedFilesTable />
|
||||||
</>
|
</>
|
||||||
@@ -196,7 +196,7 @@ export default memo(
|
|||||||
<ConfirmDeleteModal />
|
<ConfirmDeleteModal />
|
||||||
<ConfirmTrashModal />
|
<ConfirmTrashModal />
|
||||||
<Suspense fallback={<></>}>
|
<Suspense fallback={<></>}>
|
||||||
<DrivePreview />
|
<DrivePreview items={documents} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
|
|||||||
@@ -1,28 +1,54 @@
|
|||||||
import { Transition } from '@headlessui/react';
|
|
||||||
import { DownloadIcon, XIcon } from '@heroicons/react/outline';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { Transition } from '@headlessui/react';
|
||||||
import { fadeTransition } from 'src/utils/transitions';
|
import { fadeTransition } from 'src/utils/transitions';
|
||||||
import Controls from './controls';
|
import { DownloadIcon, XIcon } from '@heroicons/react/outline';
|
||||||
import DriveDisplay from './drive-display';
|
import { addShortcut, removeShortcut } from '@features/global/services/shortcut-service';
|
||||||
import { Button } from '@atoms/button/button';
|
import { getDevice } from '@features/global/utils/device';
|
||||||
import { Loader } from '@atoms/loader';
|
import RouterServices from '@features/router/services/router-service';
|
||||||
import { Modal } from '@atoms/modal';
|
import useRouterCompany from '@features/router/hooks/use-router-company';
|
||||||
import * as Text from '@atoms/text';
|
|
||||||
import {
|
import {
|
||||||
useDrivePreview,
|
useDrivePreview,
|
||||||
useDrivePreviewDisplayData,
|
useDrivePreviewDisplayData,
|
||||||
useDrivePreviewLoading,
|
useDrivePreviewLoading,
|
||||||
} from '@features/drive/hooks/use-drive-preview';
|
} from '@features/drive/hooks/use-drive-preview';
|
||||||
import { addShortcut, removeShortcut } from '@features/global/services/shortcut-service';
|
|
||||||
import { formatDate } from '@features/global/utils/format-date';
|
|
||||||
import { formatSize } from '@features/global/utils/format-file-size';
|
import { formatSize } from '@features/global/utils/format-file-size';
|
||||||
|
import { formatDate } from '@features/global/utils/format-date';
|
||||||
|
import { DriveItem } from 'app/features/drive/types';
|
||||||
|
import { Modal } from '@atoms/modal';
|
||||||
|
import { Button } from '@atoms/button/button';
|
||||||
|
import { Loader } from '@atoms/loader';
|
||||||
|
import * as Text from '@atoms/text';
|
||||||
|
import DriveDisplay from './drive-display';
|
||||||
|
import Controls from './controls';
|
||||||
|
|
||||||
export const DrivePreview = (): React.ReactElement => {
|
interface DrivePreviewProps {
|
||||||
const { isOpen, close, loading } = useDrivePreview();
|
items: DriveItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DrivePreview: React.FC<DrivePreviewProps> = ({ items }) => {
|
||||||
|
const history = useHistory();
|
||||||
|
const company = useRouterCompany();
|
||||||
|
const { status, isOpen, open, close, loading } = useDrivePreview();
|
||||||
const [modalLoading, setModalLoading] = useState(true);
|
const [modalLoading, setModalLoading] = useState(true);
|
||||||
const { loading: loadingData } = useDrivePreviewLoading();
|
const { loading: loadingData } = useDrivePreviewLoading();
|
||||||
const { type = '' } = useDrivePreviewDisplayData();
|
const { type = '' } = useDrivePreviewDisplayData();
|
||||||
let animationTimeout: number = setTimeout(() => undefined);
|
let animationTimeout: number = setTimeout(() => undefined);
|
||||||
|
const handleSwitchRight = () => {
|
||||||
|
const currentItem = status.item;
|
||||||
|
if (currentItem) {
|
||||||
|
const currentItemPos = items.findIndex(x => x.id === currentItem.id);
|
||||||
|
switchPreview(items[(currentItemPos + 1) % items.length]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSwitchLeft = () => {
|
||||||
|
const currentItem = status.item;
|
||||||
|
if (currentItem) {
|
||||||
|
const currentItemPos = items.findIndex(x => x.id === currentItem.id);
|
||||||
|
switchPreview(items[(currentItemPos - 1 + items.length) % items.length]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
addShortcut({ shortcut: 'esc', handler: close });
|
addShortcut({ shortcut: 'esc', handler: close });
|
||||||
@@ -32,6 +58,16 @@ export const DrivePreview = (): React.ReactElement => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
addShortcut({ shortcut: 'Right', handler: handleSwitchRight });
|
||||||
|
addShortcut({ shortcut: 'Left', handler: handleSwitchLeft });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
removeShortcut({ shortcut: 'Right', handler: handleSwitchRight });
|
||||||
|
removeShortcut({ shortcut: 'Left', handler: handleSwitchLeft });
|
||||||
|
};
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
clearTimeout(animationTimeout);
|
clearTimeout(animationTimeout);
|
||||||
|
|
||||||
@@ -42,6 +78,17 @@ export const DrivePreview = (): React.ReactElement => {
|
|||||||
}
|
}
|
||||||
}, [loading]);
|
}, [loading]);
|
||||||
|
|
||||||
|
const switchPreview = (item: DriveItem) => {
|
||||||
|
const device = getDevice();
|
||||||
|
if (device != 'ios' && device != 'android') {
|
||||||
|
close();
|
||||||
|
history.push(
|
||||||
|
RouterServices.generateRouteFromState({ companyId: company, viewId: '', itemId: item.id }),
|
||||||
|
);
|
||||||
|
open(item);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
|
|||||||
Reference in New Issue
Block a user