Skip to content

Commit

Permalink
Allow the key takeaways to be edited or removed
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Jan 24, 2025
1 parent 075b0db commit 2f4905b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions includes/Classifai/Blocks/key-takeaways/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ const BlockEdit = ( props ) => {
},
];

const editTakeaways = ( index, value ) => {
const newTakeaways = [ ...takeaways ];

if ( ! value ) {
newTakeaways.splice( index, 1 );
} else {
newTakeaways[ index ] = value;
}

setAttributes( {
takeaways: newTakeaways,
} );
};

return (
<>
<BlockControls>
Expand Down Expand Up @@ -136,14 +150,28 @@ const BlockEdit = ( props ) => {
{ render === 'list' && (
<ul>
{ takeaways.map( ( takeaway, index ) => (
<li key={ index }>{ takeaway }</li>
<RichText
tagName="li"
value={ takeaway }
key={ index }
onChange={ ( value ) =>
editTakeaways( index, value )
}
/>
) ) }
</ul>
) }
{ render === 'paragraph' && (
<>
{ takeaways.map( ( takeaway, index ) => (
<p key={ index }>{ takeaway }</p>
<RichText
tagName="p"
value={ takeaway }
key={ index }
onChange={ ( value ) =>
editTakeaways( index, value )
}
/>
) ) }
</>
) }
Expand Down

0 comments on commit 2f4905b

Please sign in to comment.