Skip to content

Commit

Permalink
Update variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity committed Oct 22, 2024
1 parent 50071f0 commit ab77385
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const Meta = () => {
const [ foundationPages, setFoundationPages ] = useFoundationPages();
const foundationPagesProperties = useFoundationPagesProperties();

const updatePatterns = ( newValue: string ) => {
const newPatterns = newValue.split( '\n' ).map( line => line.trim() );
const updateFoundationPages = ( newValue: string ) => {
const newItems = newValue.split( '\n' ).map( line => line.trim() );

setFoundationPages( newPatterns );
setFoundationPages( newItems );
};

let content = null;

if ( foundationPagesProperties !== undefined ) {
content = (
<BypassPatterns
patterns={ foundationPages.join( '\n' ) }
setPatterns={ updatePatterns }
maxPatterns={ foundationPagesProperties.max_pages }
<List
items={ foundationPages.join( '\n' ) }
setItems={ updateFoundationPages }
maxItems={ foundationPagesProperties.max_pages }
/>
);
} else {
Expand Down Expand Up @@ -93,27 +93,23 @@ const Meta = () => {
);
};

type BypassPatternsProps = {
patterns: string;
setPatterns: ( newValue: string ) => void;
maxPatterns: number;
type ListProps = {
items: string;
setItems: ( newValue: string ) => void;
maxItems: number;
};

const BypassPatterns: React.FC< BypassPatternsProps > = ( {
patterns,
setPatterns,
maxPatterns,
} ) => {
const [ inputValue, setInputValue ] = useState( patterns );
const List: React.FC< ListProps > = ( { items, setItems, maxItems } ) => {
const [ inputValue, setInputValue ] = useState( items );
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [ inputInvalid, setInputInvalid ] = useState( false );

const validateInputValue = ( value: string ) => {
setInputValue( value );
setInputInvalid( ! validatePatterns( value ) );
setInputInvalid( ! validateItems( value ) );
};

const validatePatterns = ( value: string ) => {
const validateItems = ( value: string ) => {
const lines = value
.split( '\n' )
.map( line => line.trim() )
Expand All @@ -124,20 +120,20 @@ const BypassPatterns: React.FC< BypassPatternsProps > = ( {
return false;
}

// Check if the number of patterns exceeds maxPatterns
if ( lines.length > maxPatterns ) {
// Check if the number of items exceeds maxItems
if ( lines.length > maxItems ) {
return false;
}

return true;
};

useEffect( () => {
setInputValue( patterns );
}, [ patterns ] );
setInputValue( items );
}, [ items ] );

function save() {
setPatterns( inputValue );
setItems( inputValue );
}

return (
Expand All @@ -159,15 +155,15 @@ const BypassPatterns: React.FC< BypassPatternsProps > = ( {
_n(
'You must provide %d foundation page URL.',
'You must provide between 1 and %d foundation page URLs.',
maxPatterns,
maxItems,
'jetpack-boost'
),
maxPatterns
maxItems
) }
</p>
) }
<Button
disabled={ patterns === inputValue || inputInvalid }
disabled={ items === inputValue || inputInvalid }
onClick={ save }
className={ styles.button }
>
Expand Down

0 comments on commit ab77385

Please sign in to comment.