From 1ca2ea12212607b9229afa7ef877517d31bdcd49 Mon Sep 17 00:00:00 2001 From: nikec <43032218+niikeec@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:40:40 +0200 Subject: [PATCH] [ENG-1182] Switch quick preview animation from react-spring to tailwindcss-animate (#1431) * animate * radix-state-open --- .../Explorer/QuickPreview/index.tsx | 480 ++++++++---------- 1 file changed, 225 insertions(+), 255 deletions(-) diff --git a/interface/app/$libraryId/Explorer/QuickPreview/index.tsx b/interface/app/$libraryId/Explorer/QuickPreview/index.tsx index f74297a86..bfc8fcc24 100644 --- a/interface/app/$libraryId/Explorer/QuickPreview/index.tsx +++ b/interface/app/$libraryId/Explorer/QuickPreview/index.tsx @@ -1,6 +1,5 @@ import { ArrowLeft, ArrowRight, DotsThree, Plus, SidebarSimple, X } from '@phosphor-icons/react'; import * as Dialog from '@radix-ui/react-dialog'; -import { animated, useTransition } from '@react-spring/web'; import clsx from 'clsx'; import { ButtonHTMLAttributes, @@ -38,9 +37,6 @@ import { FileThumb } from '../FilePath/Thumb'; import { SingleItemMetadata } from '../Inspector'; import { getQuickPreviewStore, useQuickPreviewStore } from './store'; -const AnimatedDialogOverlay = animated(Dialog.Overlay); -const AnimatedDialogContent = animated(Dialog.Content); - const iconKinds: ObjectKindKey[] = ['Audio', 'Folder', 'Executable', 'Unknown']; const textKinds: ObjectKindKey[] = ['Text', 'Config', 'Code']; const withoutBackgroundKinds: ObjectKindKey[] = [...iconKinds, ...textKinds, 'Document']; @@ -77,17 +73,6 @@ export const QuickPreview = () => { const item = useMemo(() => items[itemIndex], [items, itemIndex]); - const transitions = useTransition(open, { - from: { - opacity: 0, - transform: `translateY(20px) scale(0.9)`, - transformOrigin: 'center top' - }, - enter: { opacity: 1, transform: `translateY(0px) scale(1)` }, - leave: { opacity: 0, immediate: true }, - config: { mass: 0.2, tension: 300, friction: 20, bounce: 0 } - }); - const renameFile = useLibraryMutation(['files.renameFile'], { onError: () => setNewName(null), onSuccess: () => rspc.queryClient.invalidateQueries(['search.paths']) @@ -181,268 +166,253 @@ export const QuickPreview = () => { )); }); + if (!item) return null; + + const { kind, ...itemData } = getExplorerItemData(item); + + const name = newName || `${itemData.name}${itemData.extension ? `.${itemData.extension}` : ''}`; + + const background = !withoutBackgroundKinds.includes(kind); + const icon = iconKinds.includes(kind); + return ( (getQuickPreviewStore().open = open)}> - {transitions((styles, show) => { - if (!show || !item) return null; + + + e.preventDefault()} + /> - const { kind, ...itemData } = getExplorerItemData(item); - - const name = - newName || - `${itemData.name}${itemData.extension ? `.${itemData.extension}` : ''}`; - - const background = !withoutBackgroundKinds.includes(kind); - const icon = iconKinds.includes(kind); - - return ( - - - e.preventDefault()} + onEscapeKeyDown={(e) => isRenaming && e.preventDefault()} + onContextMenu={(e) => e.preventDefault()} + > +
+
+ {background && ( +
+ +
)} - style={{ opacity: styles.opacity }} - onContextMenu={(e) => e.preventDefault()} - /> - e.preventDefault()} - onEscapeKeyDown={(e) => isRenaming && e.preventDefault()} - onContextMenu={(e) => e.preventDefault()} - >
-
- {background && ( -
- -
- )} +
+ + + + + + + -
-
- - - - - - + {items.length > 1 && ( +
+ + + changeCurrentItem(itemIndex - 1) + } + className="rounded-r-none" + > + + - {items.length > 1 && ( -
- - - changeCurrentItem(itemIndex - 1) - } - className="rounded-r-none" - > - - - - - - - changeCurrentItem(itemIndex + 1) - } - className="rounded-l-none" - > - - - -
- )} -
- -
- {isRenaming && name ? ( - { - setIsRenaming(false); - - if ( - !('id' in item.item) || - !newName || - newName === name - ) - return; - - const filePathData = - getIndexedItemFilePath(item); - - if (!filePathData) return; - - const locationId = - filePathData.location_id; - - if (locationId === null) return; - - renameFile.mutate({ - location_id: locationId, - kind: { - One: { - from_file_path_id: - item.item.id, - to: newName - } - } - }); - - setNewName(newName); - }} - /> - ) : ( - - - name && - item.type !== 'NonIndexedPath' && - setIsRenaming(true) - } - className={clsx( - item.type === 'NonIndexedPath' - ? 'cursor-default' - : 'cursor-text' - )} - > - {name} - - - )} -
- -
- {item.type !== 'NonIndexedPath' && ( - - - - - - -
- } - onOpenChange={setIsContextMenuOpen} - align="end" - sideOffset={-10} - > - - - - - name && setIsRenaming(true) - } - /> - - - - - {(items) => ( - - {items} - - )} - - - - - - )} - - + - setShowMetadata(!showMetadata) + changeCurrentItem(itemIndex + 1) } - active={showMetadata} + className="rounded-l-none" > - +
-
- - + )}
- {showMetadata && ( -
- -
- )} +
+ {isRenaming && name ? ( + { + setIsRenaming(false); + + if ( + !('id' in item.item) || + !newName || + newName === name + ) + return; + + const filePathData = + getIndexedItemFilePath(item); + + if (!filePathData) return; + + const locationId = filePathData.location_id; + + if (locationId === null) return; + + renameFile.mutate({ + location_id: locationId, + kind: { + One: { + from_file_path_id: item.item.id, + to: newName + } + } + }); + + setNewName(newName); + }} + /> + ) : ( + + + name && + item.type !== 'NonIndexedPath' && + setIsRenaming(true) + } + className={clsx( + item.type === 'NonIndexedPath' + ? 'cursor-default' + : 'cursor-text' + )} + > + {name} + + + )} +
+ +
+ {item.type !== 'NonIndexedPath' && ( + + + + + + +
+ } + onOpenChange={setIsContextMenuOpen} + align="end" + sideOffset={-10} + > + + + + name && setIsRenaming(true)} + /> + + + + + {(items) => ( + + {items} + + )} + + + + + + )} + + + setShowMetadata(!showMetadata)} + active={showMetadata} + > + + + +
-
- - - ); - })} + + +
+ + {showMetadata && ( +
+ +
+ )} +
+ +
+
); };