Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Modal,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useContext } from '@wordpress/element';
import { useState, useContext } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -44,6 +44,7 @@ function FontLibraryModal( {
initialTabId = 'installed-fonts',
} ) {
const { collections } = useContext( FontLibraryContext );
const [ selectedTab, setSelectedTab ] = useState( initialTabId );

const tabs = [
...DEFAULT_TABS,
Expand All @@ -58,7 +59,7 @@ function FontLibraryModal( {
className="font-library-modal"
>
<div className="font-library-modal__tabs">
<Tabs initialTabId={ initialTabId }>
<Tabs selectedTabId={ selectedTab } onSelect={ setSelectedTab }>
<Tabs.TabList>
{ tabs.map( ( { id, title } ) => (
<Tabs.Tab key={ id } tabId={ id }>
Expand All @@ -70,7 +71,13 @@ function FontLibraryModal( {
let contents;
switch ( id ) {
case 'upload-fonts':
contents = <UploadFonts />;
contents = (
<UploadFonts
onUpload={ () =>
setSelectedTab( 'installed-fonts' )
}
/>
);
break;
case 'installed-fonts':
contents = <InstalledFonts />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { unlock } from '../../../lock-unlock';

const { ProgressBar } = unlock( componentsPrivateApis );

function LocalFonts() {
const { installFont } = useContext( FontLibraryContext );
function LocalFonts( { onUpload } ) {
const { installFont, handleSetLibraryFontSelected } =
useContext( FontLibraryContext );
const [ notice, setNotice ] = useState( null );
const [ isUploading, setIsUploading ] = useState( false );
const supportedFormats =
Expand Down Expand Up @@ -170,6 +171,10 @@ function LocalFonts() {
type: 'success',
message: __( 'Fonts were installed successfully.' ),
} );
handleSetLibraryFontSelected( fontFamilies[ 0 ] );
if ( onUpload ) {
onUpload();
}
} catch ( error ) {
setNotice( {
type: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { __experimentalSpacer as Spacer } from '@wordpress/components';
*/
import LocalFonts from './local-fonts';

function UploadFonts() {
function UploadFonts( { onUpload } ) {
return (
<>
<Spacer margin={ 8 } />
<LocalFonts />
<LocalFonts onUpload={ onUpload } />
</>
);
}
Expand Down