Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: address JS feedback in #57688 #57961

Merged
merged 4 commits into from
Jan 18, 2024
Merged
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 @@ -9,7 +9,7 @@ import {
useEntityRecords,
store as coreStore,
} from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -265,8 +265,11 @@ function FontLibraryProvider( { children } ) {
alreadyInstalledFontFaces.length === 0
) {
throw new Error(
__( 'No font faces were installed. ' ) +
sprintf(
/* translators: %s: Specific error message returned from server. */
__( 'No font faces were installed. %s' ),
detailedErrorMessage
)
);
}

Expand All @@ -289,9 +292,13 @@ function FontLibraryProvider( { children } ) {

if ( unsucessfullyInstalledFontFaces.length > 0 ) {
throw new Error(
__(
'Some font faces were installed. There were some errors. '
) + detailedErrorMessage
sprintf(
/* translators: %s: Specific error message returned from server. */
__(
'Some font faces were installed. There were some errors. %s'
),
detailedErrorMessage
)
);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,76 @@
*/
import apiFetch from '@wordpress/api-fetch';

const FONT_FAMILIES_URL = '/wp/v2/font-families';
const FONT_COLLECTIONS_URL = '/wp/v2/font-collections';

export async function fetchInstallFontFamily( data ) {
const config = {
path: '/wp/v2/font-families',
path: FONT_FAMILIES_URL,
method: 'POST',
body: data,
};
return apiFetch( config ).then( ( response ) => {
return {
id: response.id,
...response.font_face_settings,
fontFace: [],
};
} );
const response = await apiFetch( config );
return {
id: response.id,
...response.font_family_settings,
fontFace: [],
};
}

export async function fetchInstallFontFace( fontFamilyId, data ) {
const config = {
path: `/wp/v2/font-families/${ fontFamilyId }/font-faces`,
path: `${ FONT_FAMILIES_URL }/${ fontFamilyId }/font-faces`,
method: 'POST',
body: data,
};
return apiFetch( config ).then( ( response ) => {
return {
id: response.id,
...response.font_face_settings,
};
} );
const response = await apiFetch( config );
return {
id: response.id,
...response.font_face_settings,
};
}

export async function fetchGetFontFamilyBySlug( slug ) {
const config = {
path: `/wp/v2/font-families?slug=${ slug }&_embed=true`,
path: `${ FONT_FAMILIES_URL }?slug=${ slug }&_embed=true`,
method: 'GET',
};
return apiFetch( config ).then( ( response ) => {
if ( ! response || response.length === 0 ) {
return null;
}
const fontFamilyPost = response[ 0 ];
return {
id: fontFamilyPost.id,
...fontFamilyPost.font_family_settings,
fontFace:
fontFamilyPost?._embedded?.font_faces.map(
( face ) => face.font_face_settings
) || [],
};
} );
const response = await apiFetch( config );
if ( ! response || response.length === 0 ) {
return null;
}
const fontFamilyPost = response[ 0 ];
return {
id: fontFamilyPost.id,
...fontFamilyPost.font_family_settings,
fontFace:
fontFamilyPost?._embedded?.font_faces.map(
( face ) => face.font_face_settings
) || [],
};
}

export async function fetchUninstallFontFamily( fontFamilyId ) {
const config = {
path: `/wp/v2/font-families/${ fontFamilyId }?force=true`,
path: `${ FONT_FAMILIES_URL }/${ fontFamilyId }?force=true`,
method: 'DELETE',
};
return apiFetch( config );
return await apiFetch( config );
}

export async function fetchFontCollections() {
const config = {
path: '/wp/v2/font-collections',
path: FONT_COLLECTIONS_URL,
method: 'GET',
};
return apiFetch( config );
return await apiFetch( config );
}

export async function fetchFontCollection( id ) {
const config = {
path: `/wp/v2/font-collections/${ id }`,
path: `${ FONT_COLLECTIONS_URL }/${ id }`,
method: 'GET',
};
return apiFetch( config );
return await apiFetch( config );
}
Loading