import { Messenger } from '@estruyf/vscode/dist/client'; import { CodeIcon, PlusSmIcon } from '@heroicons/react/outline'; import * as React from 'react'; import { useCallback, useMemo, useState } from 'react'; import { useRecoilValue } from 'recoil'; import { DashboardMessage } from '../../DashboardMessage'; import { SettingsSelector, ViewDataSelector } from '../../state'; import { PageLayout } from '../Layout/PageLayout'; import { FormDialog } from '../Modals/FormDialog'; import { Item } from './Item'; import { NewForm } from './NewForm'; export interface ISnippetsProps {} export const Snippets: React.FunctionComponent = (props: React.PropsWithChildren) => { const settings = useRecoilValue(SettingsSelector); const viewData = useRecoilValue(ViewDataSelector); const [ snippetTitle, setSnippetTitle ] = useState(''); const [ snippetDescription, setSnippetDescription ] = useState(''); const [ snippetBody, setSnippetBody ] = useState(''); const [ showCreateDialog, setShowCreateDialog ] = useState(false); const snippetKeys = useMemo(() => Object.keys(settings?.snippets) || [], [settings?.snippets]); const snippets = settings?.snippets || {}; const onSnippetAdd = useCallback(() => { if (!snippetTitle || !snippetBody) { reset(); return; } Messenger.send(DashboardMessage.addSnippet, { title: snippetTitle, description: snippetDescription || '', body: snippetBody }); reset(); }, [snippetTitle, snippetDescription, snippetBody]); const reset = () => { setShowCreateDialog(false); setSnippetTitle(''); setSnippetDescription(''); setSnippetBody(''); }; return (
)}> { viewData?.data?.filePath && (

Select the snippet to add to your content.

) } { snippetKeys && snippetKeys.length > 0 ? (
    { snippetKeys.map((snippetKey: any, index: number) => ( )) }
) : (

No snippets found

) } { showCreateDialog && ( setSnippetTitle(value)} onDescriptionUpdate={(value: string) => setSnippetDescription(value)} onBodyUpdate={(value: string) => setSnippetBody(value)} /> ) }
); };