/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/reader/user-profile/controller.tsx
71 строка
2 KB
Gabriel Caires
Reader: Keep the primary panel visible between lazy-loaded pages (#112911)
23 июл 2026, 15:33
Не верифицирован
23 июл 2026, 15:33
8ab6255
Код
Авторство
О чём код?
import page, { Context } from '@automattic/calypso-router'; import { ReactElement } from 'react'; import AsyncLoad from 'calypso/components/async-load'; import { trackPageLoad, trackScrollPage } from 'calypso/reader/controller-helper'; import { getCurrentUserName } from 'calypso/state/current-user/selectors'; const loadUserProfile = () => import( /* webpackChunkName: "async-load-calypso-reader-user-profile" */ 'calypso/reader/user-profile' ); interface UserProfileContext extends Context { params: { user_login?: string; user_id?: string; view?: string; }; primary: ReactElement; } const analyticsPageTitle = 'Reader'; export function redirectMeToCurrentUser( context: Context, next: () => void ): void { const currentUserName = getCurrentUserName( context.store.getState() ); if ( currentUserName ) { page.redirect( context.path.replace( '/reader/users/me', `/reader/users/${ currentUserName }` ) ); return; } next(); } export function userProfile( ctx: Context, next: () => void ): void { const context = ctx as UserProfileContext; const view = context.params.view || 'posts'; const userLogin = context.params.user_login; const userId = context.params.user_id; const basePath = context.params.view ? `/reader/users/:user_login/${ view }` : '/reader/users/:user_login'; const fullAnalyticsPageTitle = analyticsPageTitle + ' > User > ' + userLogin + // Keep the view sentance cased for backward consistency. ` > ${ view[ 0 ].toUpperCase() + view.slice( 1 ) }`; const mcKey = `user_${ view }`; trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey, { user_login: userLogin } ); context.primary = ( <AsyncLoad require={ loadUserProfile } key={ 'user-posts-' + userLogin } userLogin={ userLogin } userId={ userId } trackScrollPage={ trackScrollPage.bind( null, basePath, fullAnalyticsPageTitle, analyticsPageTitle, mcKey ) } path={ context.path } view={ view } placeholder={ null } /> ); next(); }