Skip to content

Commit

Permalink
Font Library: Show error message when no fonts found to install (#58914)
Browse files Browse the repository at this point in the history
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: okmttdhr <[email protected]>
  • Loading branch information
4 people authored and youknowriad committed Feb 13, 2024
1 parent 72a22e5 commit 5ccaa81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ function FontLibraryProvider( { children } ) {
setRefreshKey( Date.now() );
};

// Reset notice on dismiss.
useEffect( () => {
if ( notice ) {
notice.onRemove = () => {
setNotice( null );
};
}
}, [ notice, setNotice ] );

const {
records: libraryPosts = [],
isResolving: isResolvingLibrary,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import {
__experimentalText as Text,
__experimentalHeading as Heading,
Expand All @@ -14,6 +15,11 @@ import {
import { chevronLeft } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { FontLibraryContext } from './context';

function TabPanelLayout( {
title,
description,
Expand All @@ -22,6 +28,8 @@ function TabPanelLayout( {
children,
footer,
} ) {
const { setNotice } = useContext( FontLibraryContext );

return (
<div className="font-library-modal__tabpanel-layout">
<Spacer margin={ 4 } />
Expand Down Expand Up @@ -53,7 +61,7 @@ function TabPanelLayout( {
<Spacer margin={ 1 } />
<Notice
status={ notice.type }
onRemove={ notice.onRemove }
onRemove={ () => setNotice( null ) }
>
{ notice.message }
</Notice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function UploadFonts() {
} );
if ( allowedFiles.length > 0 ) {
loadFiles( allowedFiles );
} else {
setNotice( {
type: 'error',
message: __( 'No fonts found to install.' ),
} );
setIsUploading( false );
}
};

Expand Down

0 comments on commit 5ccaa81

Please sign in to comment.