Skip to content

Commit

Permalink
Fix/default content (#13)
Browse files Browse the repository at this point in the history
* fix feed-item-content displaying default content instead of empty string when custom tag is selected and is empty

* reorganize components/utils
  • Loading branch information
cr0ybot authored May 3, 2023
1 parent c3df2b5 commit 627f628
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
19 changes: 12 additions & 7 deletions src/blocks/feed-item-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PanelBody, SelectControl } from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';

import CustomTagSelect from '../../common/components/custom-tag-select';
import CustomTagSelect from '../../components/custom-tag-select';

const contentTypeMap = {
html: 'content_html',
Expand Down Expand Up @@ -46,14 +46,19 @@ export default function Edit( {
customTag.length === 2
? custom[ customTag[ 0 ] ][ customTag[ 1 ] ]
: false;
const content = customContent
? contentType === 'htmlNoImg'
? customContent.replace( /<img[^>]*>/g, '' )
: customContent
: context[ `feed-block/item/${ contentTypeMap[ contentType ] }` ];
console.log( { customContent } );
const content =
customContent !== false
? contentType === 'htmlNoImg'
? customContent.replace( /<img[^>]*>/g, '' )
: customContent
: context[ `feed-block/item/${ contentTypeMap[ contentType ] }` ];
let contentElement = (
<div { ...blockProps }>
{ __( '<Feed Item Content>', 'feed-block' ) }
{ __( '<Feed Item Content: %s>', 'feed-block' ).replace(
'%s',
customTagname ? customTag[ 1 ] : 'default'
) }
</div>
);
if ( content && content !== '' ) {
Expand Down
6 changes: 3 additions & 3 deletions src/blocks/feed-item-content/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
*/

$contentTypeMap = array(
'text' => 'content_text',
'html' => 'content_html',
'text' => 'content_text',
'html' => 'content_html',
'htmlNoImg' => 'content_html_noimg',
);

$custom_tag = is_array( $attributes['customTag'] ) && count( $attributes['customTag'] ) === 2 ? $attributes['customTag'] : false;
$custom_tagname = $custom_tag ? $custom_tag[1] : false;
$custom_content = $custom_tag ? $block->context['feed-block/item/custom'][ $custom_tag[0] ][ $custom_tag[1] ] : false;

$content = $custom_content
$content = $custom_content !== false // Empty string is valid content.
? (
'htmlNoImg' === $attributes['contentType']
? preg_replace( '/<img[^>]*>/g', '', $custom_content )
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/feed-item-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useEntityProp } from '@wordpress/core-data';
import { format } from '@wordpress/date';
import { __ } from '@wordpress/i18n';

import CustomTagSelect from '../../common/components/custom-tag-select';
import CustomTagSelect from '../../components/custom-tag-select';

const fmt = new DateFormatter();

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/feed-item-image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';

import CustomTagSelect from '../../common/components/custom-tag-select';
import CustomTagSelect from '../../components/custom-tag-select';

import DimensionControls from './dimension-controls';
import Overlay from './overlay';
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/feed-item-summary/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { PanelBody, ToggleControl, RangeControl } from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';

import CustomTagSelect from '../../common/components/custom-tag-select';
import { trimWords } from '../../common/utils';
import CustomTagSelect from '../../components/custom-tag-select';
import { trimWords } from '../../utils/trim-words';

export default function Edit( {
attributes: {
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/feed-item-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ToggleControl, PanelBody } from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';

import CustomTagSelect from '../../common/components/custom-tag-select';
import CustomTagSelect from '../../components/custom-tag-select';

import HeadingLevelDropdown from './heading-level-dropdown';

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 627f628

Please sign in to comment.