Skip to content

Commit abd8b7d

Browse files
CJAllen056iq-dot
authored andcommitted
Remove playlist (MailOnline#21)
* removed playlist file | when no videos returned, returns empty array rather than predefined playlist * Some linting: using const rather than let where variable is not reassigned | deleted some unused variables * player should only render when videos are returned * console logging when no videos are found | Call for videos is made in constructor on initial state * Added isLoading param to state, which turns to false after video is loaded via setVideos * removed conditional rendering, for now. * video doesn't display when loading, and player dismounts if no video loaded * removed this.state.noVideos | removed skipcache=true from endpoint * Now getting videos in App rather than player * HandleScroll only running if video is loaded * minor changes: replaced uat with api, change in handleScroll function, passing container as prop to Player
1 parent dae5e00 commit abd8b7d

3 files changed

Lines changed: 34 additions & 440 deletions

File tree

src/App.jsx

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import 'whatwg-fetch';
44

55
import Player from './Player';
66

7-
import { itn, bristolsport, londontheinside, spectator, telegraph } from './playlist';
8-
97
const Modernizr = window.suggestv.Modernizr;
108

119
/**
@@ -47,7 +45,7 @@ const CLIENT = getClient();
4745

4846
class App extends React.Component {
4947
static getVideos(url, client) {
50-
let endpoint = `https://uat.suggestv.io/semantics?url=${url}&client=${client}&skipcache=true`;
48+
const endpoint = `https://api.suggestv.io/semantics?url=${url}&client=${client}`;
5149

5250
return fetch(endpoint, {
5351
method: 'GET',
@@ -126,6 +124,7 @@ class App extends React.Component {
126124
width: 640,
127125
height: 264,
128126
},
127+
isLoading: true,
129128
adError: 'N/A',
130129
adStart: 'N/A',
131130
adSrc: 'N/A',
@@ -138,11 +137,6 @@ class App extends React.Component {
138137
watchedDuration: 0,
139138
flashTestFinished: false,
140139
adLoadingPoster: 'https://build.suggestv.io/assets/adLoading.jpg',
141-
itn: itn.slice(0).sort(() => 0.5 - Math.random()),
142-
bristolsport: bristolsport.slice(0).sort(() => 0.5 - Math.random()),
143-
londontheinside: londontheinside.slice(0).sort(() => 0.5 - Math.random()),
144-
spectator: spectator.slice(0).sort(() => 0.5 - Math.random()),
145-
telegraph: telegraph.slice(0).sort(() => 0.5 - Math.random()),
146140
};
147141
this.setVideos = this.setVideos.bind(this);
148142
this.playlist = this.playlist.bind(this);
@@ -155,6 +149,14 @@ class App extends React.Component {
155149
console.log('SUGGESTV: client is ', CLIENT);
156150
window.addEventListener('scroll', this.handleScroll);
157151
window.addEventListener('touchmove', this.handleScroll);
152+
153+
App.getVideos(window.location.href, CLIENT).then((data) => {
154+
console.log('SUGGESTV: DATA', data);
155+
156+
this.setVideos(data);
157+
}).catch((err) => {
158+
console.log('SUGGESTV: Promise Error', err);
159+
});
158160
}
159161

160162
componentWillUnmount() {
@@ -163,17 +165,14 @@ class App extends React.Component {
163165
}
164166

165167
setVideos(data) {
166-
let videos = [];
168+
const videos = [];
167169
const SCORE_LIMIT = 15;
168170
this.setState({ query: data.keywords });
169171

170172
if (data !== null && data.results && data.results.length > 0) {
171173

172174
data.results.forEach((video) => {
173-
let keywordsMatched = [];
174-
const highlights = video.highlights;
175175
const fields = video.fields;
176-
const regex = /\*(\S[\s\S]*?)\*/g;
177176

178177
if (Number(fields._score[0]) > SCORE_LIMIT) {
179178
videos.push({
@@ -193,28 +192,20 @@ class App extends React.Component {
193192
this.setState({
194193
videos,
195194
videosFrom: 'semanticsearch',
195+
isLoading: false,
196196
});
197197
} else {
198-
console.log('SUGGESTV: none of the videos matched enough keywords or have big enough score');
199-
setDefaultClientVideos(this);
198+
console.log('SUGGESTV: no videos');
199+
this.setState({
200+
videos: [],
201+
isLoading: false,
202+
});
200203
}
201204
} else {
202-
setDefaultClientVideos(this);
203-
}
204-
205-
function setDefaultClientVideos(ctx) {
206-
videos = [];
207-
208-
if (CLIENT === 'localhost') videos = ctx.state.telegraph;
209-
if (CLIENT === 'telegraph') videos = ctx.state.telegraph;
210-
if (CLIENT === 'londontheinside') videos = ctx.state.londontheinside;
211-
if (CLIENT === 'beautyandthedirt') videos = ctx.state.londontheinside;
212-
if (CLIENT === 'bristol-sport') videos = ctx.state.bristolsport;
213-
if (CLIENT === 'proactiveinvestors') videos = ctx.state.itn;
214-
215-
ctx.setState({
216-
videos,
217-
videosFrom: 'defaultplaylist',
205+
console.log('SUGGESTV: no videos');
206+
this.setState({
207+
videos: [],
208+
isLoading: false,
218209
});
219210
}
220211
}
@@ -225,15 +216,15 @@ class App extends React.Component {
225216

226217
handleScroll() {
227218
const { pausedByUser, playedByUser, flashTestFinished, videoLoaded } = this.state;
228-
if (App.isInViewport(this.playerNode.videoNode)) {
229-
if (this.playerNode.videoNode && !pausedByUser && videoLoaded && flashTestFinished) {
219+
if (this.playerNode && App.isInViewport(this.playerNode.videoNode)) {
220+
if (!pausedByUser && videoLoaded && flashTestFinished) {
230221
if (CLIENT === 'cityam' || CLIENT === 'beautyandthedirt') {
231222
console.log('SUGGESTV: click-to-play');
232223
} else {
233224
this.playerNode.player.play();
234225
}
235226
}
236-
} else if (!playedByUser) {
227+
} else if (this.playerNode && !playedByUser) {
237228
this.playerNode.player.pause();
238229
}
239230
}
@@ -286,15 +277,11 @@ class App extends React.Component {
286277
}
287278

288279
render() {
289-
const url = window.location.href;
290-
291-
return (
280+
return this.state.videos.length > 0 && !this.loading ? (
292281
<Player
293282
ref={p => (this.playerNode = p)}
294283
updateState={this.updateState}
295284
plugins={this.plugins}
296-
setVideos={this.setVideos}
297-
getVideos={App.getVideos(url, CLIENT)}
298285
videos={this.state.videos}
299286
playlist={this.playlist}
300287
videoJsOptions={this.state.videoJsOptions}
@@ -305,8 +292,9 @@ class App extends React.Component {
305292
postAnalytics={this.postAnalytics}
306293
CLIENT={CLIENT}
307294
Modernizr={Modernizr}
295+
container={document.getElementById('suggestvplayer')}
308296
/>
309-
);
297+
) : null;
310298
}
311299
}
312300

src/Player.jsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@ class Player extends React.PureComponent {
1111
this.player = videojs(this.videoNode, this.props.videoJsOptions, () => {
1212
this.plugins(this.player);
1313

14-
this.props.getVideos.then((data) => {
15-
console.log('SUGGESTV: DATA', data);
16-
17-
this.props.setVideos(data);
18-
const container = document.getElementById('suggestvplayer');
19-
20-
// Only deal with tap events from users, ignore generated events
21-
container.addEventListener('tap', (e) => {
22-
if (!e.isTrusted) e.stopImmediatePropagation();
23-
}, true);
24-
25-
this.videoJsInit(this.props.videos);
26-
this.videoNode.muted = true;
27-
}).catch((err) => {
28-
console.log('SUGGESTV: Promise Error', err);
29-
this.player.dispose();
30-
});
14+
// Only deal with tap events from users, ignore generated events
15+
this.props.container.addEventListener('tap', (e) => {
16+
if (!e.isTrusted) e.stopImmediatePropagation();
17+
}, true);
18+
19+
this.videoJsInit(this.props.videos);
20+
this.videoNode.muted = true;
3121
});
3222
}
3323

0 commit comments

Comments
 (0)