-
Notifications
You must be signed in to change notification settings - Fork 46
/
routesMap.js
101 lines (91 loc) · 2.03 KB
/
routesMap.js
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
import { redirect, NOT_FOUND } from 'redux-first-router'
import { fetchData } from './utils'
export default {
HOME: '/',
LIST: {
path: '/list/:category',
thunk: async (dispatch, getState) => {
const {
jwToken,
location: { payload: { category } },
videosByCategory
} = getState()
if (videosByCategory[category]) return
const videos = await fetchData(`/api/videos/${category}`, jwToken)
if (videos.length === 0) {
return dispatch({ type: NOT_FOUND })
}
dispatch({ type: 'VIDEOS_FETCHED', payload: { videos, category } })
}
},
VIDEO: {
path: '/video/:slug',
thunk: async (dispatch, getState) => {
// TASK FOR YOU. YES, YOU!
//
// visit a VIDEO page in the app, then refresh the page, then make
// this work when visited directly by copying the LIST route above and
// using fetchData(`/api/video/${slug}`) and by dispatching
// the the corresponding action type which I'll leave up to you to find
// in ../reducers/index.js :)
}
},
PLAY: {
path: '/video/:slug/play',
thunk: (dispatch, getState) => {
if (typeof window === 'undefined') {
const { slug } = getState().location.payload
const action = redirect({ type: 'VIDEO', payload: { slug } })
dispatch(action)
}
}
},
LOGIN: '/login',
ADMIN: {
path: '/admin', // TRY: visit this path or dispatch ADMIN
role: 'admin' // + change jwToken to 'real' in server/index.js
}
}
// DON'T GO DOWN THERE!
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// |
// ▼
// ANSWER: videoRoute.thunk.body:
/* HURRAY! You found the answers on the back of the cereal box!
const { jwToken, location: { payload: { slug } } } = getState()
const video = await fetchData(`/api/video/${slug}`, jwToken)
if (!video) {
return dispatch({ type: NOT_FOUND })
}
dispatch({ type: 'VIDEO_FOUND', payload: { slug, video } })
*/