diff --git a/CHANGELOG.md b/CHANGELOG.md index d01d1bba..58a7922a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change Log +## [10.2.0] - 2024-xx-xx + +### ✨ New features + +- [#797](https://github.com/estruyf/vscode-front-matter/issues/797): Adding common actions at the bottom of the snippet cards + +### 🎨 Enhancements + +### ⚡️ Optimizations + +### 🐞 Fixes + ## [10.1.0] - 2024-04-11 - [Release notes](https://beta.frontmatter.codes/updates/v10.1.0) ### ✨ New features diff --git a/src/dashboardWebView/components/SnippetsView/FooterActions.tsx b/src/dashboardWebView/components/SnippetsView/FooterActions.tsx new file mode 100644 index 00000000..68d44e3b --- /dev/null +++ b/src/dashboardWebView/components/SnippetsView/FooterActions.tsx @@ -0,0 +1,84 @@ +import * as React from 'react'; +import * as l10n from '@vscode/l10n'; +import { LocalizationKey } from '../../../localization'; +import { QuickAction } from '../Menu'; +import { EyeIcon, PencilIcon, PlusIcon, TrashIcon } from '@heroicons/react/24/solid'; +import { useCallback } from 'react'; +import { openFile } from '../../utils/MessageHandlers'; + +export interface IFooterActionsProps { + insertEnabled: boolean; + sourcePath?: string; + onEdit?: () => void; + onInsert: () => void; + onDelete?: () => void; +} + +export const FooterActions: React.FunctionComponent = ({ + insertEnabled, + sourcePath, + onEdit, + onInsert, + onDelete, +}: React.PropsWithChildren) => { + + const showFile = useCallback(() => { + openFile(sourcePath); + }, [sourcePath]); + + if (!onEdit && !onDelete && !sourcePath && !insertEnabled) { + return null; + } + + return ( +
+ {insertEnabled && ( + + + )} + + { + !sourcePath ? ( + <> + { + onEdit && ( + + + ) + } + + { + onDelete && ( + + + ) + } + + ) : ( + + + ) + } +
+ ); +}; \ No newline at end of file diff --git a/src/dashboardWebView/components/SnippetsView/Item.tsx b/src/dashboardWebView/components/SnippetsView/Item.tsx index 1ef5ae50..762dbbed 100644 --- a/src/dashboardWebView/components/SnippetsView/Item.tsx +++ b/src/dashboardWebView/components/SnippetsView/Item.tsx @@ -2,13 +2,8 @@ import { Messenger } from '@estruyf/vscode/dist/client'; import { CodeBracketIcon, DocumentTextIcon, - EllipsisHorizontalIcon, - EyeIcon, - PencilIcon, PhotoIcon, - PlusIcon, - TrashIcon -} from '@heroicons/react/24/outline'; +} from '@heroicons/react/24/solid'; import * as React from 'react'; import { useCallback, useMemo, useRef, useState } from 'react'; import { useRecoilValue } from 'recoil'; @@ -18,14 +13,13 @@ import { SnippetParser } from '../../../helpers/SnippetParser'; import { Snippet, Snippets } from '../../../models'; import { DashboardMessage } from '../../DashboardMessage'; import { ModeAtom, SettingsSelector, ViewDataSelector } from '../../state'; -import { QuickAction } from '../Menu'; import { Alert } from '../Modals/Alert'; import { FormDialog } from '../Modals/FormDialog'; import { NewForm } from './NewForm'; import SnippetForm, { SnippetFormHandle } from './SnippetForm'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; -import { openFile } from '../../utils'; +import { FooterActions } from './FooterActions'; export interface IItemProps { snippetKey: string; @@ -65,10 +59,6 @@ export const Item: React.FunctionComponent = ({ setMediaSnippet(false); }; - const showFile = useCallback(() => { - openFile(snippet.sourcePath); - }, [snippet]); - const onOpenEdit = useCallback(() => { setSnippetTitle(snippet.title || snippetKey); setSnippetDescription(snippet.description); @@ -162,89 +152,41 @@ export const Item: React.FunctionComponent = ({ return ( <> -
  • -
    - +
  • +
    +

    + {snippet.isMediaSnippet ? ( + + ) : ( + + )} + + {snippet.title || snippetKey} +

    + +

    {snippet.description}

    -

    - {snippet.isMediaSnippet ? ( - - ) : ( - - )} - - {snippet.title || snippetKey} -

    - -
    -
    - -
    - -
    - setShowInsertDialog(true)}> - -
    -
    - - ) : undefined + setShowInsertDialog(true)} /> } > -
    -
    -
    - -
    - -
    - {insertToContent && !snippet.isMediaSnippet && ( - <> - setShowInsertDialog(true)}> - - - )} - - {!snippet.sourcePath ? ( - <> - - - - setShowAlert(true)}> - - - ) : ( - - - )} -
    -
    -
    + setShowInsertDialog(true)} + onDelete={() => setShowAlert(true)} />
    - -

    {snippet.description}

  • {showInsertDialog && (