Skip to content

Commit

Permalink
Merge pull request #71 from WebDevStudios/hotfix/#63-replace-withapidata
Browse files Browse the repository at this point in the history
Hotfix/#63 replace withapidata
  • Loading branch information
jomurgel authored Oct 4, 2018
2 parents 1401e0f + d9f5f10 commit 141c9b0
Show file tree
Hide file tree
Showing 3 changed files with 1,028 additions and 1,018 deletions.
2,001 changes: 1,007 additions & 994 deletions dist/blocks.build.js

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions src/blocks/recent-posts/recent-posts.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/**
* External dependencies
*/
import _isUndefined from 'lodash/isUndefined';
import _pickBy from 'lodash/pickBy';
import isUndefined from 'lodash/isUndefined';
import pickBy from 'lodash/pickBy';
import moment from 'moment';
import classnames from 'classnames';
import { stringify } from 'querystringify';

/**
* WordPress dependencies
*/
const { Component } = wp.element;

const {
PanelBody,
Placeholder,
Expand All @@ -20,16 +18,15 @@ const {
Spinner,
ToggleControl,
Toolbar,
withAPIData,
} = wp.components;
const { __ } = wp.i18n;
const { decodeEntities } = wp.htmlEntities;

const {
InspectorControls,
BlockControls,
BlockAlignmentToolbar,
} = wp.editor;
const { withSelect } = wp.data;

/**
* Internal dependencies
Expand Down Expand Up @@ -85,8 +82,7 @@ class RecentPostsBlock extends Component {
render() {
const maxItems = DEFAULT_MAX_ITEMS;
const minItems = DEFAULT_MIN_ITEMS;
const latestPosts = this.props.latestPosts.data;
const { attributes, setAttributes } = this.props;
const { attributes, setAttributes, latestPosts } = this.props;
const { displayPostDate, align, postLayout, columns, order, orderby, postsToShow } = attributes;

const inspectorControls = !! this.props.isSelected && (
Expand Down Expand Up @@ -287,22 +283,25 @@ class RecentPostsBlock extends Component {
}
}

export default withAPIData( ( props ) => {
export default withSelect( ( select, props ) => {
const { postsToShow, order, orderby, taxonomies } = props.attributes;
const decodedTaxonomies = taxonomies ? JSON.parse( taxonomies ) : {};

// This can be made to be much more flexible and allow for custom taxonomies and the like. Phase 2!
const tags = decodedTaxonomies.post_tag && 0 < decodedTaxonomies.post_tag.length ? decodedTaxonomies.post_tag.map( tag => tag.id ) : undefined;
const categories = decodedTaxonomies.category && 0 < decodedTaxonomies.category.length ? decodedTaxonomies.category.map( category => category.id ) : undefined;
const latestPostsQuery = stringify( _pickBy( {

const { getEntityRecords } = select( 'core' );
const latestPostsQuery = pickBy( {
_embed: 'embed',
orderby,
order,
tags,
categories,
per_page: postsToShow, // eslint-disable-line
}, value => ! _isUndefined( value ) ) );
}, ( value ) => ! isUndefined( value ) );

return {
latestPosts: `/wp/v2/posts?${ latestPostsQuery }`,
latestPosts: getEntityRecords( 'postType', 'post', latestPostsQuery ),
};
} )( RecentPostsBlock );
22 changes: 10 additions & 12 deletions src/components/search-edit-component/post-render.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Import all of our Text Options requirements.
import { TextOptionsInlineStyles } from '../../components/text-options';

/**
* WordPress dependencies
*/
const {
withAPIData,
} = wp.components;

const { Component } = wp.element;

// Import all of our Text Options requirements.
import { TextOptionsInlineStyles } from '../../components/text-options';
const { withSelect } = wp.data;

class PostRenderer extends Component {
constructor( props ) {
Expand Down Expand Up @@ -73,7 +70,7 @@ class PostRenderer extends Component {
}

render() {
const selectedResults = this.props.selectedResultsJSONAlt.data;
const selectedResults = JSON.parse( this.props.posts );

return (
( undefined !== selectedResults && 0 < selectedResults.length ) ? (
Expand All @@ -87,11 +84,12 @@ class PostRenderer extends Component {
}
}

export default withAPIData( ( props ) => {
const { posts } = props;
export default withSelect( ( select, props ) => {
const { posts } = props,
postsArray = JSON.parse( posts );

if ( undefined !== posts && '[]' !== posts ) {
const selectedResultsQuery = JSON.parse( posts ).map( item => {
if ( undefined !== postsArray && '[]' !== postsArray ) {
const selectedResultsQuery = postsArray.map( item => {
return `include[]=${ item.id }&orderby=include`;
} );

Expand Down

0 comments on commit 141c9b0

Please sign in to comment.