Skip to content

Commit

Permalink
Add lessonPlanTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
renintw committed Dec 5, 2024
1 parent 1e2d4b0 commit 64335b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"lessonPlanContent": {
"type": "string",
"default": ""
},
"lessonPlanTitle": {
"type": "string",
"default": ""
}
},
"textdomain": "wporg-learn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import './style.scss';

registerBlockType( metadata.name, {
edit: function Edit( { attributes, setAttributes } ) {
const { lessonPlanId, lessonPlanContent } = attributes;
const { lessonPlanId, lessonPlanContent, lessonPlanTitle } = attributes;
const [ searchResults, setSearchResults ] = useState( [] );
const [ isExpanded, setIsExpanded ] = useState( false );

Expand All @@ -40,7 +40,10 @@ registerBlockType( metadata.name, {
const fetchLessonPlanContent = ( id ) => {
apiFetch( { path: `/wp/v2/lesson-plan/${ id }` } ).then( ( plan ) => {
const cleanedContent = plan.content.rendered.replace( /\s+/g, ' ' ).trim();
setAttributes( { lessonPlanContent: cleanedContent } );
setAttributes( {
lessonPlanContent: cleanedContent,
lessonPlanTitle: plan.title.rendered,
} );
} );
};

Expand All @@ -63,7 +66,10 @@ registerBlockType( metadata.name, {
apiFetch( {
path: `/wp/v2/lesson-plan/${ lessonPlanId }`,
method: 'POST',
data: { content: lessonPlanContent },
data: {
content: lessonPlanContent,
title: lessonPlanTitle,
},
} ).then( () => {
// Optionally, you can show a success message or update the UI
} );
Expand All @@ -90,14 +96,18 @@ registerBlockType( metadata.name, {
/>
{ lessonPlanId && (
<>
<RichText
tagName="h1"
value={ lessonPlanTitle }
onChange={ ( newTitle ) => setAttributes( { lessonPlanTitle: newTitle } ) }
/>
<Button variant="secondary" onClick={ () => setIsExpanded( ! isExpanded ) }>
{ isExpanded
? __( 'Collapse Content', 'wporg-learn' )
: __( 'Expand Content', 'wporg-learn' ) }
</Button>
<RichText
className={ isExpanded ? 'is-expanded' : 'is-collapsed' }
label={ __( 'Edit Lesson Plan Content', 'wporg-learn' ) }
value={ lessonPlanContent }
onChange={ ( newContent ) => setAttributes( { lessonPlanContent: newContent } ) }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
overflow: scroll;
border: 1px solid var(--wp--preset--color--charcoal-5);
margin: var(--wp--preset--spacing--10) 0;
padding: var(--wp--preset--spacing--10) 0;
padding: var(--wp--preset--spacing--10);

&.is-expanded {
max-height: none;
Expand All @@ -18,4 +18,8 @@
max-height: 300px;
}
}

h1.block-editor-rich-text__editable {
padding: 0 var(--wp--preset--spacing--10);
}
}

0 comments on commit 64335b8

Please sign in to comment.