-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathreducer.js
More file actions
133 lines (126 loc) · 2.82 KB
/
reducer.js
File metadata and controls
133 lines (126 loc) · 2.82 KB
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
/* global tiobDash, localStorage */
const { onboarding, licenseTIOB } = tiobDash;
const firstEditor =
'undefined' !== typeof onboarding.sites &&
'undefined' !== typeof onboarding.sites.sites
? Object.keys( onboarding.sites.sites )[ 0 ]
: 'gutenberg';
const selectedEditor =
localStorage.getItem( 'neve-onboarding-editor' ) || firstEditor;
const initialLicense = licenseTIOB || {
key: 'free',
valid: 'invalid',
expiration: '',
tier: 0,
};
const params = new URLSearchParams( window.location.search );
const defaultSiteSlug = params.get( 'site' );
const findSiteBySlug = ( slug ) => {
const builders = onboarding?.sites?.sites || {};
for ( const builder of Object.keys( builders ) ) {
if ( builders[ builder ]?.[ slug ] ) {
return builders[ builder ][ slug ];
}
}
return null;
};
const defaultSite = defaultSiteSlug ? findSiteBySlug( defaultSiteSlug ) : null;
const initialState = {
sites: onboarding.sites || {},
editor: selectedEditor,
category: '',
currentSite: defaultSite,
fetching: false,
searchQuery: '',
license: initialLicense,
onboardingStep: defaultSite
? 3
: ( window.location.search.includes('show=welcome') ? 1 : 2 ),
userCustomSettings: {
siteName: null,
siteLogo: null,
},
importData: null,
pluginOptions: {},
error: null,
trackingId: '',
refresh: false,
};
export default ( state = initialState, action ) => {
switch ( action.type ) {
case 'SET_CATEGORY':
const { category } = action.payload;
return {
...state,
category,
};
case 'SET_ONBOARDING_STEP':
const { step } = action.payload;
return {
...state,
onboardingStep: step,
};
case 'SET_SEARCH_QUERY':
const { query } = action.payload;
return {
...state,
searchQuery: query,
};
case 'SET_FOCUSED_SITE':
const { siteData } = action.payload;
return {
...state,
currentSite: siteData,
};
case 'SET_IMPORT_DATA':
const { importData } = action.payload;
return {
...state,
importData,
};
case 'SET_PLUGIN_OPTIONS':
const { pluginOptions } = action.payload;
return {
...state,
pluginOptions,
};
case 'SET_ERROR':
const { error } = action.payload;
return {
...state,
error,
};
case 'SET_FETCHING':
const { fetching } = action.payload;
return {
...state,
fetching,
};
case 'SET_USER_CUSTOM_SETTINGS':
const { userCustomSettings } = action.payload;
return {
...state,
userCustomSettings,
};
case 'SET_CURRENT_EDITOR':
const { editor } = action.payload;
localStorage.setItem( 'neve-onboarding-editor', editor );
return {
...state,
editor,
};
case 'SET_TRACKING_ID':
const { trackingId } = action.payload;
return {
...state,
trackingId,
};
case 'SET_REFRESH':
const { refresh } = action.payload;
return {
...state,
refresh,
};
}
return state;
};