From 95e392977aa9a5aeb50cd8464264bb55d7c41168 Mon Sep 17 00:00:00 2001 From: SebiVPS <42858722+SebiVPS@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:54:02 +0200 Subject: [PATCH] Harmonize video blocks options (#2233) Outsource video options fields to use in DamVideoBlock, YouTubeVideoBlock (when moved to cms-admin from blocks-admin) and VimeoVideoBlock (PR open). --- .../cms-admin/src/blocks/DamVideoBlock.tsx | 38 ++------------ .../src/blocks/helpers/VideoOptionsFields.tsx | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 packages/admin/cms-admin/src/blocks/helpers/VideoOptionsFields.tsx diff --git a/packages/admin/cms-admin/src/blocks/DamVideoBlock.tsx b/packages/admin/cms-admin/src/blocks/DamVideoBlock.tsx index 1a5ba7eff4..ffee0f74f8 100644 --- a/packages/admin/cms-admin/src/blocks/DamVideoBlock.tsx +++ b/packages/admin/cms-admin/src/blocks/DamVideoBlock.tsx @@ -1,5 +1,5 @@ import { gql, useApolloClient } from "@apollo/client"; -import { Field, FieldContainer, FinalFormSwitch } from "@comet/admin"; +import { Field, FieldContainer } from "@comet/admin"; import { Delete, MoreVertical, OpenNewTab, Video } from "@comet/admin-icons"; import { AdminComponentButton, @@ -23,6 +23,7 @@ import { DamPathLazy } from "../form/file/DamPathLazy"; import { FileField } from "../form/file/FileField"; import { CmsBlockContext } from "./CmsBlockContextProvider"; import { GQLVideoBlockDamFileQuery, GQLVideoBlockDamFileQueryVariables } from "./DamVideoBlock.generated"; +import { VideoOptionsFields } from "./helpers/VideoOptionsFields"; type State = DamVideoBlockData; @@ -128,21 +129,7 @@ export const DamVideoBlock: BlockInterface - { - updateState((prevState) => { - // case: autoplay = false and showControls = false is not allowed - if (!values.autoplay && prevState.autoplay) { - return { ...prevState, ...values, showControls: true }; - } - if (!values.showControls && prevState.showControls) { - return { ...prevState, ...values, autoplay: true }; - } - return { ...prevState, ...values }; - }); - }} - initialValues={state} - > + {state.damFile ? ( @@ -203,24 +190,7 @@ export const DamVideoBlock: BlockInterface )} - } - component={FinalFormSwitch} - /> - } - component={FinalFormSwitch} - /> - } - component={FinalFormSwitch} - /> + ); diff --git a/packages/admin/cms-admin/src/blocks/helpers/VideoOptionsFields.tsx b/packages/admin/cms-admin/src/blocks/helpers/VideoOptionsFields.tsx new file mode 100644 index 0000000000..0806a47666 --- /dev/null +++ b/packages/admin/cms-admin/src/blocks/helpers/VideoOptionsFields.tsx @@ -0,0 +1,52 @@ +import { Field, FinalFormSwitch, OnChangeField } from "@comet/admin"; +import { FormControlLabel } from "@mui/material"; +import * as React from "react"; +import { useForm } from "react-final-form"; +import { FormattedMessage } from "react-intl"; + +export const VideoOptionsFields = () => { + const form = useForm(); + return ( + <> + + {(props) => ( + } + control={} + /> + )} + + + {(props) => ( + } + control={} + /> + )} + + + {(props) => ( + } + control={} + /> + )} + + {/* case: autoplay = false and showControls = false is not allowed */} + + {(value, previousValue) => { + if (!value && previousValue) { + form.change("showControls", true); + } + }} + + + {(value, previousValue) => { + if (!value && previousValue) { + form.change("autoplay", true); + } + }} + + + ); +};