Skip to content

Commit 373bd5b

Browse files
committed
Replace superagent with waitForData and getAtURL
1 parent 54f88a7 commit 373bd5b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

client/gutenberg/editor/controller.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
import React from 'react';
77
import debug from 'debug';
8-
import request from 'superagent';
98
import { isEnabled } from 'config';
109
import { has, uniqueId } from 'lodash';
1110
import { setLocaleData } from '@wordpress/i18n';
@@ -19,6 +18,8 @@ import { setAllSitesSelected } from 'state/ui/actions';
1918
import { getSelectedSiteId, getSelectedSiteSlug } from 'state/ui/selectors';
2019
import { EDITOR_START } from 'state/action-types';
2120
import { initGutenberg } from './init';
21+
import { getAtUrl } from 'state/data-getters';
22+
import { waitForData } from 'state/data-layer/http-data';
2223

2324
function determinePostType( context ) {
2425
if ( context.path.startsWith( '/gutenberg/post/' ) ) {
@@ -54,18 +55,20 @@ export const jetpackBlocki18n = ( context, next ) => {
5455
return next();
5556
}
5657

57-
const languageFileUrl =
58-
'https://widgets.wp.com/languages/jetpack-gutenberg-blocks/' + localeSlug + '.json';
58+
const languageFileUrl = `https://widgets.wp.com/languages/jetpack-gutenberg-blocks/${ localeSlug }.json`;
5959

60-
request.get( languageFileUrl ).end( ( error, response ) => {
61-
if ( error ) {
60+
waitForData( {
61+
translations: () => getAtUrl( languageFileUrl ),
62+
} ).then( ( { translations: { state: requestState, data } } ) => {
63+
if ( requestState === 'failure' ) {
6264
debug(
63-
'Encountered an error loading locale file for ' + localeSlug + '. Falling back to English.'
65+
`Encountered an error loading locale file for ${ localeSlug }. Falling back to English.`
6466
);
65-
return next();
6667
}
6768

68-
setLocaleData( response.body, 'jetpack' );
69+
if ( data ) {
70+
setLocaleData( data.body, 'jetpack' );
71+
}
6972

7073
next();
7174
} );

0 commit comments

Comments
 (0)