Skip to content

Commit

Permalink
fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Sep 9, 2024
1 parent c053a9a commit 3e948cc
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions packages/edit-site/src/components/post-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
useState,
useCallback,
useRef,
useEffect,
} from '@wordpress/element';
import { dateI18n, getDate, getSettings } from '@wordpress/date';
import {
Expand Down Expand Up @@ -146,11 +145,16 @@ function PostAuthorField( { item } ) {
);
}

function FeaturedImage( { item, viewType, getFeaturedMediaUrl } ) {
function FeaturedImage( { item, viewType } ) {
const mediaId = item.featured_media;

const media = getFeaturedMediaUrl( mediaId );

const media = useSelect(
( select ) => {
const { getEntityRecord } = select( coreStore );
return getEntityRecord( 'root', 'media', mediaId );
},
[ mediaId ]
);
const url = media?.source_url;
const title = media?.title?.rendered;

Expand Down Expand Up @@ -217,19 +221,14 @@ function usePostFields( viewType ) {
const { records: authors, isResolving: isLoadingAuthors } =
useEntityRecords( 'root', 'user', { per_page: -1 } );

const { frontPageId, postsPageId, getFeaturedMediaUrl } = useSelect(
( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPageId: siteSettings?.page_on_front,
postsPageId: siteSettings?.page_for_posts,
getFeaturedMediaUrl: ( id ) =>
getEntityRecord( 'root', 'media', id ),
};
},
[]
);
const { frontPageId, postsPageId } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPageId: siteSettings?.page_on_front,
postsPageId: siteSettings?.page_for_posts,
};
}, [] );

const fields = useMemo(
() => [
Expand All @@ -238,16 +237,20 @@ function usePostFields( viewType ) {
label: __( 'Featured Image' ),
type: 'image',
render: ( { item } ) => (
<FeaturedImage
item={ item }
viewType={ viewType }
getFeaturedMediaUrl={ getFeaturedMediaUrl }
/>
<FeaturedImage item={ item } viewType={ viewType } />
),
Edit: ( { field, onChange, data } ) => {
const { id } = field;

const value = field.getValue( { item: data } ) ?? '';
const value = field.getValue( { item: data } );

const media = useSelect(
( select ) => {
const { getEntityRecord } = select( coreStore );
return getEntityRecord( 'root', 'media', value );
},
[ value ]
);

const onChangeControl = useCallback(
( newValue ) =>
Expand All @@ -257,22 +260,13 @@ function usePostFields( viewType ) {
[ id, onChange ]
);

const media = getFeaturedMediaUrl( value );

const url = media?.source_url;
const title = media?.title?.rendered;
const filename =
media?.media_details?.file?.match( '([^/]+$)' )[ 0 ];

const ref = useRef( null );

// Focus to the media upload button when the component mounts.
useEffect( () => {
if ( ref.current ) {
ref.current.focus();
}
}, [] );

return (
<fieldset className="edit-site-dataviews-controls__featured-image">
<div className="edit-side-dataviews-controls__featured-image-container">
Expand Down Expand Up @@ -565,7 +559,7 @@ function usePostFields( viewType ) {
],
},
],
[ authors, getFeaturedMediaUrl, viewType, frontPageId, postsPageId ]
[ authors, viewType, frontPageId, postsPageId ]
);

return {
Expand Down

0 comments on commit 3e948cc

Please sign in to comment.