diff --git a/src/dashboardWebView/components/Media/Item.tsx b/src/dashboardWebView/components/Media/Item.tsx index e674ae10..5ee91ba2 100644 --- a/src/dashboardWebView/components/Media/Item.tsx +++ b/src/dashboardWebView/components/Media/Item.tsx @@ -3,7 +3,7 @@ import { Menu } from '@headlessui/react'; import { ClipboardIcon, CodeIcon, DocumentIcon, EyeIcon, MusicNoteIcon, PencilIcon, PhotographIcon, PlusIcon, TerminalIcon, TrashIcon, VideoCameraIcon } from '@heroicons/react/outline'; import { basename, dirname } from 'path'; import * as React from 'react'; -import { useCallback, useEffect, useMemo } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { useRecoilState, useRecoilValue } from 'recoil'; import { CustomScript } from '../../../helpers/CustomScript'; import { parseWinPath } from '../../../helpers/parseWinPath'; @@ -18,6 +18,7 @@ import { QuickAction } from '../Menu/QuickAction'; import { Alert } from '../Modals/Alert'; import { InfoDialog } from '../Modals/InfoDialog'; import { DetailsSlideOver } from './DetailsSlideOver'; +import { usePopper } from 'react-popper'; export interface IItemProps { media: MediaInfo; @@ -25,17 +26,24 @@ export interface IItemProps { export const Item: React.FunctionComponent = ({media}: React.PropsWithChildren) => { const [ , setLightbox ] = useRecoilState(LightboxAtom); - const [ showAlert, setShowAlert ] = React.useState(false); - const [ showForm, setShowForm ] = React.useState(false); - const [ showSnippetSelection, setShowSnippetSelection ] = React.useState(false); - const [ showDetails, setShowDetails ] = React.useState(false); - const [ caption, setCaption ] = React.useState(media.caption); - const [ alt, setAlt ] = React.useState(media.alt); - const [ filename, setFilename ] = React.useState(null); + const [ showAlert, setShowAlert ] = useState(false); + const [ showForm, setShowForm ] = useState(false); + const [ showSnippetSelection, setShowSnippetSelection ] = useState(false); + const [ showDetails, setShowDetails ] = useState(false); + const [ caption, setCaption ] = useState(media.caption); + const [ alt, setAlt ] = useState(media.alt); + const [ filename, setFilename ] = useState(null); const settings = useRecoilValue(SettingsSelector); const selectedFolder = useRecoilValue(SelectedMediaFolderSelector); const viewData = useRecoilValue(ViewDataSelector); + const [referenceElement, setReferenceElement] = useState(null); + const [popperElement, setPopperElement] = useState(null); + const { styles, attributes, forceUpdate } = usePopper(referenceElement, popperElement, { + placement: 'bottom-end', + strategy: 'fixed' + }) + const mediaSnippets = useMemo(() => { if (!settings?.snippets) { return []; @@ -380,59 +388,63 @@ export const Item: React.FunctionComponent = ({media}: React.PropsWi - +
+ +
- - - Edit metadata - - )} - onClick={updateMetadata} - /> +
+ + + Edit metadata +
+ )} + onClick={updateMetadata} + /> - { - viewData?.data?.filePath ? ( - <> - Insert image markdown} - onClick={insertToArticle} /> + { + viewData?.data?.filePath ? ( + <> + Insert image markdown} + onClick={insertToArticle} /> - { - (viewData?.data?.position && mediaSnippets.length > 0) && mediaSnippets.map((snippet, idx) => ( - {snippet.title}} - onClick={() => processSnippet(snippet)} /> - )) - } + { + (viewData?.data?.position && mediaSnippets.length > 0) && mediaSnippets.map((snippet, idx) => ( + {snippet.title}} + onClick={() => processSnippet(snippet)} /> + )) + } - { customScriptActions() } - - ) : ( - <> - - Copy media path - - )} - onClick={copyToClipboard} /> + { customScriptActions() } + + ) : ( + <> + + Copy media path + + )} + onClick={copyToClipboard} /> - { customScriptActions() } - - ) - } + { customScriptActions() } + + ) + } - Reveal media} - onClick={revealMedia} /> + Reveal media} + onClick={revealMedia} /> - Delete} - onClick={deleteMedia} /> -
+ Delete} + onClick={deleteMedia} /> + + @@ -530,4 +542,4 @@ export const Item: React.FunctionComponent = ({media}: React.PropsWi } ); -}; \ No newline at end of file +};