downshiftorg / prophoto7-issues

A current roadmap and bug tracking for ProPhoto 7
1 stars 0 forks source link

use featured image setting uses excerpt image in the visual builder #777

Open j-arens opened 5 years ago

j-arens commented 5 years ago

If a post does not have a featured image set but has an image within the content, then entities with the "use featured image" background image setting selected will show an image from the post in the visual builder but not on the front. I believe the correct behavior would be to not show anything in the visual builder if a featured image is not selected. It looks like the root cause is in the getFeaturedImgUri selector.

export const getFeaturedImageUri = createSelector(
  state => state.request.get('properties', Map()),
  getLoopPosts,
  (reqProperties: Map<string, *>, posts: List<Map<string, *>>) => {
    const isArchive = reqProperties.get('isArchive', false);
    const isSearch = reqProperties.get('isSearch', false);
    const isSingular = reqProperties.get('isArticle', false);
    if (isSingular || isSearch || isArchive) {
      const post = posts.first();
      // $FlowFixMe
      return Map.isMap(post) ? post.get('excerpt_image', '') : '';
    }
    return '';
  },
);

post.get('excerpt_image', '') is wrong. There's no guarantee that the excerpt image is the featured image. Could be a little tricky to fix because the post data only contains the id of the featured image, so we'll need to check if we fetched the image by that id, and if not we'll need to get it.