General.js
253 lines
| 1 | /** @jsx jsx */ |
| 2 | const { __ } = wp.i18n; |
| 3 | const { dispatch } = wp.data; |
| 4 | const { RangeControl, Spinner } = wp.components; |
| 5 | const { useEffect, useState } = wp.element; |
| 6 | |
| 7 | import { getSetting, getSettings } from "@/admin/settings/util"; |
| 8 | import { css, jsx } from "@emotion/core"; |
| 9 | import ColorPicker from "../components/ColorPicker"; |
| 10 | import Disabled from "../components/Disabled"; |
| 11 | import Group from "../components/Group"; |
| 12 | import Media from "../components/Media"; |
| 13 | import Page from "../components/Page"; |
| 14 | import ComboboxControl from "../components/ComboboxControl"; |
| 15 | import ToggleControl from "../components/ToggleControl"; |
| 16 | import CodeMirror from "../components/CodeMirror"; |
| 17 | |
| 18 | export default () => { |
| 19 | const settings = getSettings(); |
| 20 | const disabled = () => { |
| 21 | if (prestoPlayer?.isPremium) { |
| 22 | return false; |
| 23 | } |
| 24 | return { |
| 25 | title: __("Pro Feature", "presto-player"), |
| 26 | heading: __("Unlock Presto Player Pro", "presto-player"), |
| 27 | message: __( |
| 28 | "Get this feature and more with the Pro version of Presto Player!", |
| 29 | "presto-player" |
| 30 | ), |
| 31 | link: "https://prestoplayer.com", |
| 32 | }; |
| 33 | }; |
| 34 | |
| 35 | const [presets, setPresets] = useState([]); |
| 36 | const [audioPresets, setAudioPresets] = useState([]); |
| 37 | |
| 38 | useEffect(() => { |
| 39 | async function getPresets() { |
| 40 | const res = await wp.apiFetch({ |
| 41 | path: `/presto-player/v1/preset/`, |
| 42 | }); |
| 43 | setPresets( |
| 44 | res.map(function (item) { |
| 45 | return { |
| 46 | label: item.name, |
| 47 | value: item.id, |
| 48 | }; |
| 49 | }) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | // get audio presets |
| 54 | async function getAudioPresets() { |
| 55 | const res = await wp.apiFetch({ |
| 56 | path: `/presto-player/v1/audio-preset/`, |
| 57 | }); |
| 58 | setAudioPresets( |
| 59 | res.map(function (item) { |
| 60 | return { |
| 61 | label: item.name, |
| 62 | value: item.id, |
| 63 | }; |
| 64 | }) |
| 65 | ); |
| 66 | } |
| 67 | getPresets(); |
| 68 | getAudioPresets(); |
| 69 | }, []); |
| 70 | |
| 71 | return ( |
| 72 | <Page |
| 73 | title={__("General", "presto-player")} |
| 74 | description={__( |
| 75 | "Branding, analytics and uninstall data.", |
| 76 | "presto-player" |
| 77 | )} |
| 78 | > |
| 79 | <Group |
| 80 | title={__("Branding", "presto-player")} |
| 81 | description={__("Global player branding options", "presto-player")} |
| 82 | > |
| 83 | <Disabled disabled={disabled()}> |
| 84 | <Media |
| 85 | className={"presto-player__setting--logo"} |
| 86 | option={{ |
| 87 | name: ( |
| 88 | <> |
| 89 | {__("Logo", "presto-player")}{" "} |
| 90 | {disabled() && ( |
| 91 | <span className="presto-options__pro-badge"> |
| 92 | {__("Pro", "presto-player")} |
| 93 | </span> |
| 94 | )} |
| 95 | </> |
| 96 | ), |
| 97 | id: "logo", |
| 98 | default: "", |
| 99 | }} |
| 100 | maxWidth={getSetting("branding", "logo_width") || 150} |
| 101 | value={getSetting("branding", "logo")} |
| 102 | optionName="branding" |
| 103 | /> |
| 104 | |
| 105 | <div style={{ maxWidth: "500px" }}> |
| 106 | <RangeControl |
| 107 | className={"presto-player__setting--logo-width"} |
| 108 | label={__("Logo Max Width", "presto-player")} |
| 109 | value={getSetting("branding", "logo_width") || 150} |
| 110 | onChange={(width) => { |
| 111 | dispatch("presto-player/settings").updateSetting( |
| 112 | "logo_width", |
| 113 | width, |
| 114 | "branding" |
| 115 | ); |
| 116 | }} |
| 117 | min={1} |
| 118 | max={400} |
| 119 | /> |
| 120 | </div> |
| 121 | </Disabled> |
| 122 | <ColorPicker |
| 123 | className={"presto-player__setting--brand-color"} |
| 124 | option={{ |
| 125 | name: __("Brand Color", "presto-player"), |
| 126 | id: "color", |
| 127 | default: "", |
| 128 | }} |
| 129 | value={getSetting("branding", "color")} |
| 130 | optionName="branding" |
| 131 | /> |
| 132 | </Group> |
| 133 | |
| 134 | <Group |
| 135 | title={__("Analytics", "presto-player")} |
| 136 | disabled={disabled()} |
| 137 | description={__( |
| 138 | "Analytics settings for media plays, watch times and more.", |
| 139 | "presto-player" |
| 140 | )} |
| 141 | > |
| 142 | <div> |
| 143 | <ToggleControl |
| 144 | className={"presto-player__setting--analytics-enable"} |
| 145 | option={{ |
| 146 | id: "enable", |
| 147 | name: __("Enable", "presto-player"), |
| 148 | help: __("Enable view analytics for your media", "presto-player"), |
| 149 | }} |
| 150 | value={settings?.presto_player_analytics?.enable} |
| 151 | optionName="analytics" |
| 152 | /> |
| 153 | {!!settings?.presto_player_analytics?.enable && ( |
| 154 | <ToggleControl |
| 155 | className={"presto-player__setting--purge-data"} |
| 156 | option={{ |
| 157 | id: "purge_data", |
| 158 | name: __("Auto-Purge Data (recommended)", "presto-player"), |
| 159 | help: __( |
| 160 | "Automatically purge data older than 90 days.", |
| 161 | "presto-player" |
| 162 | ), |
| 163 | }} |
| 164 | value={ |
| 165 | settings?.presto_player_analytics?.purge_data !== undefined |
| 166 | ? settings?.presto_player_analytics?.purge_data |
| 167 | : true |
| 168 | } |
| 169 | optionName="analytics" |
| 170 | /> |
| 171 | )} |
| 172 | </div> |
| 173 | </Group> |
| 174 | |
| 175 | <Group |
| 176 | title={__("Presets", "presto-player")} |
| 177 | disabled={disabled()} |
| 178 | description={__("Media presets settings.", "presto-player")} |
| 179 | > |
| 180 | {!presets.length ? ( |
| 181 | <Spinner /> |
| 182 | ) : ( |
| 183 | <ComboboxControl |
| 184 | option={{ |
| 185 | name: __("Select default preset for video.", "presto-player"), |
| 186 | id: "default_player_preset", |
| 187 | }} |
| 188 | options={presets} |
| 189 | value={settings?.presto_player_presets?.default_player_preset} |
| 190 | optionName="presets" |
| 191 | /> |
| 192 | )} |
| 193 | {!audioPresets.length ? ( |
| 194 | <Spinner /> |
| 195 | ) : ( |
| 196 | <ComboboxControl |
| 197 | option={{ |
| 198 | name: __("Select default preset for audio.", "presto-player"), |
| 199 | id: "default_player_preset", |
| 200 | }} |
| 201 | options={audioPresets} |
| 202 | value={settings?.presto_player_audio_presets?.default_player_preset} |
| 203 | optionName="audio_presets" |
| 204 | /> |
| 205 | )} |
| 206 | </Group> |
| 207 | |
| 208 | <Group |
| 209 | disabled={disabled()} |
| 210 | title={__("Custom CSS", "presto-player")} |
| 211 | description={__( |
| 212 | "Quickly add custom css to the player web component.", |
| 213 | "presto-player" |
| 214 | )} |
| 215 | > |
| 216 | <CodeMirror |
| 217 | disabled={!prestoPlayer?.isPremium} |
| 218 | option={{ id: "player_css" }} |
| 219 | value={settings?.presto_player_branding?.player_css} |
| 220 | optionName="branding" |
| 221 | /> |
| 222 | </Group> |
| 223 | |
| 224 | <Group |
| 225 | title={__("Uninstall Options", "presto-player")} |
| 226 | description={__( |
| 227 | "Options to remove data on uninstall.", |
| 228 | "presto-player" |
| 229 | )} |
| 230 | > |
| 231 | <ToggleControl |
| 232 | className="presto-player__setting--uninstall" |
| 233 | option={{ |
| 234 | id: "uninstall_data", |
| 235 | name: __("Remove data on uninstall", "presto-player"), |
| 236 | help: __("This removes all data on uninstall.", "presto-player"), |
| 237 | confirm: { |
| 238 | title: __("Caution: Data Loss", "presto-player"), |
| 239 | heading: __("Are you sure?", "presto-player"), |
| 240 | message: __( |
| 241 | "Are you sure you want to remove all the data from this plugin? This is irreversible!", |
| 242 | "presto-player" |
| 243 | ), |
| 244 | }, |
| 245 | }} |
| 246 | value={settings?.presto_player_uninstall?.uninstall_data} |
| 247 | optionName="uninstall" |
| 248 | /> |
| 249 | </Group> |
| 250 | </Page> |
| 251 | ); |
| 252 | }; |
| 253 |