File size: 1,161 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import page, { type Callback } from '@automattic/calypso-router';
import { addQueryArgs } from 'calypso/lib/route';
import { hideMasterbar } from 'calypso/state/ui/actions';
import JetpackComFooter from '../pricing/jpcom-footer';
import JetpackComMasterbar from '../pricing/jpcom-masterbar';
import { Content } from './content';
import Header from './header';

export const jetpackComparisonContext: Callback = ( context, next ) => {
	const urlQueryArgs = context.query;
	const { lang } = context.params;
	const path = context.path;

	if ( context.pathname.endsWith( '/features/comparison' ) && urlQueryArgs.site ) {
		page.redirect( addQueryArgs( urlQueryArgs, `${ context.pathname }/${ urlQueryArgs.site }` ) );
		return;
	}

	context.store.dispatch( hideMasterbar() );
	context.nav = <JetpackComMasterbar pathname={ lang ? path.replace( `/${ lang }`, '' ) : path } />;
	context.header = <Header />;
	context.footer = <JetpackComFooter />;

	context.primary = (
		<Content
			footer={ context.footer }
			header={ context.header }
			locale={ lang }
			nav={ context.nav }
			urlQueryArgs={ urlQueryArgs }
			rootUrl={ context.pathname }
		/>
	);
	next();
};