import * as React from 'react'; import { useCallback, useState } from 'react'; import { _ } from '@joplin/lib/locale'; import DialogButtonRow, { ClickEvent } from '../DialogButtonRow'; import Dialog from '../Dialog'; import DialogTitle from '../DialogTitle'; import StyledInput from '../style/StyledInput'; import { IconSelector, ChangeEvent } from './IconSelector'; import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect'; import Folder from '@joplin/lib/models/Folder'; import { FolderIcon } from '@joplin/lib/services/database/types'; import Button from '../Button/Button'; interface Props { themeId: number; dispatch: Function; folderId: string; } export default function(props: Props) { const [folderTitle, setFolderTitle] = useState(''); const [folderIcon, setFolderIcon] = useState(); useAsyncEffect(async (event: AsyncEffectEvent) => { const folder = await Folder.load(props.folderId); if (event.cancelled) return; setFolderTitle(folder.title); setFolderIcon(Folder.unserializeIcon(folder.icon)); }, [props.folderId]); const onClose = useCallback(() => { props.dispatch({ type: 'DIALOG_CLOSE', name: 'editFolder', }); }, [props.dispatch]); const onButtonRowClick = useCallback(async (event: ClickEvent) => { if (event.buttonName === 'cancel') { onClose(); return; } if (event.buttonName === 'ok') { await Folder.save({ id: props.folderId, title: folderTitle, icon: Folder.serializeIcon(folderIcon), }); onClose(); return; } }, [onClose, folderTitle, folderIcon, props.folderId]); const onFolderTitleChange = useCallback((event: any) => { setFolderTitle(event.target.value); }, []); const onFolderIconChange = useCallback((event: ChangeEvent) => { setFolderIcon(event.value); }, []); const onClearClick = useCallback(() => { setFolderIcon(null); }, []); function renderForm() { return (
); } function renderContent() { return (
{renderForm()}
); } function renderDialogWrapper() { return (
{renderContent()}
); } return ( ); }