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