From 747f021c906a8894f0fbb2550adfa95873b25313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Su=C3=A1rez?= Date: Tue, 8 Mar 2022 16:41:04 -0300 Subject: [PATCH] Jetpack: Render site logo in the QR Post when it exists (#23292) Co-authored-by: oskosk --- .../update-jetpack-add-icon-to-qr-post | 4 ++ .../post-publish-qr-post-panel/index.js | 54 +++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-jetpack-add-icon-to-qr-post diff --git a/projects/plugins/jetpack/changelog/update-jetpack-add-icon-to-qr-post b/projects/plugins/jetpack/changelog/update-jetpack-add-icon-to-qr-post new file mode 100644 index 0000000000000..48dc10c8f1b47 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-jetpack-add-icon-to-qr-post @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Jetpack: Render site logo in the QR Post when it exists diff --git a/projects/plugins/jetpack/extensions/plugins/post-publish-qr-post-panel/index.js b/projects/plugins/jetpack/extensions/plugins/post-publish-qr-post-panel/index.js index 7b65b172c2d31..b67c4a9d4f730 100644 --- a/projects/plugins/jetpack/extensions/plugins/post-publish-qr-post-panel/index.js +++ b/projects/plugins/jetpack/extensions/plugins/post-publish-qr-post-panel/index.js @@ -5,6 +5,7 @@ import { PluginPostPublishPanel } from '@wordpress/edit-post'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; +import { store as coreStore } from '@wordpress/core-data'; import { SVG, Path, Component } from '@wordpress/components'; import { QRCode } from '@automattic/jetpack-components'; @@ -19,14 +20,46 @@ const QRIcon = () => ( ); +/** + * React hook that returns the site logo data. + * + * @returns {object} Site Logo object data. + */ +function useSiteLogo() { + const { id, mediaItemData } = useSelect( select => { + const { canUser, getEntityRecord, getEditedEntityRecord } = select( coreStore ); + const siteSettings = getEditedEntityRecord( 'root', 'site' ); + const siteData = getEntityRecord( 'root', '__unstableBase' ); + const siteLogo = siteSettings?.site_logo; + const readOnlyLogo = siteData?.site_logo; + const canUserEdit = canUser( 'update', 'settings' ); + const siteLogoId = canUserEdit ? siteLogo : readOnlyLogo; + const mediaItem = + siteLogoId && + select( coreStore ).getMedia( siteLogoId, { + context: 'view', + } ); + + return { + id: siteLogoId, + mediaItemData: mediaItem && { + mediaId: mediaItem.id, + url: mediaItem.source_url, + alt: mediaItem.alt_text, + }, + }; + }, [] ); + + return { id, ...mediaItemData }; +} + /** * React component that renders a QR code for the post, * pulling the post data from the editor store. * - * @param {object} props - Component props. * @returns {Component} The react component. */ -function QRPost( props ) { +function QRPost() { const { post: { title }, permalink, @@ -39,8 +72,23 @@ function QRPost( props ) { ); const codeContent = `${ title } ${ permalink }`; + const { url: siteLogologoUrl } = useSiteLogo(); - return ; + return ( + + ); } export const name = 'post-publish-qr-post-panel';