general
1 month ago
integrations
1 month ago
shared
1 month ago
PerformancePage.js
1 month ago
config.js
1 month ago
entities.js
1 month ago
PerformancePage.js
111 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { useEffect, useState } from 'react'; |
| 3 | import { Container, Switch, Alert, Tooltip } from '@bsf/force-ui'; |
| 4 | import { Info } from 'lucide-react'; |
| 5 | import SettingsPageShell from './shared/SettingsPageShell'; |
| 6 | import SectionCard from './shared/SectionCard'; |
| 7 | import useSimpleSettingsPage from '../../hooks/useSimpleSettingsPage'; |
| 8 | import { OPTION_KEYS } from './config'; |
| 9 | |
| 10 | const DEFAULTS = { |
| 11 | module_enabled: false, |
| 12 | automations: true, |
| 13 | }; |
| 14 | |
| 15 | const PerformancePage = ( { registerActivePage } ) => { |
| 16 | const { data, update, handleSave, isDirty, isSaving, isLoading } = |
| 17 | useSimpleSettingsPage( |
| 18 | OPTION_KEYS.performance, |
| 19 | DEFAULTS, |
| 20 | registerActivePage |
| 21 | ); |
| 22 | |
| 23 | const [ noteDismissed, setNoteDismissed ] = useState( false ); |
| 24 | |
| 25 | // Reset dismissal when the feature is turned off so the note reappears |
| 26 | // next time the user enables it — they may have forgotten the caveats. |
| 27 | useEffect( () => { |
| 28 | if ( ! data.module_enabled ) { |
| 29 | setNoteDismissed( false ); |
| 30 | } |
| 31 | }, [ data.module_enabled ] ); |
| 32 | |
| 33 | return ( |
| 34 | <SettingsPageShell |
| 35 | title={ __( 'Performance', 'presto-player' ) } |
| 36 | isDirty={ isDirty } |
| 37 | isSaving={ isSaving } |
| 38 | isLoading={ isLoading } |
| 39 | onSave={ handleSave } |
| 40 | > |
| 41 | <SectionCard> |
| 42 | <Container direction="column" className="gap-4"> |
| 43 | <Switch |
| 44 | size="md" |
| 45 | value={ !! data.module_enabled } |
| 46 | onChange={ ( val ) => update( { module_enabled: val } ) } |
| 47 | label={ { |
| 48 | heading: __( 'Dynamically Load JavaScript', 'presto-player' ), |
| 49 | description: __( |
| 50 | 'Dynamically load javascript modules on the page which can significantly reduce javascript size and increase performance.', |
| 51 | 'presto-player' |
| 52 | ), |
| 53 | } } |
| 54 | /> |
| 55 | |
| 56 | { !! data.module_enabled && ! noteDismissed && ( |
| 57 | <Alert |
| 58 | design="stack" |
| 59 | variant="info" |
| 60 | title={ __( 'Please Note', 'presto-player' ) } |
| 61 | content={ |
| 62 | <> |
| 63 | { __( |
| 64 | 'You may need to exclude the player script from combining, as well as enable CORS requests for some CDNs.', |
| 65 | 'presto-player' |
| 66 | ) }{ ' ' } |
| 67 | <a |
| 68 | href="https://prestoplayer.com/docs/performance-preferences-explained#global-player-performance-setting" |
| 69 | target="_blank" |
| 70 | rel="noreferrer" |
| 71 | className="text-brand-primary-600 hover:underline" |
| 72 | > |
| 73 | { __( 'Learn More', 'presto-player' ) } |
| 74 | </a> |
| 75 | </> |
| 76 | } |
| 77 | onClose={ () => setNoteDismissed( true ) } |
| 78 | /> |
| 79 | ) } |
| 80 | |
| 81 | <Switch |
| 82 | size="md" |
| 83 | value={ !! data.automations } |
| 84 | onChange={ ( val ) => update( { automations: val } ) } |
| 85 | label={ { |
| 86 | heading: ( |
| 87 | <span className="inline-flex items-center gap-1.5"> |
| 88 | { __( 'Enable Ajax Requests for Progress Integrations', 'presto-player' ) } |
| 89 | <Tooltip |
| 90 | content={ __( 'Required for LMS, membership, and automation integrations to track video progress correctly. Disable only if you are not using any such integrations.', 'presto-player' ) } |
| 91 | arrow |
| 92 | placement="right" |
| 93 | > |
| 94 | <Info className="size-3.5 text-icon-secondary cursor-help shrink-0" /> |
| 95 | </Tooltip> |
| 96 | </span> |
| 97 | ), |
| 98 | description: __( |
| 99 | 'Keep this on unless you do not plan on using automation, LMS or membership integrations.', |
| 100 | 'presto-player' |
| 101 | ), |
| 102 | } } |
| 103 | /> |
| 104 | </Container> |
| 105 | </SectionCard> |
| 106 | </SettingsPageShell> |
| 107 | ); |
| 108 | }; |
| 109 | |
| 110 | export default PerformancePage; |
| 111 |