-
Notifications
You must be signed in to change notification settings - Fork 86
Studio: The "Add site" action doesn't work if there is no site #570
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { I18nProvider } from '@wordpress/react-i18n'; | |||||||
| import { createContext, useContext, useEffect, useMemo, useState, useCallback } from 'react'; | ||||||||
| import { getIpcApi } from '../lib/get-ipc-api'; | ||||||||
| import { SupportedLocale, getLocaleData } from '../lib/locale'; | ||||||||
| import { useOnboarding } from './use-onboarding'; | ||||||||
|
|
||||||||
| interface I18nDataContext { | ||||||||
| setLocale: ( localeKey: SupportedLocale ) => void; | ||||||||
|
|
@@ -19,26 +20,30 @@ export const I18nDataProvider = ( { children }: { children: React.ReactNode } ) | |||||||
| const [ initialized, setInitialized ] = useState< boolean >( false ); | ||||||||
| const [ i18n, setI18n ] = useState< I18n | null >( null ); | ||||||||
| const [ locale, setLocale ] = useState< SupportedLocale >( 'en' ); | ||||||||
| const { needsOnboarding } = useOnboarding(); | ||||||||
|
|
||||||||
| const initI18n = useCallback( async ( localeKey: SupportedLocale ) => { | ||||||||
| const translations = getLocaleData( localeKey )?.messages; | ||||||||
| const newI18n = createI18n( translations ); | ||||||||
| setI18n( newI18n ); | ||||||||
| // Update default I18n data to reflect language change when using | ||||||||
| // I18n functions from `@wordpress/i18n` package. | ||||||||
| // Note we need to update this in both the renderer and main processes. | ||||||||
| if ( translations ) { | ||||||||
| defaultI18n.setLocaleData( translations ); | ||||||||
| getIpcApi().setDefaultLocaleData( translations ); | ||||||||
| } else { | ||||||||
| // In case we don't find translations, we reset the locale data to | ||||||||
| // fallback to the default translations. | ||||||||
| defaultI18n.resetLocaleData(); | ||||||||
| getIpcApi().resetDefaultLocaleData(); | ||||||||
| } | ||||||||
| // App menu is reloaded to ensure the items show the translated strings. | ||||||||
| getIpcApi().setupAppMenu(); | ||||||||
| }, [] ); | ||||||||
| const initI18n = useCallback( | ||||||||
| async ( localeKey: SupportedLocale ) => { | ||||||||
| const translations = getLocaleData( localeKey )?.messages; | ||||||||
| const newI18n = createI18n( translations ); | ||||||||
| setI18n( newI18n ); | ||||||||
| // Update default I18n data to reflect language change when using | ||||||||
| // I18n functions from `@wordpress/i18n` package. | ||||||||
| // Note we need to update this in both the renderer and main processes. | ||||||||
| if ( translations ) { | ||||||||
| defaultI18n.setLocaleData( translations ); | ||||||||
| getIpcApi().setDefaultLocaleData( translations ); | ||||||||
| } else { | ||||||||
| // In case we don't find translations, we reset the locale data to | ||||||||
| // fallback to the default translations. | ||||||||
| defaultI18n.resetLocaleData(); | ||||||||
| getIpcApi().resetDefaultLocaleData(); | ||||||||
| } | ||||||||
| // App menu is reloaded to ensure the items show the translated strings. | ||||||||
| getIpcApi().setupAppMenu( { needsOnboarding } ); | ||||||||
|
Comment on lines
+42
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't expect that refreshing the app menu requires passing the entire config parameters, like The provider will use the hook Lines 24 to 26 in c444a1c
Additionally, the provider will expose a function to refresh the app menu that will be consumed here. We could also expose other functions in the future to make updates in the app bar in a reactive way. With the above approach, we'll unlock updating the app menu from anywhere on the app. WDYT?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe another alternative would be reading the number of sites directly on IPC? Something like (I didn't try the code):
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we need to manipulate just one menu item for now, I am going to merge this as this will have an immediate positive effect on the user experience. Let's open a separate issue to create a React context and make this more adaptable for future implementations.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created the issue related to this here: https://github.com/Automattic/dotcom-forge/issues/9313 |
||||||||
| }, | ||||||||
| [ needsOnboarding ] | ||||||||
| ); | ||||||||
|
|
||||||||
| useEffect( () => { | ||||||||
| if ( initialized ) { | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.