@ndla/video-search 4.1.44 → 4.1.46
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.
- package/es/PreviewVideo.js +12 -16
- package/es/VideoLoadMoreButton.js +15 -16
- package/es/VideoSearch.js +201 -230
- package/es/VideoSearchForm.js +46 -73
- package/es/VideoSearchList.js +32 -37
- package/es/VideoSearchResultBrightcove.js +39 -40
- package/es/VideoSearchResultYouTube.js +32 -37
- package/es/VideoTabs.js +8 -15
- package/es/index.js +8 -0
- package/es/shapes.js +3 -3
- package/es/videoHelpers.js +14 -15
- package/lib/PreviewVideo.js +20 -22
- package/lib/VideoLoadMoreButton.js +24 -24
- package/lib/VideoSearch.js +210 -238
- package/lib/VideoSearchForm.js +55 -81
- package/lib/VideoSearchList.js +41 -45
- package/lib/VideoSearchResultBrightcove.js +47 -46
- package/lib/VideoSearchResultYouTube.js +40 -43
- package/lib/VideoTabs.js +17 -23
- package/lib/index.js +8 -2
- package/lib/shapes.js +4 -7
- package/lib/videoHelpers.js +14 -15
- package/package.json +8 -8
package/es/PreviewVideo.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
1
|
/**
|
|
8
2
|
* Copyright (c) 2017-present, NDLA.
|
|
9
3
|
*
|
|
@@ -18,22 +12,24 @@ import { ButtonV2 } from '@ndla/button';
|
|
|
18
12
|
import { Cross } from '@ndla/icons/action';
|
|
19
13
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
20
14
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
21
|
-
|
|
15
|
+
const classes = new BEMHelper({
|
|
22
16
|
name: 'video-preview',
|
|
23
17
|
prefix: 'c-'
|
|
24
18
|
});
|
|
25
19
|
export default function PreviewVideo(_ref) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
let {
|
|
21
|
+
onVideoPreview,
|
|
22
|
+
children
|
|
23
|
+
} = _ref;
|
|
24
|
+
return _jsxs("div", {
|
|
25
|
+
...classes(),
|
|
26
|
+
children: [_jsx(ButtonV2, {
|
|
27
|
+
...classes('close'),
|
|
30
28
|
variant: "stripped",
|
|
31
|
-
onClick:
|
|
32
|
-
return onVideoPreview(undefined);
|
|
33
|
-
},
|
|
29
|
+
onClick: () => onVideoPreview(undefined),
|
|
34
30
|
children: _jsx(Cross, {})
|
|
35
|
-
})
|
|
36
|
-
})
|
|
31
|
+
}), children]
|
|
32
|
+
});
|
|
37
33
|
}
|
|
38
34
|
PreviewVideo.propTypes = {
|
|
39
35
|
children: PropTypes.node,
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
1
|
/**
|
|
8
2
|
* Copyright (c) 2017-present, NDLA.
|
|
9
3
|
*
|
|
@@ -17,26 +11,31 @@ import BEMHelper from 'react-bem-helper';
|
|
|
17
11
|
import { ButtonV2 } from '@ndla/button';
|
|
18
12
|
import { BrightcoveShape, YouTubeShape } from './shapes';
|
|
19
13
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
20
|
-
|
|
14
|
+
const classes = new BEMHelper({
|
|
21
15
|
name: 'video-search',
|
|
22
16
|
prefix: 'c-'
|
|
23
17
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
const VideoLoadMoreButton = props => {
|
|
19
|
+
const {
|
|
20
|
+
videos,
|
|
21
|
+
searching,
|
|
22
|
+
limit,
|
|
23
|
+
translations,
|
|
24
|
+
loadMoreVideos
|
|
25
|
+
} = props;
|
|
30
26
|
if (!videos || videos.length === 0 || videos.length % limit !== 0) {
|
|
31
27
|
return null;
|
|
32
28
|
}
|
|
33
|
-
return _jsx("div",
|
|
29
|
+
return _jsx("div", {
|
|
30
|
+
...classes('load-videos'),
|
|
34
31
|
children: _jsx(ButtonV2, {
|
|
35
32
|
disabled: searching,
|
|
36
33
|
onClick: loadMoreVideos,
|
|
37
|
-
children: searching ? _jsx("div",
|
|
34
|
+
children: searching ? _jsx("div", {
|
|
35
|
+
...classes('spinner')
|
|
36
|
+
}) : translations.loadMoreVideos
|
|
38
37
|
})
|
|
39
|
-
})
|
|
38
|
+
});
|
|
40
39
|
};
|
|
41
40
|
VideoLoadMoreButton.propTypes = {
|
|
42
41
|
searching: PropTypes.bool.isRequired,
|
package/es/VideoSearch.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
11
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
13
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
14
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
16
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
1
|
/**
|
|
18
2
|
* Copyright (c) 2017-present, NDLA.
|
|
19
3
|
*
|
|
@@ -22,29 +6,25 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
22
6
|
*
|
|
23
7
|
*/
|
|
24
8
|
|
|
25
|
-
import { Component } from 'react';
|
|
26
9
|
import PropTypes from 'prop-types';
|
|
10
|
+
import { Component } from 'react';
|
|
27
11
|
import BEMHelper from 'react-bem-helper';
|
|
28
12
|
import Pager from '@ndla/pager';
|
|
13
|
+
import { getLastPage } from './videoHelpers';
|
|
14
|
+
import VideoLoadMoreButton from './VideoLoadMoreButton';
|
|
29
15
|
import VideoSearchForm from './VideoSearchForm';
|
|
30
16
|
import VideoSearchList from './VideoSearchList';
|
|
31
|
-
import VideoLoadMoreButton from './VideoLoadMoreButton';
|
|
32
17
|
import VideoTabs from './VideoTabs';
|
|
33
|
-
import { getLastPage } from './videoHelpers';
|
|
34
18
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
35
19
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
36
|
-
|
|
20
|
+
const classes = new BEMHelper({
|
|
37
21
|
name: 'video-search',
|
|
38
22
|
prefix: 'c-'
|
|
39
23
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _this;
|
|
45
|
-
_classCallCheck(this, VideoSearch);
|
|
46
|
-
_this = _super.call(this);
|
|
47
|
-
_this.state = {
|
|
24
|
+
class VideoSearch extends Component {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.state = {
|
|
48
28
|
queryObject: {
|
|
49
29
|
query: '',
|
|
50
30
|
offset: 0,
|
|
@@ -57,218 +37,209 @@ var VideoSearch = /*#__PURE__*/function (_Component) {
|
|
|
57
37
|
lastPage: 0,
|
|
58
38
|
searching: false
|
|
59
39
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return _this;
|
|
40
|
+
this.submitVideoSearchQuery = this.submitVideoSearchQuery.bind(this);
|
|
41
|
+
this.changeQueryPage = this.changeQueryPage.bind(this);
|
|
42
|
+
this.onSearchTypeChange = this.onSearchTypeChange.bind(this);
|
|
43
|
+
this.searchVideos = this.searchVideos.bind(this);
|
|
44
|
+
this.onVideoPreview = this.onVideoPreview.bind(this);
|
|
45
|
+
this.onSelectVideo = this.onSelectVideo.bind(this);
|
|
46
|
+
this.loadMoreVideos = this.loadMoreVideos.bind(this);
|
|
68
47
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
48
|
+
componentDidMount() {
|
|
49
|
+
this.searchVideos(this.state.queryObject);
|
|
50
|
+
}
|
|
51
|
+
onVideoPreview(video) {
|
|
52
|
+
this.setState({
|
|
53
|
+
selectedVideo: video
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
onSelectVideo(video) {
|
|
57
|
+
const {
|
|
58
|
+
selectedType
|
|
59
|
+
} = this.state;
|
|
60
|
+
const {
|
|
61
|
+
onVideoSelect
|
|
62
|
+
} = this.props;
|
|
63
|
+
this.setState({
|
|
64
|
+
selectedVideo: undefined
|
|
65
|
+
});
|
|
66
|
+
onVideoSelect(video, selectedType);
|
|
67
|
+
}
|
|
68
|
+
onSearchTypeChange(type) {
|
|
69
|
+
let queryObject;
|
|
70
|
+
if (type === 'youtube') {
|
|
71
|
+
queryObject = {
|
|
72
|
+
query: '',
|
|
73
|
+
offset: undefined,
|
|
74
|
+
limit: undefined,
|
|
75
|
+
page: 1,
|
|
76
|
+
start: 1
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
queryObject = {
|
|
80
|
+
query: '',
|
|
81
|
+
offset: 0,
|
|
82
|
+
limit: 10,
|
|
83
|
+
page: undefined,
|
|
84
|
+
start: undefined
|
|
85
|
+
};
|
|
80
86
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
this.setState({
|
|
88
|
+
queryObject,
|
|
89
|
+
selectedType: type,
|
|
90
|
+
selectedVideo: undefined,
|
|
91
|
+
videos: [],
|
|
92
|
+
searching: true
|
|
93
|
+
}, this.searchVideos(queryObject, type));
|
|
94
|
+
}
|
|
95
|
+
loadMoreVideos() {
|
|
96
|
+
const {
|
|
97
|
+
queryObject,
|
|
98
|
+
videos,
|
|
99
|
+
selectedType
|
|
100
|
+
} = this.state;
|
|
101
|
+
const {
|
|
102
|
+
searchVideos,
|
|
103
|
+
onError
|
|
104
|
+
} = this.props;
|
|
105
|
+
this.setState({
|
|
106
|
+
searching: true
|
|
107
|
+
});
|
|
108
|
+
searchVideos({
|
|
109
|
+
...queryObject,
|
|
110
|
+
offset: queryObject.offset + 10
|
|
111
|
+
}, selectedType).then(result => {
|
|
112
|
+
this.setState(prevState => ({
|
|
113
|
+
queryObject: {
|
|
114
|
+
...prevState.queryObject,
|
|
115
|
+
offset: prevState.queryObject.offset + 10
|
|
116
|
+
},
|
|
117
|
+
videos: videos.concat(result),
|
|
118
|
+
searching: false
|
|
119
|
+
}));
|
|
120
|
+
}).catch(err => {
|
|
121
|
+
onError(err);
|
|
86
122
|
this.setState({
|
|
87
|
-
|
|
123
|
+
searching: false
|
|
88
124
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
changeQueryPage(page) {
|
|
128
|
+
this.setState({
|
|
129
|
+
lastPage: 0
|
|
130
|
+
});
|
|
131
|
+
const {
|
|
132
|
+
queryObject
|
|
133
|
+
} = this.state;
|
|
134
|
+
const nextIndex = queryObject.start + (page.page - queryObject.page) * 10;
|
|
135
|
+
const newQueryObject = {
|
|
136
|
+
...queryObject,
|
|
137
|
+
...page,
|
|
138
|
+
start: nextIndex
|
|
139
|
+
};
|
|
140
|
+
this.searchVideos(newQueryObject);
|
|
141
|
+
}
|
|
142
|
+
submitVideoSearchQuery(query) {
|
|
143
|
+
const queryObject = {
|
|
144
|
+
...this.state.queryObject,
|
|
145
|
+
query
|
|
146
|
+
};
|
|
147
|
+
this.searchVideos(queryObject);
|
|
148
|
+
}
|
|
149
|
+
searchVideos(queryObject) {
|
|
150
|
+
let selectedType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.state.selectedType;
|
|
151
|
+
const {
|
|
152
|
+
searchVideos,
|
|
153
|
+
onError
|
|
154
|
+
} = this.props;
|
|
155
|
+
searchVideos(queryObject, selectedType).then(result => {
|
|
156
|
+
if (selectedType === this.state.selectedType) {
|
|
157
|
+
this.setState(prevState => ({
|
|
158
|
+
queryObject: {
|
|
159
|
+
...prevState.queryObject,
|
|
160
|
+
query: queryObject.query,
|
|
161
|
+
page: queryObject.page,
|
|
162
|
+
start: queryObject.start,
|
|
163
|
+
offset: 0
|
|
164
|
+
},
|
|
165
|
+
videos: selectedType === 'youtube' ? result.items : result,
|
|
166
|
+
searching: false,
|
|
167
|
+
lastPage: getLastPage(result, selectedType)
|
|
168
|
+
}));
|
|
111
169
|
}
|
|
170
|
+
}).catch(err => {
|
|
171
|
+
onError(err);
|
|
112
172
|
this.setState({
|
|
113
|
-
|
|
114
|
-
selectedType: type,
|
|
115
|
-
selectedVideo: undefined,
|
|
116
|
-
videos: [],
|
|
117
|
-
searching: true
|
|
118
|
-
}, this.searchVideos(queryObject, type));
|
|
119
|
-
}
|
|
120
|
-
}, {
|
|
121
|
-
key: "loadMoreVideos",
|
|
122
|
-
value: function loadMoreVideos() {
|
|
123
|
-
var _this2 = this;
|
|
124
|
-
var _this$state = this.state,
|
|
125
|
-
queryObject = _this$state.queryObject,
|
|
126
|
-
videos = _this$state.videos,
|
|
127
|
-
selectedType = _this$state.selectedType;
|
|
128
|
-
var _this$props = this.props,
|
|
129
|
-
searchVideos = _this$props.searchVideos,
|
|
130
|
-
onError = _this$props.onError;
|
|
131
|
-
this.setState({
|
|
132
|
-
searching: true
|
|
133
|
-
});
|
|
134
|
-
searchVideos(_objectSpread(_objectSpread({}, queryObject), {}, {
|
|
135
|
-
offset: queryObject.offset + 10
|
|
136
|
-
}), selectedType).then(function (result) {
|
|
137
|
-
_this2.setState(function (prevState) {
|
|
138
|
-
return {
|
|
139
|
-
queryObject: _objectSpread(_objectSpread({}, prevState.queryObject), {}, {
|
|
140
|
-
offset: prevState.queryObject.offset + 10
|
|
141
|
-
}),
|
|
142
|
-
videos: videos.concat(result),
|
|
143
|
-
searching: false
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
}).catch(function (err) {
|
|
147
|
-
onError(err);
|
|
148
|
-
_this2.setState({
|
|
149
|
-
searching: false
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: "changeQueryPage",
|
|
155
|
-
value: function changeQueryPage(page) {
|
|
156
|
-
this.setState({
|
|
157
|
-
lastPage: 0
|
|
158
|
-
});
|
|
159
|
-
var queryObject = this.state.queryObject;
|
|
160
|
-
var nextIndex = queryObject.start + (page.page - queryObject.page) * 10;
|
|
161
|
-
var newQueryObject = _objectSpread(_objectSpread(_objectSpread({}, queryObject), page), {}, {
|
|
162
|
-
start: nextIndex
|
|
163
|
-
});
|
|
164
|
-
this.searchVideos(newQueryObject);
|
|
165
|
-
}
|
|
166
|
-
}, {
|
|
167
|
-
key: "submitVideoSearchQuery",
|
|
168
|
-
value: function submitVideoSearchQuery(query) {
|
|
169
|
-
var queryObject = _objectSpread(_objectSpread({}, this.state.queryObject), {}, {
|
|
170
|
-
query: query
|
|
171
|
-
});
|
|
172
|
-
this.searchVideos(queryObject);
|
|
173
|
-
}
|
|
174
|
-
}, {
|
|
175
|
-
key: "searchVideos",
|
|
176
|
-
value: function searchVideos(queryObject) {
|
|
177
|
-
var _this3 = this;
|
|
178
|
-
var selectedType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.state.selectedType;
|
|
179
|
-
var _this$props2 = this.props,
|
|
180
|
-
searchVideos = _this$props2.searchVideos,
|
|
181
|
-
onError = _this$props2.onError;
|
|
182
|
-
searchVideos(queryObject, selectedType).then(function (result) {
|
|
183
|
-
if (selectedType === _this3.state.selectedType) {
|
|
184
|
-
_this3.setState(function (prevState) {
|
|
185
|
-
return {
|
|
186
|
-
queryObject: _objectSpread(_objectSpread({}, prevState.queryObject), {}, {
|
|
187
|
-
query: queryObject.query,
|
|
188
|
-
page: queryObject.page,
|
|
189
|
-
start: queryObject.start,
|
|
190
|
-
offset: 0
|
|
191
|
-
}),
|
|
192
|
-
videos: selectedType === 'youtube' ? result.items : result,
|
|
193
|
-
searching: false,
|
|
194
|
-
lastPage: getLastPage(result, selectedType)
|
|
195
|
-
};
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}).catch(function (err) {
|
|
199
|
-
onError(err);
|
|
200
|
-
_this3.setState({
|
|
201
|
-
searching: false
|
|
202
|
-
});
|
|
173
|
+
searching: false
|
|
203
174
|
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return _jsx(Pager, {
|
|
233
|
-
page: page || 1,
|
|
234
|
-
lastPage: lastPage,
|
|
235
|
-
onClick: _this4.changeQueryPage
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
render() {
|
|
178
|
+
const {
|
|
179
|
+
translations,
|
|
180
|
+
locale,
|
|
181
|
+
enabledSources
|
|
182
|
+
} = this.props;
|
|
183
|
+
const {
|
|
184
|
+
queryObject,
|
|
185
|
+
lastPage,
|
|
186
|
+
videos,
|
|
187
|
+
selectedVideo,
|
|
188
|
+
selectedType,
|
|
189
|
+
searching
|
|
190
|
+
} = this.state;
|
|
191
|
+
const {
|
|
192
|
+
query,
|
|
193
|
+
page
|
|
194
|
+
} = queryObject;
|
|
195
|
+
const paginationItem = () => {
|
|
196
|
+
if (selectedType === 'brightcove') {
|
|
197
|
+
return _jsx(VideoLoadMoreButton, {
|
|
198
|
+
searching: searching,
|
|
199
|
+
videos: videos,
|
|
200
|
+
loadMoreVideos: this.loadMoreVideos,
|
|
201
|
+
limit: queryObject.limit,
|
|
202
|
+
translations: translations
|
|
236
203
|
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
content: _jsx("div", _objectSpread(_objectSpread({}, classes('list')), {}, {
|
|
243
|
-
children: selectedType === source.toLowerCase() && _jsx(VideoSearchList, {
|
|
244
|
-
translations: translations,
|
|
245
|
-
selectedType: source.toLowerCase(),
|
|
246
|
-
selectedVideo: selectedVideo,
|
|
247
|
-
videos: videos,
|
|
248
|
-
locale: locale,
|
|
249
|
-
onVideoPreview: _this4.onVideoPreview,
|
|
250
|
-
searching: searching,
|
|
251
|
-
onSelectVideo: _this4.onSelectVideo
|
|
252
|
-
})
|
|
253
|
-
}))
|
|
254
|
-
};
|
|
204
|
+
}
|
|
205
|
+
return _jsx(Pager, {
|
|
206
|
+
page: page || 1,
|
|
207
|
+
lastPage: lastPage,
|
|
208
|
+
onClick: this.changeQueryPage
|
|
255
209
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
210
|
+
};
|
|
211
|
+
const searchListTabs = enabledSources.map(source => ({
|
|
212
|
+
title: source,
|
|
213
|
+
id: source,
|
|
214
|
+
content: _jsx("div", {
|
|
215
|
+
...classes('list'),
|
|
216
|
+
children: selectedType === source.toLowerCase() && _jsx(VideoSearchList, {
|
|
217
|
+
translations: translations,
|
|
218
|
+
selectedType: source.toLowerCase(),
|
|
219
|
+
selectedVideo: selectedVideo,
|
|
220
|
+
videos: videos,
|
|
221
|
+
locale: locale,
|
|
222
|
+
onVideoPreview: this.onVideoPreview,
|
|
260
223
|
searching: searching,
|
|
261
|
-
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
224
|
+
onSelectVideo: this.onSelectVideo
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
}));
|
|
228
|
+
return _jsxs("div", {
|
|
229
|
+
...classes(),
|
|
230
|
+
children: [_jsx(VideoSearchForm, {
|
|
231
|
+
onSearchQuerySubmit: this.submitVideoSearchQuery,
|
|
232
|
+
query: query,
|
|
233
|
+
searching: searching,
|
|
234
|
+
translations: translations
|
|
235
|
+
}), _jsx(VideoTabs, {
|
|
236
|
+
searchTypes: selectedType,
|
|
237
|
+
tabs: searchListTabs,
|
|
238
|
+
onSearchTypeChange: this.onSearchTypeChange
|
|
239
|
+
}), paginationItem()]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
272
243
|
VideoSearch.propTypes = {
|
|
273
244
|
onVideoSelect: PropTypes.func.isRequired,
|
|
274
245
|
searchVideos: PropTypes.func.isRequired,
|