@@ -17,6 +17,7 @@ import {
1717 ResizableBox ,
1818 Spinner ,
1919 ToggleControl ,
20+ Icon ,
2021} from '@wordpress/components' ;
2122import { useViewportMatch } from '@wordpress/compose' ;
2223import {
@@ -73,7 +74,7 @@ const SiteLogo = ( {
7374 title : siteEntities . title ,
7475 ...pick ( getSettings ( ) , [ 'imageSizes' , 'maxWidth' ] ) ,
7576 } ;
76- } ) ;
77+ } , [ ] ) ;
7778
7879 function onResizeStart ( ) {
7980 toggleSelection ( false ) ;
@@ -255,27 +256,38 @@ export default function LogoEdit( {
255256 const [ logoUrl , setLogoUrl ] = useState ( ) ;
256257 const [ error , setError ] = useState ( ) ;
257258 const ref = useRef ( ) ;
258- const { mediaItemData, siteLogo, url } = useSelect ( ( select ) => {
259- const siteSettings = select ( coreStore ) . getEditedEntityRecord (
260- 'root' ,
261- 'site'
262- ) ;
263- const mediaItem = siteSettings . site_logo
264- ? select ( coreStore ) . getEntityRecord (
259+
260+ const { siteLogoId, canUserEdit, url, mediaItemData } = useSelect (
261+ ( select ) => {
262+ const { canUser, getEntityRecord, getEditedEntityRecord } = select (
263+ coreStore
264+ ) ;
265+ const siteSettings = getEditedEntityRecord ( 'root' , 'site' ) ;
266+ const siteData = getEntityRecord ( 'root' , '__unstableBase' ) ;
267+ const _siteLogo = siteSettings ?. site_logo ;
268+ const _readOnlyLogo = siteData ?. site_logo ;
269+ const _canUserEdit = canUser ( 'update' , 'settings' ) ;
270+ const _siteLogoId = _siteLogo || _readOnlyLogo ;
271+ const mediaItem =
272+ _siteLogoId &&
273+ select ( coreStore ) . getEntityRecord (
265274 'root' ,
266275 'media' ,
267- siteSettings . site_logo
268- )
269- : null ;
270- return {
271- mediaItemData : mediaItem && {
272- url : mediaItem . source_url ,
273- alt : mediaItem . alt_text ,
274- } ,
275- siteLogo : siteSettings . site_logo ,
276- url : siteSettings . url ,
277- } ;
278- } , [ ] ) ;
276+ _siteLogoId ,
277+ { context : 'view' }
278+ ) ;
279+ return {
280+ siteLogoId : _siteLogoId ,
281+ canUserEdit : _canUserEdit ,
282+ url : siteData ?. url ,
283+ mediaItemData : mediaItem && {
284+ url : mediaItem . source_url ,
285+ alt : mediaItem . alt_text ,
286+ } ,
287+ } ;
288+ } ,
289+ [ ]
290+ ) ;
279291
280292 const { editEntityRecord } = useDispatch ( coreStore ) ;
281293 const setLogo = ( newValue ) =>
@@ -290,7 +302,6 @@ export default function LogoEdit( {
290302 setLogoUrl ( mediaItemData . url ) ;
291303 }
292304 }
293-
294305 const onSelectLogo = ( media ) => {
295306 if ( ! media ) {
296307 return ;
@@ -311,7 +322,7 @@ export default function LogoEdit( {
311322 setError ( message [ 2 ] ? message [ 2 ] : null ) ;
312323 } ;
313324
314- const controls = logoUrl && (
325+ const controls = canUserEdit && logoUrl && (
315326 < BlockControls group = "other" >
316327 < MediaReplaceFlow
317328 mediaURL = { logoUrl }
@@ -325,10 +336,10 @@ export default function LogoEdit( {
325336
326337 const label = __ ( 'Site Logo' ) ;
327338 let logoImage ;
328- if ( siteLogo === undefined ) {
339+ const isLoading = siteLogoId === undefined || ( siteLogoId && ! logoUrl ) ;
340+ if ( isLoading ) {
329341 logoImage = < Spinner /> ;
330342 }
331-
332343 if ( ! ! logoUrl ) {
333344 logoImage = (
334345 < SiteLogo
@@ -343,45 +354,46 @@ export default function LogoEdit( {
343354 />
344355 ) ;
345356 }
346-
347- const mediaPlaceholder = (
348- < MediaPlaceholder
349- icon = { < BlockIcon icon = { icon } /> }
350- labels = { {
351- title : label ,
352- instructions : __ (
353- 'Upload an image, or pick one from your media library, to be your site logo'
354- ) ,
355- } }
356- onSelect = { onSelectLogo }
357- accept = { ACCEPT_MEDIA_STRING }
358- allowedTypes = { ALLOWED_MEDIA_TYPES }
359- mediaPreview = { logoImage }
360- notices = {
361- error && (
362- < Notice status = "error" isDismissible = { false } >
363- { error }
364- </ Notice >
365- )
366- }
367- onError = { onUploadError }
368- />
369- ) ;
370-
371357 const classes = classnames ( className , {
372358 'is-default-size' : ! width ,
373359 } ) ;
374-
375360 const blockProps = useBlockProps ( {
376361 ref,
377362 className : classes ,
378363 } ) ;
379-
380364 return (
381365 < div { ...blockProps } >
382366 { controls }
383- { logoUrl && logoImage }
384- { ! logoUrl && mediaPlaceholder }
367+ { ! ! logoUrl && logoImage }
368+ { ! logoUrl && ! canUserEdit && (
369+ < div className = "site-logo_placeholder" >
370+ < Icon icon = { icon } />
371+ < p > { __ ( 'Site Logo' ) } </ p >
372+ </ div >
373+ ) }
374+ { ! logoUrl && canUserEdit && (
375+ < MediaPlaceholder
376+ icon = { < BlockIcon icon = { icon } /> }
377+ labels = { {
378+ title : label ,
379+ instructions : __ (
380+ 'Upload an image, or pick one from your media library, to be your site logo'
381+ ) ,
382+ } }
383+ onSelect = { onSelectLogo }
384+ accept = { ACCEPT_MEDIA_STRING }
385+ allowedTypes = { ALLOWED_MEDIA_TYPES }
386+ mediaPreview = { logoImage }
387+ notices = {
388+ error && (
389+ < Notice status = "error" isDismissible = { false } >
390+ { error }
391+ </ Notice >
392+ )
393+ }
394+ onError = { onUploadError }
395+ />
396+ ) }
385397 </ div >
386398 ) ;
387399}
0 commit comments