@ndla/video-search 4.1.44 → 4.1.47

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.
@@ -10,34 +10,32 @@ var _button = require("@ndla/button");
10
10
  var _action = require("@ndla/icons/action");
11
11
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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); }
14
- 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; }
15
- 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; }
16
- 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; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
- 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); } /**
19
- * Copyright (c) 2017-present, NDLA.
20
- *
21
- * This source code is licensed under the GPLv3 license found in the
22
- * LICENSE file in the root directory of this source tree.
23
- *
24
- */
25
- var classes = new _reactBemHelper.default({
13
+ /**
14
+ * Copyright (c) 2017-present, NDLA.
15
+ *
16
+ * This source code is licensed under the GPLv3 license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ const classes = new _reactBemHelper.default({
26
22
  name: 'video-preview',
27
23
  prefix: 'c-'
28
24
  });
29
25
  function PreviewVideo(_ref) {
30
- var onVideoPreview = _ref.onVideoPreview,
31
- children = _ref.children;
32
- return (0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, classes()), {}, {
33
- children: [(0, _jsxRuntime.jsx)(_button.ButtonV2, _objectSpread(_objectSpread({}, classes('close')), {}, {
26
+ let {
27
+ onVideoPreview,
28
+ children
29
+ } = _ref;
30
+ return (0, _jsxRuntime.jsxs)("div", {
31
+ ...classes(),
32
+ children: [(0, _jsxRuntime.jsx)(_button.ButtonV2, {
33
+ ...classes('close'),
34
34
  variant: "stripped",
35
- onClick: function onClick() {
36
- return onVideoPreview(undefined);
37
- },
35
+ onClick: () => onVideoPreview(undefined),
38
36
  children: (0, _jsxRuntime.jsx)(_action.Cross, {})
39
- })), children]
40
- }));
37
+ }), children]
38
+ });
41
39
  }
42
40
  PreviewVideo.propTypes = {
43
41
  children: _propTypes.default.node,
@@ -10,38 +10,39 @@ var _button = require("@ndla/button");
10
10
  var _shapes = require("./shapes");
11
11
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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); }
14
- 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; }
15
- 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; }
16
- 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; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
- 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); } /**
19
- * Copyright (c) 2017-present, NDLA.
20
- *
21
- * This source code is licensed under the GPLv3 license found in the
22
- * LICENSE file in the root directory of this source tree.
23
- *
24
- */
25
- var classes = new _reactBemHelper.default({
13
+ /**
14
+ * Copyright (c) 2017-present, NDLA.
15
+ *
16
+ * This source code is licensed under the GPLv3 license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ const classes = new _reactBemHelper.default({
26
22
  name: 'video-search',
27
23
  prefix: 'c-'
28
24
  });
29
- var VideoLoadMoreButton = function VideoLoadMoreButton(props) {
30
- var videos = props.videos,
31
- searching = props.searching,
32
- limit = props.limit,
33
- translations = props.translations,
34
- loadMoreVideos = props.loadMoreVideos;
25
+ const VideoLoadMoreButton = props => {
26
+ const {
27
+ videos,
28
+ searching,
29
+ limit,
30
+ translations,
31
+ loadMoreVideos
32
+ } = props;
35
33
  if (!videos || videos.length === 0 || videos.length % limit !== 0) {
36
34
  return null;
37
35
  }
38
- return (0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, classes('load-videos')), {}, {
36
+ return (0, _jsxRuntime.jsx)("div", {
37
+ ...classes('load-videos'),
39
38
  children: (0, _jsxRuntime.jsx)(_button.ButtonV2, {
40
39
  disabled: searching,
41
40
  onClick: loadMoreVideos,
42
- children: searching ? (0, _jsxRuntime.jsx)("div", _objectSpread({}, classes('spinner'))) : translations.loadMoreVideos
41
+ children: searching ? (0, _jsxRuntime.jsx)("div", {
42
+ ...classes('spinner')
43
+ }) : translations.loadMoreVideos
43
44
  })
44
- }));
45
+ });
45
46
  };
46
47
  VideoLoadMoreButton.propTypes = {
47
48
  searching: _propTypes.default.bool.isRequired,
@@ -54,5 +55,4 @@ VideoLoadMoreButton.propTypes = {
54
55
  limit: _propTypes.default.number.isRequired,
55
56
  loadMoreVideos: _propTypes.default.func.isRequired
56
57
  };
57
- var _default = VideoLoadMoreButton;
58
- exports.default = _default;
58
+ var _default = exports.default = VideoLoadMoreButton;
@@ -1,54 +1,36 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- var _react = require("react");
9
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = require("react");
10
9
  var _reactBemHelper = _interopRequireDefault(require("react-bem-helper"));
11
10
  var _pager = _interopRequireDefault(require("@ndla/pager"));
11
+ var _videoHelpers = require("./videoHelpers");
12
+ var _VideoLoadMoreButton = _interopRequireDefault(require("./VideoLoadMoreButton"));
12
13
  var _VideoSearchForm = _interopRequireDefault(require("./VideoSearchForm"));
13
14
  var _VideoSearchList = _interopRequireDefault(require("./VideoSearchList"));
14
- var _VideoLoadMoreButton = _interopRequireDefault(require("./VideoLoadMoreButton"));
15
15
  var _VideoTabs = _interopRequireDefault(require("./VideoTabs"));
16
- var _videoHelpers = require("./videoHelpers");
17
16
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
18
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- 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; }
20
- 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; }
21
- 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; }
22
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
- 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); } }
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
26
- 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); }
27
- 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); }
28
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
- 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); }; }
30
- 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); }
31
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
32
- 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; } }
33
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**
34
- * Copyright (c) 2017-present, NDLA.
35
- *
36
- * This source code is licensed under the GPLv3 license found in the
37
- * LICENSE file in the root directory of this source tree.
38
- *
39
- */
40
- var classes = new _reactBemHelper.default({
18
+ /**
19
+ * Copyright (c) 2017-present, NDLA.
20
+ *
21
+ * This source code is licensed under the GPLv3 license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ *
24
+ */
25
+
26
+ const classes = new _reactBemHelper.default({
41
27
  name: 'video-search',
42
28
  prefix: 'c-'
43
29
  });
44
- var VideoSearch = /*#__PURE__*/function (_Component) {
45
- _inherits(VideoSearch, _Component);
46
- var _super = _createSuper(VideoSearch);
47
- function VideoSearch() {
48
- var _this;
49
- _classCallCheck(this, VideoSearch);
50
- _this = _super.call(this);
51
- _this.state = {
30
+ class VideoSearch extends _react.Component {
31
+ constructor() {
32
+ super();
33
+ this.state = {
52
34
  queryObject: {
53
35
  query: '',
54
36
  offset: 0,
@@ -61,218 +43,209 @@ var VideoSearch = /*#__PURE__*/function (_Component) {
61
43
  lastPage: 0,
62
44
  searching: false
63
45
  };
64
- _this.submitVideoSearchQuery = _this.submitVideoSearchQuery.bind(_assertThisInitialized(_this));
65
- _this.changeQueryPage = _this.changeQueryPage.bind(_assertThisInitialized(_this));
66
- _this.onSearchTypeChange = _this.onSearchTypeChange.bind(_assertThisInitialized(_this));
67
- _this.searchVideos = _this.searchVideos.bind(_assertThisInitialized(_this));
68
- _this.onVideoPreview = _this.onVideoPreview.bind(_assertThisInitialized(_this));
69
- _this.onSelectVideo = _this.onSelectVideo.bind(_assertThisInitialized(_this));
70
- _this.loadMoreVideos = _this.loadMoreVideos.bind(_assertThisInitialized(_this));
71
- return _this;
46
+ this.submitVideoSearchQuery = this.submitVideoSearchQuery.bind(this);
47
+ this.changeQueryPage = this.changeQueryPage.bind(this);
48
+ this.onSearchTypeChange = this.onSearchTypeChange.bind(this);
49
+ this.searchVideos = this.searchVideos.bind(this);
50
+ this.onVideoPreview = this.onVideoPreview.bind(this);
51
+ this.onSelectVideo = this.onSelectVideo.bind(this);
52
+ this.loadMoreVideos = this.loadMoreVideos.bind(this);
72
53
  }
73
- _createClass(VideoSearch, [{
74
- key: "componentDidMount",
75
- value: function componentDidMount() {
76
- this.searchVideos(this.state.queryObject);
77
- }
78
- }, {
79
- key: "onVideoPreview",
80
- value: function onVideoPreview(video) {
81
- this.setState({
82
- selectedVideo: video
83
- });
54
+ componentDidMount() {
55
+ this.searchVideos(this.state.queryObject);
56
+ }
57
+ onVideoPreview(video) {
58
+ this.setState({
59
+ selectedVideo: video
60
+ });
61
+ }
62
+ onSelectVideo(video) {
63
+ const {
64
+ selectedType
65
+ } = this.state;
66
+ const {
67
+ onVideoSelect
68
+ } = this.props;
69
+ this.setState({
70
+ selectedVideo: undefined
71
+ });
72
+ onVideoSelect(video, selectedType);
73
+ }
74
+ onSearchTypeChange(type) {
75
+ let queryObject;
76
+ if (type === 'youtube') {
77
+ queryObject = {
78
+ query: '',
79
+ offset: undefined,
80
+ limit: undefined,
81
+ page: 1,
82
+ start: 1
83
+ };
84
+ } else {
85
+ queryObject = {
86
+ query: '',
87
+ offset: 0,
88
+ limit: 10,
89
+ page: undefined,
90
+ start: undefined
91
+ };
84
92
  }
85
- }, {
86
- key: "onSelectVideo",
87
- value: function onSelectVideo(video) {
88
- var selectedType = this.state.selectedType;
89
- var onVideoSelect = this.props.onVideoSelect;
93
+ this.setState({
94
+ queryObject,
95
+ selectedType: type,
96
+ selectedVideo: undefined,
97
+ videos: [],
98
+ searching: true
99
+ }, this.searchVideos(queryObject, type));
100
+ }
101
+ loadMoreVideos() {
102
+ const {
103
+ queryObject,
104
+ videos,
105
+ selectedType
106
+ } = this.state;
107
+ const {
108
+ searchVideos,
109
+ onError
110
+ } = this.props;
111
+ this.setState({
112
+ searching: true
113
+ });
114
+ searchVideos({
115
+ ...queryObject,
116
+ offset: queryObject.offset + 10
117
+ }, selectedType).then(result => {
118
+ this.setState(prevState => ({
119
+ queryObject: {
120
+ ...prevState.queryObject,
121
+ offset: prevState.queryObject.offset + 10
122
+ },
123
+ videos: videos.concat(result),
124
+ searching: false
125
+ }));
126
+ }).catch(err => {
127
+ onError(err);
90
128
  this.setState({
91
- selectedVideo: undefined
129
+ searching: false
92
130
  });
93
- onVideoSelect(video, selectedType);
94
- }
95
- }, {
96
- key: "onSearchTypeChange",
97
- value: function onSearchTypeChange(type) {
98
- var queryObject;
99
- if (type === 'youtube') {
100
- queryObject = {
101
- query: '',
102
- offset: undefined,
103
- limit: undefined,
104
- page: 1,
105
- start: 1
106
- };
107
- } else {
108
- queryObject = {
109
- query: '',
110
- offset: 0,
111
- limit: 10,
112
- page: undefined,
113
- start: undefined
114
- };
131
+ });
132
+ }
133
+ changeQueryPage(page) {
134
+ this.setState({
135
+ lastPage: 0
136
+ });
137
+ const {
138
+ queryObject
139
+ } = this.state;
140
+ const nextIndex = queryObject.start + (page.page - queryObject.page) * 10;
141
+ const newQueryObject = {
142
+ ...queryObject,
143
+ ...page,
144
+ start: nextIndex
145
+ };
146
+ this.searchVideos(newQueryObject);
147
+ }
148
+ submitVideoSearchQuery(query) {
149
+ const queryObject = {
150
+ ...this.state.queryObject,
151
+ query
152
+ };
153
+ this.searchVideos(queryObject);
154
+ }
155
+ searchVideos(queryObject) {
156
+ let selectedType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.state.selectedType;
157
+ const {
158
+ searchVideos,
159
+ onError
160
+ } = this.props;
161
+ searchVideos(queryObject, selectedType).then(result => {
162
+ if (selectedType === this.state.selectedType) {
163
+ this.setState(prevState => ({
164
+ queryObject: {
165
+ ...prevState.queryObject,
166
+ query: queryObject.query,
167
+ page: queryObject.page,
168
+ start: queryObject.start,
169
+ offset: 0
170
+ },
171
+ videos: selectedType === 'youtube' ? result.items : result,
172
+ searching: false,
173
+ lastPage: (0, _videoHelpers.getLastPage)(result, selectedType)
174
+ }));
115
175
  }
176
+ }).catch(err => {
177
+ onError(err);
116
178
  this.setState({
117
- queryObject: queryObject,
118
- selectedType: type,
119
- selectedVideo: undefined,
120
- videos: [],
121
- searching: true
122
- }, this.searchVideos(queryObject, type));
123
- }
124
- }, {
125
- key: "loadMoreVideos",
126
- value: function loadMoreVideos() {
127
- var _this2 = this;
128
- var _this$state = this.state,
129
- queryObject = _this$state.queryObject,
130
- videos = _this$state.videos,
131
- selectedType = _this$state.selectedType;
132
- var _this$props = this.props,
133
- searchVideos = _this$props.searchVideos,
134
- onError = _this$props.onError;
135
- this.setState({
136
- searching: true
137
- });
138
- searchVideos(_objectSpread(_objectSpread({}, queryObject), {}, {
139
- offset: queryObject.offset + 10
140
- }), selectedType).then(function (result) {
141
- _this2.setState(function (prevState) {
142
- return {
143
- queryObject: _objectSpread(_objectSpread({}, prevState.queryObject), {}, {
144
- offset: prevState.queryObject.offset + 10
145
- }),
146
- videos: videos.concat(result),
147
- searching: false
148
- };
149
- });
150
- }).catch(function (err) {
151
- onError(err);
152
- _this2.setState({
153
- searching: false
154
- });
155
- });
156
- }
157
- }, {
158
- key: "changeQueryPage",
159
- value: function changeQueryPage(page) {
160
- this.setState({
161
- lastPage: 0
162
- });
163
- var queryObject = this.state.queryObject;
164
- var nextIndex = queryObject.start + (page.page - queryObject.page) * 10;
165
- var newQueryObject = _objectSpread(_objectSpread(_objectSpread({}, queryObject), page), {}, {
166
- start: nextIndex
167
- });
168
- this.searchVideos(newQueryObject);
169
- }
170
- }, {
171
- key: "submitVideoSearchQuery",
172
- value: function submitVideoSearchQuery(query) {
173
- var queryObject = _objectSpread(_objectSpread({}, this.state.queryObject), {}, {
174
- query: query
175
- });
176
- this.searchVideos(queryObject);
177
- }
178
- }, {
179
- key: "searchVideos",
180
- value: function searchVideos(queryObject) {
181
- var _this3 = this;
182
- var selectedType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.state.selectedType;
183
- var _this$props2 = this.props,
184
- searchVideos = _this$props2.searchVideos,
185
- onError = _this$props2.onError;
186
- searchVideos(queryObject, selectedType).then(function (result) {
187
- if (selectedType === _this3.state.selectedType) {
188
- _this3.setState(function (prevState) {
189
- return {
190
- queryObject: _objectSpread(_objectSpread({}, prevState.queryObject), {}, {
191
- query: queryObject.query,
192
- page: queryObject.page,
193
- start: queryObject.start,
194
- offset: 0
195
- }),
196
- videos: selectedType === 'youtube' ? result.items : result,
197
- searching: false,
198
- lastPage: (0, _videoHelpers.getLastPage)(result, selectedType)
199
- };
200
- });
201
- }
202
- }).catch(function (err) {
203
- onError(err);
204
- _this3.setState({
205
- searching: false
206
- });
179
+ searching: false
207
180
  });
208
- }
209
- }, {
210
- key: "render",
211
- value: function render() {
212
- var _this4 = this;
213
- var _this$props3 = this.props,
214
- translations = _this$props3.translations,
215
- locale = _this$props3.locale,
216
- enabledSources = _this$props3.enabledSources;
217
- var _this$state2 = this.state,
218
- queryObject = _this$state2.queryObject,
219
- lastPage = _this$state2.lastPage,
220
- videos = _this$state2.videos,
221
- selectedVideo = _this$state2.selectedVideo,
222
- selectedType = _this$state2.selectedType,
223
- searching = _this$state2.searching;
224
- var query = queryObject.query,
225
- page = queryObject.page;
226
- var paginationItem = function paginationItem() {
227
- if (selectedType === 'brightcove') {
228
- return (0, _jsxRuntime.jsx)(_VideoLoadMoreButton.default, {
229
- searching: searching,
230
- videos: videos,
231
- loadMoreVideos: _this4.loadMoreVideos,
232
- limit: queryObject.limit,
233
- translations: translations
234
- });
235
- }
236
- return (0, _jsxRuntime.jsx)(_pager.default, {
237
- page: page || 1,
238
- lastPage: lastPage,
239
- onClick: _this4.changeQueryPage
181
+ });
182
+ }
183
+ render() {
184
+ const {
185
+ translations,
186
+ locale,
187
+ enabledSources
188
+ } = this.props;
189
+ const {
190
+ queryObject,
191
+ lastPage,
192
+ videos,
193
+ selectedVideo,
194
+ selectedType,
195
+ searching
196
+ } = this.state;
197
+ const {
198
+ query,
199
+ page
200
+ } = queryObject;
201
+ const paginationItem = () => {
202
+ if (selectedType === 'brightcove') {
203
+ return (0, _jsxRuntime.jsx)(_VideoLoadMoreButton.default, {
204
+ searching: searching,
205
+ videos: videos,
206
+ loadMoreVideos: this.loadMoreVideos,
207
+ limit: queryObject.limit,
208
+ translations: translations
240
209
  });
241
- };
242
- var searchListTabs = enabledSources.map(function (source) {
243
- return {
244
- title: source,
245
- id: source,
246
- content: (0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, classes('list')), {}, {
247
- children: selectedType === source.toLowerCase() && (0, _jsxRuntime.jsx)(_VideoSearchList.default, {
248
- translations: translations,
249
- selectedType: source.toLowerCase(),
250
- selectedVideo: selectedVideo,
251
- videos: videos,
252
- locale: locale,
253
- onVideoPreview: _this4.onVideoPreview,
254
- searching: searching,
255
- onSelectVideo: _this4.onSelectVideo
256
- })
257
- }))
258
- };
210
+ }
211
+ return (0, _jsxRuntime.jsx)(_pager.default, {
212
+ page: page || 1,
213
+ lastPage: lastPage,
214
+ onClick: this.changeQueryPage
259
215
  });
260
- return (0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, classes()), {}, {
261
- children: [(0, _jsxRuntime.jsx)(_VideoSearchForm.default, {
262
- onSearchQuerySubmit: this.submitVideoSearchQuery,
263
- query: query,
216
+ };
217
+ const searchListTabs = enabledSources.map(source => ({
218
+ title: source,
219
+ id: source,
220
+ content: (0, _jsxRuntime.jsx)("div", {
221
+ ...classes('list'),
222
+ children: selectedType === source.toLowerCase() && (0, _jsxRuntime.jsx)(_VideoSearchList.default, {
223
+ translations: translations,
224
+ selectedType: source.toLowerCase(),
225
+ selectedVideo: selectedVideo,
226
+ videos: videos,
227
+ locale: locale,
228
+ onVideoPreview: this.onVideoPreview,
264
229
  searching: searching,
265
- translations: translations
266
- }), (0, _jsxRuntime.jsx)(_VideoTabs.default, {
267
- searchTypes: selectedType,
268
- tabs: searchListTabs,
269
- onSearchTypeChange: this.onSearchTypeChange
270
- }), paginationItem()]
271
- }));
272
- }
273
- }]);
274
- return VideoSearch;
275
- }(_react.Component);
230
+ onSelectVideo: this.onSelectVideo
231
+ })
232
+ })
233
+ }));
234
+ return (0, _jsxRuntime.jsxs)("div", {
235
+ ...classes(),
236
+ children: [(0, _jsxRuntime.jsx)(_VideoSearchForm.default, {
237
+ onSearchQuerySubmit: this.submitVideoSearchQuery,
238
+ query: query,
239
+ searching: searching,
240
+ translations: translations
241
+ }), (0, _jsxRuntime.jsx)(_VideoTabs.default, {
242
+ searchTypes: selectedType,
243
+ tabs: searchListTabs,
244
+ onSearchTypeChange: this.onSearchTypeChange
245
+ }), paginationItem()]
246
+ });
247
+ }
248
+ }
276
249
  VideoSearch.propTypes = {
277
250
  onVideoSelect: _propTypes.default.func.isRequired,
278
251
  searchVideos: _propTypes.default.func.isRequired,
@@ -288,5 +261,4 @@ VideoSearch.propTypes = {
288
261
  VideoSearch.defaultProps = {
289
262
  enabledSources: ['Brightcove']
290
263
  };
291
- var _default = VideoSearch;
292
- exports.default = _default;
264
+ var _default = exports.default = VideoSearch;