1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +07:00

#58 using formik at node submit form

This commit is contained in:
Fedor Katurov 2021-03-26 17:52:24 +07:00
parent 4b542e0291
commit b871cc2042
17 changed files with 230 additions and 423 deletions

View file

@ -6,16 +6,18 @@ import { InputText } from '~/components/input/InputText';
import classnames from 'classnames';
import { getYoutubeThumb } from '~/utils/dom';
import { NodeEditorProps } from '~/redux/node/types';
import { useNodeFormContext } from '~/utils/hooks/useNodeFormFormik';
type IProps = NodeEditorProps & {};
const VideoEditor: FC<IProps> = ({ data, setData }) => {
const setUrl = useCallback(
(url: string) => setData({ ...data, blocks: [{ type: 'video', url }] }),
[data, setData]
);
const VideoEditor: FC<IProps> = () => {
const { values, setFieldValue } = useNodeFormContext();
const url = (path(['blocks', 0, 'url'], data) as string) || '';
const setUrl = useCallback((url: string) => setFieldValue('blocks', [{ type: 'video', url }]), [
setFieldValue,
]);
const url = (path(['blocks', 0, 'url'], values) as string) || '';
const preview = useMemo(() => getYoutubeThumb(url), [url]);
const backgroundImage = (preview && `url("${preview}")`) || '';