Skip to content

Commit

Permalink
Fix: lint JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
AleTorrisi committed Dec 30, 2024
1 parent 1d32f50 commit a010ca4
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 147 deletions.
2 changes: 1 addition & 1 deletion components/advancedSettings/JetpackBoost/SingleOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const SingleOption = ( { params, isChild, methods, constants } ) => {
! NewfoldRuntime.sdk.performance
.jetpack_boost_premium_is_active && (
<FeatureUpsell
cardText={constants.text.upgradeModule}
cardText={ constants.text.upgradeModule }
cardLink={ option.premiumUrl }
>
<ToggleField
Expand Down
196 changes: 105 additions & 91 deletions components/cacheSettings/index.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,114 @@
import { Container, RadioGroup } from "@newfold/ui-component-library";
import { Container, RadioGroup } from '@newfold/ui-component-library';

const CacheSettings = ({ methods, constants, Components }) => {
const [ cacheLevel, setCacheLevel ] = methods.useState(constants.store.cacheLevel);
const CacheSettings = ( { methods, constants, Components } ) => {
const [ cacheLevel, setCacheLevel ] = methods.useState(
constants.store.cacheLevel
);

const cacheOptions = [
{
label: constants.text.cacheLevel0Label,
description: constants.text.cacheLevel0Description + constants.text.cacheLevel0Recommendation,
value: 0,
notice: constants.text.cacheLevel0NoticeText,
},
{
label: constants.text.cacheLevel1Label,
description: constants.text.cacheLevel1Description + constants.text.cacheLevel1Recommendation,
value: 1,
notice: constants.text.cacheLevel1NoticeText,
},
{
label: constants.text.cacheLevel2Label,
description: constants.text.cacheLevel2Description + constants.text.cacheLevel2Recommendation,
value: 2,
notice: constants.text.cacheLevel2NoticeText,
},
{
label: constants.text.cacheLevel3Label,
description: constants.text.cacheLevel3Description + constants.text.cacheLevel3Recommendation,
value: 3,
notice: constants.text.cacheLevel3NoticeText,
},
];
const cacheOptions = [
{
label: constants.text.cacheLevel0Label,
description:
constants.text.cacheLevel0Description +
constants.text.cacheLevel0Recommendation,
value: 0,
notice: constants.text.cacheLevel0NoticeText,
},
{
label: constants.text.cacheLevel1Label,
description:
constants.text.cacheLevel1Description +
constants.text.cacheLevel1Recommendation,
value: 1,
notice: constants.text.cacheLevel1NoticeText,
},
{
label: constants.text.cacheLevel2Label,
description:
constants.text.cacheLevel2Description +
constants.text.cacheLevel2Recommendation,
value: 2,
notice: constants.text.cacheLevel2NoticeText,
},
{
label: constants.text.cacheLevel3Label,
description:
constants.text.cacheLevel3Description +
constants.text.cacheLevel3Recommendation,
value: 3,
notice: constants.text.cacheLevel3NoticeText,
},
];

const getCacheLevelNoticeTitle = () => {
return constants.text.cacheLevelNoticeTitle;
};
const getCacheLevelNoticeTitle = () => {
return constants.text.cacheLevelNoticeTitle;
};

const getCacheLevelNoticeText = () => {
return cacheOptions[cacheLevel].notice;
};
const getCacheLevelNoticeText = () => {
return cacheOptions[ cacheLevel ].notice;
};

const handleCacheLevelChange = (e) => {
methods.newfoldSettingsApiFetch(
{ cacheLevel: parseInt(e.target.value) },
methods.setError, (response) => {
setCacheLevel(parseInt(e.target.value));
}
);
};
const handleCacheLevelChange = ( e ) => {
methods.newfoldSettingsApiFetch(
{ cacheLevel: parseInt( e.target.value ) },
methods.setError,
( response ) => {
setCacheLevel( parseInt( e.target.value ) );
}
);
};

methods.useUpdateEffect(() => {
methods.setStore({
...constants.store,
cacheLevel,
});
methods.useUpdateEffect( () => {
methods.setStore( {
...constants.store,
cacheLevel,
} );

methods.makeNotice(
"cache-level-change-notice",
getCacheLevelNoticeTitle(),
getCacheLevelNoticeText(),
"success",
5000
);
}, [cacheLevel]);
methods.makeNotice(
'cache-level-change-notice',
getCacheLevelNoticeTitle(),
getCacheLevelNoticeText(),
'success',
5000
);
}, [ cacheLevel ] );

return (
<>
<Container.SettingsField
title={constants.text.cacheLevelTitle}
description={constants.text.cacheLevelDescription}
>
<RadioGroup
className="cache-options"
id="cache-type"
name="cache-level"
value=""
>
{cacheOptions.map((option) => {
return (
<Components.Fragment key={option.value}>
<RadioGroup.Radio
defaultChecked={option.value === constants.store.cacheLevel}
id={'cache-level-' + option.value}
label={option.label}
value={option.value}
name="cache-level"
onChange={handleCacheLevelChange}
/>
<div className="nfd-radio__description">
{option.description}
</div>
</Components.Fragment>
);
})}
</RadioGroup>
</Container.SettingsField>
</>
);
}
return (
<>
<Container.SettingsField
title={ constants.text.cacheLevelTitle }
description={ constants.text.cacheLevelDescription }
>
<RadioGroup
className="cache-options"
id="cache-type"
name="cache-level"
value=""
>
{ cacheOptions.map( ( option ) => {
return (
<Components.Fragment key={ option.value }>
<RadioGroup.Radio
defaultChecked={
option.value ===
constants.store.cacheLevel
}
id={ 'cache-level-' + option.value }
label={ option.label }
value={ option.value }
name="cache-level"
onChange={ handleCacheLevelChange }
/>
<div className="nfd-radio__description">
{ option.description }
</div>
</Components.Fragment>
);
} ) }
</RadioGroup>
</Container.SettingsField>
</>
);
};

export default CacheSettings;
export default CacheSettings;
70 changes: 34 additions & 36 deletions components/clearCache/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
import { Button, Container } from "@newfold/ui-component-library";
import { Button, Container } from '@newfold/ui-component-library';

const ClearCache = ({ methods, constants }) => {
const ClearCache = ( { methods, constants } ) => {
const clearCache = () => {
methods.newfoldPurgeCacheApiFetch(
{},
methods.setError,
( response ) => {
methods.makeNotice(
'disable-old-posts-comments-notice',
constants.text.clearCacheNoticeTitle,
null,
'success',
5000
);
}
);
};

const clearCache = () => {
methods.newfoldPurgeCacheApiFetch(
{},
methods.setError,
(response) => {
methods.makeNotice(
"disable-old-posts-comments-notice",
constants.text.clearCacheNoticeTitle,
null,
"success",
5000
);
}
);
};
return (
<Container.SettingsField
title={ constants.text.clearCacheTitle }
description={ constants.text.clearCacheDescription }
>
<Button
variant="secondary"
className="clear-cache-button"
disabled={ constants.store.cacheLevel > 0 ? false : true }
onClick={ clearCache }
>
{ constants.text.clearCacheButton }
</Button>
</Container.SettingsField>
);
};

return (
<Container.SettingsField
title={constants.text.clearCacheTitle}
description={constants.text.clearCacheDescription}
>
<Button
variant="secondary"
className="clear-cache-button"
disabled={constants.store.cacheLevel > 0 ? false : true}
onClick={clearCache}
>
{constants.text.clearCacheButton}
</Button>
</Container.SettingsField>

);
;}

export default ClearCache;
export default ClearCache;
32 changes: 13 additions & 19 deletions includes/burstSafetyModeFunctions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
namespace NewfoldLabs\WP\Module\Performance;
use NewfoldLabs\WP\Module\Performance\CacheTypes\Browser;
use NewfoldLabs\WP\Module\Performance\CacheTypes\Skip404;
Expand All @@ -7,13 +7,7 @@
$newfold_burst_safety_mode = (bool) get_option( 'newfold_burst_safety_mode' );

$site_cache_level = get_option( 'newfold_cache_level', 3 );
$site_skip404 = (bool) get_option( 'newfold_skip_404_handling', true );

if ( $newfold_burst_safety_mode === false ) {

}else{

}
$site_skip404 = (bool) get_option( 'newfold_skip_404_handling', true );

if ( defined( 'BURST_SAFETY_MODE' ) && BURST_SAFETY_MODE ) {
if ( $newfold_burst_safety_mode === false ) {
Expand All @@ -22,23 +16,23 @@
update_option( 'newfold_burst_safety_mode_site_cache_level', $current_level );
$browser = new Browser();
$browser::maybeAddRules( 3 );
if( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) {
$skip404 = new Skip404();
$skip404::maybeAddRules( true );
}
$responseHeaderManager = new ResponseHeaderManager();
if ( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) {
$skip404 = new Skip404();
$skip404::maybeAddRules( true );
}
$responseHeaderManager = new ResponseHeaderManager();
$responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', 3 );
}
} elseif ( $newfold_burst_safety_mode ) {
$cache_level = get_option( 'newfold_burst_safety_mode_site_cache_level' );
$browser = new Browser();
$browser::maybeAddRules( $cache_level );
if( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) {
$skip404 = new Skip404();
$skip404::maybeAddRules( false );
}
$responseHeaderManager = new ResponseHeaderManager();
$responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', $cache_level );
if ( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) {
$skip404 = new Skip404();
$skip404::maybeAddRules( false );
}
$responseHeaderManager = new ResponseHeaderManager();
$responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', $cache_level );
delete_option( 'newfold_burst_safety_mode' );
delete_option( 'newfold_burst_safety_mode_site_cache_level' );
}

0 comments on commit a010ca4

Please sign in to comment.