Skip to content

Commit

Permalink
Adjusts the post render component part to replace withAPIData
Browse files Browse the repository at this point in the history
  • Loading branch information
coreymcollins committed Oct 4, 2018
1 parent 8200def commit 84fb1a6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 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,19 +84,20 @@ 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`;
} );

if ( 0 < selectedResultsQuery.length ) {
const selectedResultsFilter = selectedResultsQuery.join( '&' );

return {
selectedResultsJSONAlt: `/wp/v2/${ props.attributes.queryFor }?_embed&${ selectedResultsFilter }&orderby=include`,
selectedResultsJSONAlt: `/wp/v2/${ props.attributes.queryFor }?_embed&${ selectedResultsFilter }&orderby=include`
};
}
}
Expand Down

0 comments on commit 84fb1a6

Please sign in to comment.