index.js
75 lines
| 1 | /** @jsx jsx */ |
| 2 | |
| 3 | const { __ } = wp.i18n; |
| 4 | const { useState } = wp.element; |
| 5 | const { useSelect, dispatch } = wp.data; |
| 6 | const { withNotices, BaseControl, Spinner, Button } = wp.components; |
| 7 | |
| 8 | import ProBadge from "@/admin/blocks/shared/components/ProBadge"; |
| 9 | import EditOverlay from "./Edit"; |
| 10 | |
| 11 | import { css, jsx } from "@emotion/core"; |
| 12 | |
| 13 | const VideoOverlays = ({ setAttributes, attributes }) => { |
| 14 | // modal |
| 15 | const { overlays } = attributes; |
| 16 | const [modal, setModal] = useState(false); |
| 17 | const openModal = () => setModal(true); |
| 18 | const closeModal = () => setModal(false); |
| 19 | |
| 20 | const updateOverlayAttribute = (overlays) => { |
| 21 | setAttributes({ overlays: overlays }); |
| 22 | }; |
| 23 | |
| 24 | return ( |
| 25 | <> |
| 26 | <BaseControl> |
| 27 | <Button |
| 28 | isPrimary |
| 29 | onClick={() => { |
| 30 | if (!prestoPlayer?.isPremium) { |
| 31 | dispatch("presto-player/player").setProModal(true); |
| 32 | return; |
| 33 | } |
| 34 | openModal("new"); |
| 35 | }} |
| 36 | > |
| 37 | {!!overlays.length |
| 38 | ? __("Update Overlays", "presto-player") |
| 39 | : __("Add Overlay", "presto-player")} |
| 40 | {!!overlays.length && ( |
| 41 | <div |
| 42 | css={css` |
| 43 | font-size: 10px; |
| 44 | background: #fff; |
| 45 | color: var(--wp-admin-theme-color); |
| 46 | font-weight: bold; |
| 47 | display: inline-block; |
| 48 | line-height: 6px; |
| 49 | padding: 5px; |
| 50 | border-radius: 9999px; |
| 51 | margin-left: 10px; |
| 52 | `} |
| 53 | > |
| 54 | {overlays.length} |
| 55 | </div> |
| 56 | )} |
| 57 | </Button> |
| 58 | |
| 59 | {!prestoPlayer?.isPremium && <ProBadge />} |
| 60 | </BaseControl> |
| 61 | |
| 62 | {modal && ( |
| 63 | <EditOverlay |
| 64 | closeModal={closeModal} |
| 65 | attributes={attributes} |
| 66 | setAttributes={setAttributes} |
| 67 | updateOverlayAttribute={updateOverlayAttribute} |
| 68 | /> |
| 69 | )} |
| 70 | </> |
| 71 | ); |
| 72 | }; |
| 73 | |
| 74 | export default VideoOverlays; |
| 75 |