File size: 4,688 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import AsyncLoad from 'calypso/components/async-load';
import {
	trackPageLoad,
	trackUpdatesLoaded,
	trackScrollPage,
} from 'calypso/reader/controller-helper';
import { recordTrack } from 'calypso/reader/stats';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';

const analyticsPageTitle = 'Reader';

export const createList = ( context, next ) => {
	const basePath = '/reader/list/new';
	const fullAnalyticsPageTitle = `${ analyticsPageTitle } > List > Create`;
	const mcKey = 'list';

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack( 'calypso_reader_list_create_loaded' );

	context.primary = (
		<AsyncLoad require="calypso/reader/list-manage" key="list-manage" isCreateForm />
	);
	next();
};

export const listListing = ( context, next ) => {
	const basePath = '/reader/list/:owner/:slug';
	const fullAnalyticsPageTitle =
		analyticsPageTitle + ' > List > ' + context.params.user + ' - ' + context.params.list;
	const mcKey = 'list';
	const streamKey =
		'list:' + JSON.stringify( { owner: context.params.user, slug: context.params.list } );
	const state = context.store.getState();

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack(
		'calypso_reader_list_loaded',
		{
			list_owner: context.params.user,
			list_slug: context.params.list,
		},
		{ pathnameOverride: getCurrentRoute( state ) }
	);

	context.primary = (
		<AsyncLoad
			require="calypso/reader/list-stream"
			key={ 'tag-' + context.params.user + '-' + context.params.list }
			streamKey={ streamKey }
			owner={ encodeURIComponent( context.params.user ) }
			slug={ encodeURIComponent( context.params.list ) }
			trackScrollPage={ trackScrollPage.bind(
				null,
				basePath,
				fullAnalyticsPageTitle,
				analyticsPageTitle,
				mcKey
			) }
			onUpdatesShown={ trackUpdatesLoaded.bind( null, mcKey ) }
		/>
	);
	next();
};

export const editList = ( context, next ) => {
	const basePath = '/reader/list/:owner/:slug/edit';
	const fullAnalyticsPageTitle = `${ analyticsPageTitle } > List > ${ context.params.user } - ${ context.params.list } > Edit`;
	const mcKey = 'list';

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack( 'calypso_reader_list_edit_loaded', {
		list_owner: context.params.user,
		list_slug: context.params.list,
	} );

	context.primary = (
		<AsyncLoad
			require="calypso/reader/list-manage"
			key="list-manage"
			owner={ encodeURIComponent( context.params.user ) }
			slug={ encodeURIComponent( context.params.list ) }
			selectedSection="details"
		/>
	);
	next();
};

export const editListItems = ( context, next ) => {
	const basePath = '/reader/list/:owner/:slug/edit/items';
	const fullAnalyticsPageTitle = `${ analyticsPageTitle } > List > ${ context.params.user } - ${ context.params.list } > Edit > Items`;
	const mcKey = 'list';

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack( 'calypso_reader_list_edit_items_loaded', {
		list_owner: context.params.user,
		list_slug: context.params.list,
	} );

	context.primary = (
		<AsyncLoad
			require="calypso/reader/list-manage"
			key="list-manage"
			owner={ encodeURIComponent( context.params.user ) }
			slug={ encodeURIComponent( context.params.list ) }
			selectedSection="items"
		/>
	);
	next();
};

export const exportList = ( context, next ) => {
	const basePath = '/reader/list/:owner/:slug/export';
	const fullAnalyticsPageTitle = `${ analyticsPageTitle } > List > ${ context.params.user } - ${ context.params.list } > Edit > Export`;
	const mcKey = 'list';

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack( 'calypso_reader_list_export_loaded', {
		list_owner: context.params.user,
		list_slug: context.params.list,
	} );

	context.primary = (
		<AsyncLoad
			require="calypso/reader/list-manage"
			key="list-manage"
			owner={ encodeURIComponent( context.params.user ) }
			slug={ encodeURIComponent( context.params.list ) }
			selectedSection="export"
		/>
	);
	next();
};

export const deleteList = ( context, next ) => {
	const basePath = '/reader/list/:owner/:slug/delete';
	const fullAnalyticsPageTitle = `${ analyticsPageTitle } > List > ${ context.params.user } - ${ context.params.list } > Edit > Delete`;
	const mcKey = 'list';

	trackPageLoad( basePath, fullAnalyticsPageTitle, mcKey );
	recordTrack( 'calypso_reader_list_delete_loaded', {
		list_owner: context.params.user,
		list_slug: context.params.list,
	} );

	context.primary = (
		<AsyncLoad
			require="calypso/reader/list-manage"
			key="list-manage"
			owner={ encodeURIComponent( context.params.user ) }
			slug={ encodeURIComponent( context.params.list ) }
			selectedSection="delete"
		/>
	);
	next();
};