-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d32f50
commit a010ca4
Showing
4 changed files
with
153 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters