Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Check for existing font family using GET /font-families?slug=.
  • Loading branch information
jffng committed Jan 16, 2024
commit 6648afc527c67e1c2b386df8990998f9a28e632a
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
* Internal dependencies
*/
import {
fetchGetFontFamilyBySlug,
fetchInstallFontFamily,
fetchUninstallFonts,
fetchFontCollections,
Expand Down Expand Up @@ -203,9 +204,13 @@ function FontLibraryProvider( { children } ) {
setIsInstalling( true );
try {
// Get the ID of the font family post, if it is already installed.
let fontFamilyId = libraryPosts.filter(
( post ) => post.font_family_settings.slug === font.slug
)[ 0 ]?.id;
let fontFamilyId = await fetchGetFontFamilyBySlug( font.slug )
.then( ( response ) => response?.[ 0 ]?.id )
.catch( ( e ) => {
// eslint-disable-next-line no-console
console.error( e );
return null;
} );

// Otherwise, install it.
if ( ! fontFamilyId ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export async function fetchInstallFontFace( fontFamilyId, data ) {
return apiFetch( config );
}

export async function fetchGetFontFamilyBySlug( slug ) {
const config = {
path: `/wp/v2/font-families?slug=${ slug }`,
method: 'GET',
};
return apiFetch( config );
}

export async function fetchUninstallFonts( fonts ) {
const data = {
font_families: fonts,
Expand Down