/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/hosting/server-settings/controller.js
48 строк
1 KB
Ashar Fuadi
Untangling: clean up hosting-related routing logic (#100946)
07 мар 2025, 09:16
Не верифицирован
07 мар 2025, 09:16
5097531
Код
Авторство
О чём код?
import { createElement } from 'react'; import { fetchSitePlans } from 'calypso/state/sites/plans/actions'; import { getCurrentPlan } from 'calypso/state/sites/plans/selectors'; import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors'; import Hosting from './main'; function waitForState( context ) { return new Promise( ( resolve ) => { const unsubscribe = context.store.subscribe( () => { const state = context.store.getState(); const siteId = getSelectedSiteId( state ); if ( ! siteId ) { return; } const currentPlan = getCurrentPlan( state, siteId ); if ( ! currentPlan ) { return; } unsubscribe(); resolve(); } ); // Trigger a `store.subscribe()` callback context.store.dispatch( fetchSitePlans( getSelectedSiteId( context.store.getState() ) ) ); } ); } export async function handleHostingPanelRedirect( context, next ) { const { store } = context; await waitForState( context ); const state = store.getState(); const site = getSelectedSite( state ); const isAtomicSite = !! site?.is_wpcom_atomic || !! site?.is_wpcom_staging_site; const isJetpackNonAtomic = ! isAtomicSite && !! site?.jetpack; if ( isJetpackNonAtomic ) { context.page.replace( `/overview/${ site?.slug }` ); return; } next(); return; } export function layout( context, next ) { context.primary = createElement( Hosting ); next(); }