-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
197 lines (174 loc) · 3.82 KB
/
Copy pathindex.js
File metadata and controls
197 lines (174 loc) · 3.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import {
} from "../utils/dummyData";
import {isArray} from "lodash";
import config from "../../config";
import {fromJS} from "immutable";
export const RECEIVE_MOMENT = "RECEIVE_MOMENT";
export const FETCH_MOMENT = "FETCH_MOMENT";
export const FETCH_METRICS = "FETCH_METRICS";
export const RECEIVE_METRICS = "RECEIVE_METRICS";
function receiveMoments({moments}) {
return {
type: RECEIVE_MOMENT,
moments
};
}
function fetchMoments() {
return {
type: FETCH_MOMENT
};
}
export function loadMoments(args) {
const {momentId} = args;
return dispatch => {
dispatch(fetchMoments());
fetch(`${config.apiEntry}/api/moments/${momentId}`)
.then((response) => {
return response.json();
})
.then((moment) => {
moment.media = fromJS(moment.media);
dispatch(receiveMoments({
moments: moment
}));
});
};
}
function fetchMetrics() {
return {
type: FETCH_METRICS
};
}
function receiveMetrics({metrics}) {
return {
type: RECEIVE_METRICS,
metrics
};
}
export function loadMetrics({momentId}) {
return dispatch => {
dispatch(fetchMetrics());
fetch(`${config.apiEntry}/api/moments/${momentId}/metrics`)
.then((response) => {
return response.json();
})
.then((metrics) => {
dispatch(receiveMetrics({metrics}));
});
};
}
export const RECEIVE_STORY = "RECEIVE_STORY";
export const FETCH_STORY = "FETCH_STORY";
function receiveStory({story}) {
return {
type: RECEIVE_STORY,
story
};
}
function fetchStory() {
return {
type: FETCH_STORY
};
}
export function loadStory(args) {
const {storyId} = args;
return dispatch => {
dispatch(fetchStory());
fetch(`${config.apiEntry}/api/stories/${storyId}`)
.then((response) => {
return response.json();
})
.then((story) => {
dispatch(receiveStory({
story
}));
});
};
}
export const RECEIVE_STORIES = "RECEIVE_STORIES";
export const FETCH_STORIES = "FETCH_STORIES";
function receiveStories({stories}) {
return {
type: RECEIVE_STORIES,
stories
};
}
function fetchStories() {
return {
type: FETCH_STORIES
};
}
export function loadStories() { //could send args... but we're just getting all stories
return dispatch => {
dispatch(fetchStories());
// simulate async request
fetch(`${config.apiEntry}/api/stories`)
.then((response) => {
return response.json();
})
.then((stories) => {
if(isArray(stories) && stories.length > 0) {
dispatch(receiveStories({
stories
}));
}
});
};
}
export const RECEIVE_TRANSCRIPTS = "RECEIVE_TRANSCRIPTS";
export const FETCH_TRANSCRIPTS = "FETCH_TRANSCRIPTS";
function fetchTranscripts() {
return {
type: FETCH_TRANSCRIPTS
};
}
function receiveTranscripts({transcripts}) {
return {
type: RECEIVE_TRANSCRIPTS,
transcripts
};
}
export function loadTranscripts({momentId}) {
return dispatch => {
dispatch(fetchTranscripts());
fetch(`${config.apiEntry}/api/moments/${momentId}/transcripts`)
.then((response) => {
return response.json();
})
.then((transcripts) => {
if(isArray(transcripts) && transcripts.length > 0) {
dispatch(receiveTranscripts({
transcripts: transcripts
}));
}
});
};
}
export const RECEIVE_AUDIO = "RECEIVE_AUDIO";
// export const FETCH_AUDIO = "FETCH_AUDIO";
// function fetchAudio() {
// return {
// type: FETCH_AUDIO
// };
// }
function receiveAudio({
time, playing, momentId
}) {
return {
type: RECEIVE_AUDIO,
playing,
time,
momentId
};
}
export function loadAudio({
time, playing, momentId
}) {
return dispatch => {
dispatch(receiveAudio({
playing,
time,
momentId
}));
};
}