@twreporter/universal-header 2.2.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +302 -0
  2. package/LICENSE +21 -0
  3. package/README.md +223 -0
  4. package/lib/actions/auth.js +105 -0
  5. package/lib/actions/error-action-creators.js +162 -0
  6. package/lib/components/action-button.js +216 -0
  7. package/lib/components/channels.js +420 -0
  8. package/lib/components/customized-link.js +49 -0
  9. package/lib/components/drop-down-menu.js +138 -0
  10. package/lib/components/hamburger-icons.js +270 -0
  11. package/lib/components/hamburger-menu.js +152 -0
  12. package/lib/components/header.js +233 -0
  13. package/lib/components/icons.js +276 -0
  14. package/lib/components/mobile-header.js +264 -0
  15. package/lib/components/search-box.js +214 -0
  16. package/lib/components/slogan.js +57 -0
  17. package/lib/constants/action-types.js +14 -0
  18. package/lib/constants/actions.js +35 -0
  19. package/lib/constants/categories.js +32 -0
  20. package/lib/constants/channels.js +41 -0
  21. package/lib/constants/colors.js +17 -0
  22. package/lib/constants/external-links.js +13 -0
  23. package/lib/constants/fonts.js +32 -0
  24. package/lib/constants/prop-types.js +46 -0
  25. package/lib/constants/services.js +31 -0
  26. package/lib/constants/slogan.js +9 -0
  27. package/lib/constants/theme.js +13 -0
  28. package/lib/containers/header.js +375 -0
  29. package/lib/contexts/header-context.js +17 -0
  30. package/lib/index.js +18 -0
  31. package/lib/reducers/auth.js +109 -0
  32. package/lib/reducers/index.js +22 -0
  33. package/lib/standalone-header.js +110 -0
  34. package/lib/utils/animations.js +32 -0
  35. package/lib/utils/icon.js +905 -0
  36. package/lib/utils/jwt.js +37 -0
  37. package/lib/utils/links.js +177 -0
  38. package/lib/utils/theme.js +415 -0
  39. package/package.json +38 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,302 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [2.2.0-rc.5](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.2.0-rc.4...@twreporter/universal-header@2.2.0-rc.5) (2021-09-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **universal-header:** fix channel top position in hd & channel active index logic ([12ff6bb](https://github.com/twreporter/twreporter-npm-packages/commit/12ff6bb125c90ef789297c9435222abac285a152))
12
+ * **universal-header:** fix code review ([8b5ff1c](https://github.com/twreporter/twreporter-npm-packages/commit/8b5ff1c1c18b7bb503641797f715cc3dd0c1b524))
13
+ * **universal-header:** fix infinite header transforming ([dab3463](https://github.com/twreporter/twreporter-npm-packages/commit/dab3463d2f9c1035a27a45cff97e39e622b58fc6))
14
+ * **universal-header:** fix ui defect & code review comment ([ada3578](https://github.com/twreporter/twreporter-npm-packages/commit/ada357865e24d3813557850724c2fbd2fc99a494))
15
+
16
+
17
+ ### Features
18
+
19
+ * **universal-header:** add narrow type header & header transform animation ([32b26bc](https://github.com/twreporter/twreporter-npm-packages/commit/32b26bcb213da38ec972eb972e3c648494cbcc50))
20
+
21
+
22
+
23
+
24
+
25
+ # [2.2.0-rc.4](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.2.0-rc.3...@twreporter/universal-header@2.2.0-rc.4) (2021-08-31)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * **universal-header:** update @twreporter/react-component dependency version ([f5d5a22](https://github.com/twreporter/twreporter-npm-packages/commit/f5d5a2255de72c27f91cc09b734242e7b17fd91e))
31
+
32
+
33
+
34
+
35
+
36
+ # [2.2.0-rc.3](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.2.0-rc.2...@twreporter/universal-header@2.2.0-rc.3) (2021-08-30)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **universal-header:** adress review comment ([cb94bfa](https://github.com/twreporter/twreporter-npm-packages/commit/cb94bfa1f1bccda0e8d7255eb42d6ff778c4e9f8))
42
+ * **universal-header:** fix click on ios & missing semi column ([1535641](https://github.com/twreporter/twreporter-npm-packages/commit/1535641c00613055e0c32ae9ab563c6932fe1958))
43
+ * **universal-header:** fix code review ([e5d3d08](https://github.com/twreporter/twreporter-npm-packages/commit/e5d3d08ee62685c0a49c8c746421ce68b3fa4693))
44
+ * **universal-header:** modal scroll problem ([c909c4d](https://github.com/twreporter/twreporter-npm-packages/commit/c909c4d224d3ae57d5ebc38287d78f4ad22e224d))
45
+ * **universal-header:** use @twreporter/react-components mobile-pop-up-modal to deal with scrolling problem ([5797493](https://github.com/twreporter/twreporter-npm-packages/commit/5797493c7bdd761cef0d284685f21db201f29ea3))
46
+
47
+
48
+ ### Features
49
+
50
+ * **universal-header:** add new hamburger menu ([d42d296](https://github.com/twreporter/twreporter-npm-packages/commit/d42d2966619c822883d1f6deeac89cbef68138a3))
51
+
52
+
53
+
54
+
55
+
56
+ # [2.2.0-rc.2](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.2.0-rc.1...@twreporter/universal-header@2.2.0-rc.2) (2021-08-11)
57
+
58
+
59
+ ### Bug Fixes
60
+
61
+ * **universal-header:** add prop types check to ActionButton component ([352eaba](https://github.com/twreporter/twreporter-npm-packages/commit/352eaba9a030894471661aeb91536a87d69d2cd2))
62
+ * **universal-header:** code review ([4620715](https://github.com/twreporter/twreporter-npm-packages/commit/46207156199667ec0f0f6a273291d580605c0324))
63
+
64
+
65
+ ### Features
66
+
67
+ * **universal-header:** add ActionButtom component & Slogan component (TWREPORTER-1) ([06ea138](https://github.com/twreporter/twreporter-npm-packages/commit/06ea1382368a1773f0433ef8b3c1fad2864a1ad4))
68
+
69
+
70
+
71
+
72
+
73
+ # [2.2.0-rc.1](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.2.0-rc.0...@twreporter/universal-header@2.2.0-rc.1) (2021-07-27)
74
+
75
+
76
+ ### Bug Fixes
77
+
78
+ * **universal-header:** fix code review & warning ([7478483](https://github.com/twreporter/twreporter-npm-packages/commit/7478483ee3ca573dab24d8769e38a81bd0222fec))
79
+
80
+
81
+ ### Features
82
+
83
+ * **universal-header:** adjust desktop category style & update icons ([21e5126](https://github.com/twreporter/twreporter-npm-packages/commit/21e5126bb7dbdd425e292315395a8327d9985d8c))
84
+
85
+
86
+
87
+
88
+
89
+ # [2.2.0-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.8...@twreporter/universal-header@2.2.0-rc.0) (2021-07-21)
90
+
91
+
92
+ ### Bug Fixes
93
+
94
+ * **universal-header:** remove useless variable ([086b95a](https://github.com/twreporter/twreporter-npm-packages/commit/086b95a811c50f2ba17f2afc1443f1d717772295))
95
+
96
+
97
+ ### Features
98
+
99
+ * **universal-header:** bookmark icon only show when login & modify desktop icon show/hide flow ([a97f727](https://github.com/twreporter/twreporter-npm-packages/commit/a97f727fb0c0966067bc7dae543353a774fb7b34))
100
+ * **universal-header:** bookmark icon only show when login & modify desktop icon show/hide flow ([009cf4c](https://github.com/twreporter/twreporter-npm-packages/commit/009cf4cea4bf8e180f1db6a5dc530e978530a8be))
101
+ * **universal-header:** remove TWREPORTER-73 ([6e077f3](https://github.com/twreporter/twreporter-npm-packages/commit/6e077f30f6bcd211533f9bc1e559ad3fe8edb4de))
102
+
103
+
104
+
105
+
106
+
107
+ ## [2.1.8](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.8-rc.0...@twreporter/universal-header@2.1.8) (2020-09-10)
108
+
109
+ **Note:** Version bump only for package @twreporter/universal-header
110
+
111
+
112
+
113
+
114
+
115
+ ## [2.1.8-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.7...@twreporter/universal-header@2.1.8-rc.0) (2020-09-10)
116
+
117
+ **Note:** Version bump only for package @twreporter/universal-header
118
+
119
+
120
+
121
+
122
+
123
+ ## [2.1.7](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.7-rc.0...@twreporter/universal-header@2.1.7) (2020-02-19)
124
+
125
+ **Note:** Version bump only for package @twreporter/universal-header
126
+
127
+
128
+
129
+
130
+
131
+ ## [2.1.7-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.6...@twreporter/universal-header@2.1.7-rc.0) (2020-02-14)
132
+
133
+
134
+ ### Bug Fixes
135
+
136
+ * **universal-header:** standalone header cannot work normally ([40fb08c](https://github.com/twreporter/twreporter-npm-packages/commit/40fb08c8df12b6b2a98cbe5890b41e7d181608b1))
137
+
138
+
139
+
140
+
141
+
142
+ ## [2.1.6](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.6-rc.0...@twreporter/universal-header@2.1.6) (2020-02-13)
143
+
144
+ **Note:** Version bump only for package @twreporter/universal-header
145
+
146
+
147
+
148
+
149
+
150
+ ## [2.1.6-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.5...@twreporter/universal-header@2.1.6-rc.0) (2020-02-12)
151
+
152
+ **Note:** Version bump only for package @twreporter/universal-header
153
+
154
+
155
+
156
+
157
+
158
+ ## [2.1.5](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.5-rc.0...@twreporter/universal-header@2.1.5) (2020-02-10)
159
+
160
+ **Note:** Version bump only for package @twreporter/universal-header
161
+
162
+
163
+
164
+
165
+
166
+ ## [2.1.5-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.4...@twreporter/universal-header@2.1.5-rc.0) (2020-02-10)
167
+
168
+ **Note:** Version bump only for package @twreporter/universal-header
169
+
170
+
171
+
172
+
173
+
174
+ ## [2.1.4](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.3...@twreporter/universal-header@2.1.4) (2020-01-14)
175
+
176
+ **Note:** Version bump only for package @twreporter/universal-header
177
+
178
+ ## [2.1.3](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.3-rc.1...@twreporter/universal-header@2.1.3) (2020-01-03)
179
+
180
+ **Note:** Version bump only for package @twreporter/universal-header
181
+
182
+ ## [2.1.3-rc.1](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.3-rc.0...@twreporter/universal-header@2.1.3-rc.1) (2020-01-03)
183
+
184
+ **Note:** Version bump only for package @twreporter/universal-header
185
+
186
+ ## [2.1.3-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.2...@twreporter/universal-header@2.1.3-rc.0) (2020-01-02)
187
+
188
+ **Note:** Version bump only for package @twreporter/universal-header
189
+
190
+ ## [2.1.2](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/universal-header@2.1.2-rc.7...@twreporter/universal-header@2.1.2) (2019-11-26)
191
+
192
+ **Note:** Version bump only for package @twreporter/universal-header
193
+
194
+ ## 2.1.2-rc.7 (2019-11-26)
195
+
196
+ **Note:** Version bump only for package @twreporter/universal-header
197
+
198
+ ### 2.1.2-rc.6
199
+
200
+ - dep upgrade:
201
+ - @twreporter/redux: 5.0.4 -> 5.0.7-rc.1
202
+
203
+ #### Commits
204
+
205
+ - [[11adfd0](https://github.com/twreporter/twreporter-npm-packages/commit/11adfd0)] - @twreporter/redux: v5.0.4 -> v5.0.7-rc.1(taylrj)
206
+
207
+ ### 2.1.2-rc.3
208
+
209
+ - dep upgrade:
210
+ - @twreporter/core: 1.1.2-rc.1 -> 1.1.2-rc.2
211
+
212
+ #### Commits
213
+
214
+ - [[a5ad626](https://github.com/twreporter/twreporter-npm-packages/commit/a5ad626229ad995150c3beb0d26d2e6a70254a84)] - [universal-header] upgrade @twreporter/core: 1.1.2-rc.1 -> 1.1.2-rc.2(taylrj)
215
+
216
+ #### Commits
217
+
218
+ - [[1f14b29](https://github.com/twreporter/twreporter-npm-packages/commit/1f14b29912ae703bfea7ea55725f57abdfaf314e)] - [universal-header] Update constant of `categories` in `channelPathnames` (taylrj)
219
+
220
+ ### 2.1.2-rc.2
221
+
222
+ - Update `categories` in `channelPathnames` from `/?section=categories` to `/#categories`
223
+
224
+ #### Commits
225
+
226
+ - [[1f14b29](https://github.com/twreporter/twreporter-npm-packages/commit/1f14b29912ae703bfea7ea55725f57abdfaf314e)] - [universal-header] Update constant of `categories` in `channelPathnames` (taylrj)
227
+
228
+ ### 2.1.2-rc.1
229
+
230
+ - dep upgrade:
231
+ - @twreporter/core: ^1.1.0 -> 1.1.2-rc.1
232
+
233
+ #### Commits
234
+
235
+ - [[f912e38](https://github.com/twreporter/twreporter-npm-packages/commit/f912e386173f6462c855c429dfaa8efa97679ce2)] - [universal-header] upgrade @twreporter/core: ^1.1.0 -> ^1.1.2-rc.1(nickhsine)
236
+
237
+ ### 2.1.1
238
+
239
+ - Remove deprecated React API `componentWillMount` and `componentWillReceiveProps`
240
+ - `react-transition-group@^1.2.1` -> `^2.0.0`
241
+ - `react-router-dom@^4.3.1` -> `^5.1.2`
242
+ - Per file imports are deprecated for `react-router-dom` v5
243
+
244
+ ### 2.1.0
245
+
246
+ - Spread out the header proptypes
247
+ - Update context prop constants
248
+ - Update standalone-header
249
+ - Remove unused code
250
+ - Take constants from core
251
+
252
+ - Update dependencies
253
+ - Add `@twreporter/core`: ^1.1.0
254
+ - Add `@twreporter/redux`: ^5.0.3
255
+ - Change `axios` version: ^0.18.0 -> ^0.19.0
256
+ - Replace `lodash.get` with `lodash/get`
257
+
258
+ ### 2.0.5
259
+
260
+ - Remove `dependencies.react-router` in package.json
261
+
262
+ ### 2.0.4
263
+
264
+ - Update link selector of channel items
265
+
266
+ ### 2.0.3
267
+
268
+ - Update appearance of `transparent` theme.
269
+ This patch does the following changes:
270
+
271
+ - Render light gray or normal icons on demand(refer to theme)
272
+ - Update src/utils/theme.js. Add `selectServiceIcons`,
273
+ `selectHoverFontColor`, `selectChannelTextShadow` and
274
+ `selectChannelsBgColor` functions.
275
+ - Render hover effect, font color, text shadow on demand
276
+
277
+ - Optimize svg files by svgo.
278
+ - Close slide down menu when menu items are clicked on mobile.
279
+
280
+ ### 2.0.2
281
+
282
+ - Fix undefined variables
283
+ - Add eslintrc
284
+
285
+ ### 2.0.1
286
+
287
+ - Set `text-decoration: none` for all links
288
+ - Fix old key from `branch` to `releaseBranch`
289
+
290
+ ### 2.0.0
291
+
292
+ #### Introduce Dependent and Standalone Header
293
+
294
+ - Dependent Header
295
+ It is used for server side rendering.
296
+ Clients should prepare redux store, combine redux reducers and
297
+ grant authorization for users by redux actions on the server.
298
+
299
+ - Standalone Header
300
+ It is used for client side rendering.
301
+ Clients need to `import { StandaloneHeader} from '@twreporter/universal-header'`,
302
+ and render `<StandalineHeader>` on the client side.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 TwReporter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # TWReporter Universal Header
2
+
3
+ Universal header(UH) is aimed to provide the consistent user experience
4
+ whicherver twreporter sites the users visit.
5
+
6
+ Universal header has two different ways to render both on client side
7
+ and server side.
8
+
9
+ For client side rendering, we call it _STANDALONE_ header, which is
10
+ along with redux store, requesting authentication and authorization after
11
+ `componentDidMount` on the page.
12
+
13
+ For server side rendering, we call it _DEPENDENT_ header, which is a
14
+ container component(see https://redux.js.org/basics/usage-with-react for information).
15
+ Because the _DEPENDENT_ header is a container component, the redux store
16
+ needs to be prepared by clients.
17
+
18
+ See the following example codes to understand how to use UH in different
19
+ situations.
20
+
21
+ ### Dependencies of UH
22
+
23
+ Make sure you have the following dependencies installed.
24
+
25
+ - react@^16.3.0 (Required)
26
+ - styled-components@^4.0.0 (Required)
27
+ - react-router-dom@^4.0.0 (Required by _DEPENDENT_ header)
28
+ - react-redux@^6.0.0 (Required by _DEPENDENT_ header)
29
+ - redux and redux-thunk (Required by _DEPENDENT_ header)
30
+
31
+ ### Standalone Header
32
+
33
+ To use standalone header is easy, see the following example.
34
+
35
+ ```javascript
36
+ // In your React components, such as app.js
37
+ import StandaloneHeader from '@twreporter/universal-header/dist/standalone-header'
38
+
39
+ class App extends React.Component {
40
+ render() {
41
+ // see the `isLinkExternal and releaseBranch` section for more info
42
+ const releaseBranch = 'master'
43
+ return (
44
+ <React.Fragment>
45
+ <StandaloneHeader releaseBranch={releaseBranch} />
46
+ </React.Fragment>
47
+ )
48
+ }
49
+ }
50
+ ```
51
+
52
+ ### Dependent Header
53
+
54
+ Dependent header is more complicated to setup than standalone header.
55
+ There are three parts(reducer, store and server side data dispatching)
56
+ need to be configured by clients.
57
+
58
+ ```javascript
59
+ // src/reducers/index.js of clients
60
+ import authReducer from '@twreporter/universal-header/dist/reducers/auth'
61
+ import { combineReducers } from 'redux'
62
+
63
+ const rootReducer = combineReducers({
64
+ // must be `auth` property
65
+ auth: authReducer,
66
+ // other reducers needed by clients
67
+ })
68
+
69
+ export default rootReducer
70
+
71
+ // src/store.js of clients
72
+ import reducer from './reducers/index'
73
+ import thunkMiddleware from 'redux-thunk'
74
+ import { createStore, applyMiddleware } from 'redux'
75
+
76
+ export function configureStore(initialState = {}) {
77
+ return createstore(
78
+ reducer, // reducers including uh.reducers.auth
79
+ initialstate,
80
+ applymiddleware(thunkmiddleware) // thunk middleware is required because of uh.actions.auth
81
+ )
82
+ }
83
+
84
+ export default {
85
+ configureStore,
86
+ }
87
+ ```
88
+
89
+ ```javascript
90
+ // in src/server.js
91
+ import HeaderContainer from '@twreporter/universal-header/dist/containers/header'
92
+ import ReactDOMServer from 'react-dom/server'
93
+ import authActions from '@twreporter/universal-header/dist/actions/auth'
94
+ import store from './store.js'
95
+ import { Provider } from 'react-redux'
96
+ impport serialize from 'serialize-javascript'
97
+
98
+ app.use(*, function(req, res, next) {
99
+ const cookie = req.get('cookie')
100
+ const store = store.configureStore()
101
+ const releaseBranch = process.env.RELEASE_BRANCH
102
+ const isLinkExternal = false
103
+ store.dispatch(authActions.getAccessToken(cookie))
104
+ .then(() => {
105
+ const markup = ReactDOMServer.renderToString(
106
+ <Provider store={store}>
107
+ <HeaderConatiner
108
+ releaseBranch={releaseBranch}
109
+ isLinkExternal={false}
110
+ />
111
+ </Provider>
112
+ ) // no catch here since authActions.getAccessToken always resolve the promise
113
+
114
+ const html = ReactDOMServer.renderToStaticMarkup(
115
+ <body>
116
+ <div id="app" dangerouslySetInnerHTML={{ __html: markup }}></div>
117
+ <script dangerouslySetInnerHTML={{ __html: `window.__REDUX_STATE__=${serialize(store.getState())};` }} charSet="UTF-8"/>
118
+ <script src="main.bundle.js" />
119
+ </body>
120
+ )
121
+ res.send('<!DOCTYPE>' + html)
122
+ })
123
+ })
124
+ ```
125
+
126
+ ```javascript
127
+ // in src/client.js
128
+ import 'babel-polyfill'
129
+ import ReactDOM from 'react-dom'
130
+ import store from './store'
131
+ import HeaderContainer from '@twreporter/universal-header/dist/containers/header'
132
+ import { Provider } from 'react-redux'
133
+
134
+ let reduxState
135
+ if (window.__REDUX_STATE__) {
136
+ reduxState = window.__REDUX_STATE__
137
+ }
138
+
139
+ const reduxStore = store.configureStore(reduxState)
140
+
141
+ // see the `isLinkExternal and releaseBranch` section for more info
142
+ const releaseBranch = process.env.RELEASE_BRANCH
143
+ const isLinkExternal = false
144
+
145
+ ReactDOM.hydrate(
146
+ <Provider store={reduxStore}>
147
+ <HeaderContainer
148
+ releaseBranch={releaseBranch}
149
+ isLinkExternal={isLinkExternal}
150
+ />
151
+ </Provider>,
152
+ document.getElementById('app')
153
+ )
154
+ ```
155
+
156
+ ### isLinkExternal, releaseBranch and theme
157
+
158
+ #### isLinkExternal
159
+
160
+ `isLinkExternal` is a bool.
161
+
162
+ If `isLinkExternal={false}`, the links of header would be relative paths, and
163
+ links' behavior would be handled by `react-router`.
164
+
165
+ If `isLinkExternal={true}`, all the links in the header would be `href`s,
166
+ handled by normal `<a>` HTML tag.
167
+
168
+ #### releaseBranch
169
+
170
+ Currently, `releaseBranch` works with `isLinkExternal={true}`.
171
+
172
+ `releaseBranch` is used to provide different links for different environments.
173
+ `releaseBranch` could be `master`, `test`, `staging` and `release`,
174
+ and each would generate corresponding links.
175
+ EX:
176
+ If you pass `releaseBranch="master"`, then the logo link would be `http://localhost:3000`.
177
+ If you pass `releaseBranch="test"`, then the logo link would be `http://localhost:3000`.
178
+ If you pass `releaseBranch="staging"`, then the logo link would be `https://staging.twreporter.org`
179
+ If you pass `releaseBranch="release"`, then the logo link would be `https://www.twreporter.org`
180
+ If you want to know more about how we generate links, please check `src/utils/links.js` out
181
+
182
+ #### theme
183
+
184
+ You can pass `theme` prop into standalone and dependent header to have different styles.
185
+ So far, `theme` supports the following values, including `normal`, `index`, `photography` and `transparent`.
186
+ You also can check the following theme lookup table for more information.
187
+
188
+ ```javascript
189
+ {
190
+ normal: {
191
+ fontColor: '#262626',
192
+ backgroundColor: '#f1f1f1',
193
+ logo: 'logo with black color fonts',
194
+ },
195
+ index: {
196
+ fontColor: '#262626',
197
+ backgroundColor: '#fff',
198
+ logo: 'logo with black color fonts',
199
+ },
200
+ photography: {
201
+ fontColor: '#fff',
202
+ backgroundColor: '#08192d',
203
+ logo: 'logo with white color fonts',
204
+ },
205
+ transparent: {
206
+ fontColor: '#fff',
207
+ backgroundColor: 'transparent',
208
+ logo: 'logo with white color fonts',
209
+ },
210
+ }
211
+ ```
212
+
213
+ #### TODO for theme customization
214
+
215
+ So far, the clients can not customize `fontColor`, `backgroundColor` and `logo` by themeselves.
216
+ However, we could support `theme` either to be string or to be an object like the following spec.
217
+
218
+ ```javascript
219
+ @typedef {Object} theme
220
+ @property {string} theme.bgColor
221
+ @property {string} theme.fontColor
222
+ @property {React.Element} theme.logo
223
+ ```
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAccessToken = getAccessToken;
7
+ exports["default"] = void 0;
8
+
9
+ var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
10
+
11
+ var _axios = _interopRequireDefault(require("axios"));
12
+
13
+ var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
14
+
15
+ var _get = _interopRequireDefault(require("lodash/get"));
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18
+
19
+ // lodash
20
+ var _ = {
21
+ get: _get["default"]
22
+ };
23
+ var timeout = 5000;
24
+ /**
25
+ * Send POST method request with Cookie in the headers
26
+ * to fetch the access_token.
27
+ *
28
+ * @param {string} [cookieList] - cookieList contains `id_token` cookie
29
+ * @return {Function} returned function will get executed by the Redux Thunk middleware
30
+ */
31
+
32
+ function getAccessToken(cookieList) {
33
+ /**
34
+ * @param {Function} dispatch - Redux store dispatch function
35
+ * @param {Function} getState - Redux store getState function
36
+ * @return {Promise} resolve with success action and reject with fail action
37
+ */
38
+ return function (dispatch, getState) {
39
+ var state = getState();
40
+
41
+ var apiOrigin = _.get(state, 'origins.api', '');
42
+
43
+ var url = "".concat(apiOrigin, "/v2/auth/token");
44
+ var headers = {};
45
+
46
+ if (cookieList) {
47
+ headers.Cookie = cookieList;
48
+ }
49
+
50
+ var options = {
51
+ timeout: timeout,
52
+ headers: headers,
53
+ withCredentials: true
54
+ };
55
+
56
+ var interceptor = _axios["default"].interceptors.request.use(function (config) {
57
+ var method = config.method,
58
+ url = config.url,
59
+ headers = config.headers,
60
+ data = config.data,
61
+ withCredentials = config.withCredentials,
62
+ timeout = config.timeout;
63
+ dispatch({
64
+ type: _actionTypes["default"].REQUEST_AUTH,
65
+ payload: {
66
+ method: method,
67
+ config: {
68
+ timeout: timeout,
69
+ withCredentials: withCredentials
70
+ },
71
+ url: url,
72
+ headers: headers,
73
+ body: data
74
+ }
75
+ });
76
+
77
+ _axios["default"].interceptors.request.eject(interceptor);
78
+
79
+ return config;
80
+ });
81
+
82
+ return _axios["default"].post(url, null, options).then(function (axiosRes) {
83
+ var successAction = {
84
+ type: _actionTypes["default"].AUTH_SUCCESS,
85
+ payload: {
86
+ headers: axiosRes.headers,
87
+ statusCode: axiosRes.status,
88
+ data: _.get(axiosRes, 'data.data')
89
+ }
90
+ };
91
+ dispatch(successAction);
92
+ return successAction;
93
+ })["catch"](function (err) {
94
+ var failAction = _errorActionCreators["default"].axios(err, _actionTypes["default"].AUTH_FAILURE);
95
+
96
+ dispatch(failAction);
97
+ return Promise.reject(failAction);
98
+ });
99
+ };
100
+ }
101
+
102
+ var _default = {
103
+ getAccessToken: getAccessToken
104
+ };
105
+ exports["default"] = _default;