@@ -954,28 +954,42 @@ var lib_1 = __webpack_require__(15);
954
954
var React = __webpack_require__(4);
955
955
var ReactDOM = __webpack_require__(19);
956
956
// feel free to change these :)
957
- var suggestions = ["stop it", "nice one", "look up ", "no", "bad "];
957
+ var suggestions = ["watching", "quiz", " stop it", "nice one", "learn ", "no", "read", "work "];
958
958
var ExampleApp = /** @class */ (function (_super) {
959
959
__extends(ExampleApp, _super);
960
960
function ExampleApp(props) {
961
961
var _this = _super.call(this, props) || this;
962
962
_this.state = {
963
- apiKey: ""
963
+ apiKey: "",
964
+ isKeySubmitted: false
964
965
};
965
966
_this.onKeyChange = _this.onKeyChange.bind(_this);
967
+ _this.onKeySubmit = _this.onKeySubmit.bind(_this);
968
+ _this.onGifSelected = _this.onGifSelected.bind(_this);
966
969
return _this;
967
970
}
968
971
ExampleApp.prototype.onKeyChange = function (event) {
969
972
this.setState({ apiKey: event.target.value });
970
973
};
974
+ ExampleApp.prototype.onKeySubmit = function (event) {
975
+ event.preventDefault();
976
+ this.setState({
977
+ isKeySubmitted: true
978
+ });
979
+ };
980
+ ExampleApp.prototype.onGifSelected = function (gifObject) {
981
+ console.dir(gifObject);
982
+ };
971
983
ExampleApp.prototype.render = function () {
972
- var apiKey = this.state.apiKey;
984
+ var _a = this.state, apiKey = _a .apiKey, isKeySubmitted = _a.isKeySubmitted ;
973
985
var suggestions = this.props.suggestions;
986
+ if (!isKeySubmitted) {
987
+ return (React.createElement("form", { onSubmit: this.onKeySubmit },
988
+ React.createElement("input", { type: "text", placeholder: "Enter your Giphy API Key", value: apiKey, onChange: this.onKeyChange }),
989
+ React.createElement("button", { type: "submit" }, "Set API Key")));
990
+ }
974
991
return (React.createElement("div", null,
975
- React.createElement("div", null,
976
- React.createElement("input", { type: "text", placeholder: "Enter your Giphy API Key", value: apiKey, onChange: this.onKeyChange })),
977
- React.createElement("div", null,
978
- React.createElement(lib_1.Selector, { apiKey: apiKey, suggestions: suggestions }))));
992
+ React.createElement(lib_1.Selector, { apiKey: apiKey, suggestions: suggestions, onGifSelected: this.onGifSelected })));
979
993
};
980
994
return ExampleApp;
981
995
}(React.Component));
@@ -18764,6 +18778,7 @@ var types_1 = __webpack_require__(16);
18764
18778
var GiphyClient_1 = __webpack_require__(17);
18765
18779
var SearchInput_1 = __webpack_require__(33);
18766
18780
var Suggestions_1 = __webpack_require__(34);
18781
+ var SearchResults_1 = __webpack_require__(36);
18767
18782
var Selector = /** @class */ (function (_super) {
18768
18783
__extends(Selector, _super);
18769
18784
function Selector(props) {
@@ -18787,9 +18802,9 @@ var Selector = /** @class */ (function (_super) {
18787
18802
* search
18788
18803
* @param q string
18789
18804
*/
18790
- Selector.prototype.onQueryChange = function (q) {
18805
+ Selector.prototype.onQueryChange = function (q, cb ) {
18791
18806
// Update the query
18792
- this.setState({ query: q });
18807
+ this.setState({ query: q }, cb );
18793
18808
};
18794
18809
/**
18795
18810
* Fired when the query should be executed
@@ -18827,20 +18842,24 @@ var Selector = /** @class */ (function (_super) {
18827
18842
* Fired when a suggestion has been selected
18828
18843
*/
18829
18844
Selector.prototype.onSuggestionSelected = function (q) {
18830
- this.onQueryChange(q);
18831
- this.onQueryExecute();
18845
+ var _this = this;
18846
+ this.onQueryChange(q, function () {
18847
+ _this.onQueryExecute();
18848
+ });
18832
18849
};
18833
18850
Selector.prototype.render = function () {
18834
18851
var _a = this.state, query = _a.query, searchResult = _a.searchResult, isPending = _a.isPending, searchError = _a.searchError;
18835
- var suggestions = this.props.suggestions;
18852
+ var _b = this.props, suggestions = _b .suggestions, onGifSelected = _b.onGifSelected ;
18836
18853
var showSuggestions = !!suggestions.length && !searchResult && !isPending && !searchError;
18837
18854
return (React.createElement("div", null,
18838
18855
React.createElement(SearchInput_1.SearchInput, { onQueryChange: this.onQueryChange, onQueryExecute: this.onQueryExecute, queryValue: query }),
18839
18856
showSuggestions && (React.createElement(Suggestions_1.Suggestions, { suggestions: suggestions, onSuggestionSelected: this.onSuggestionSelected })),
18840
18857
isPending && React.createElement("div", null, "Loading"),
18841
18858
!isPending && !!searchError && React.createElement("div", null,
18842
18859
"Error: ",
18843
- searchError.message)));
18860
+ searchError.message),
18861
+ !isPending &&
18862
+ !!searchResult && (React.createElement(SearchResults_1.SearchResults, { gifObjects: searchResult.gifObjects, onGifSelected: onGifSelected }))));
18844
18863
};
18845
18864
Selector.defaultProps = {
18846
18865
rating: types_1.Rating.G,
@@ -20375,17 +20394,7 @@ var GiphyClient = /** @class */ (function () {
20375
20394
*/
20376
20395
GiphyClient.prototype.searchGifs = function (params) {
20377
20396
return this.client.search("gifs", params).then(function (response) {
20378
- return response.data.map(function (rawGifObject) {
20379
- return {
20380
- id: rawGifObject.id,
20381
- slug: rawGifObject.slug,
20382
- url: rawGifObject.url,
20383
- embedUrl: rawGifObject.embed_url,
20384
- source: rawGifObject.source,
20385
- rating: rawGifObject.rating,
20386
- title: rawGifObject.title
20387
- };
20388
- });
20397
+ return { gifObjects: response.data };
20389
20398
});
20390
20399
};
20391
20400
return GiphyClient;
@@ -22955,14 +22964,93 @@ var Suggestion = /** @class */ (function (_super) {
22955
22964
this.props.onSelected(this.props.suggestion);
22956
22965
};
22957
22966
Suggestion.prototype.render = function () {
22958
- var _a = this.props, suggestion = _a .suggestion, onSelected = _a.onSelected ;
22959
- return React.createElement("a", { href: "javascript:void(0)", onClick: this.onClick }, suggestion);
22967
+ var suggestion = this.props.suggestion;
22968
+ return ( React.createElement("a", { href: "javascript:void(0)", onClick: this.onClick }, suggestion) );
22960
22969
};
22961
22970
return Suggestion;
22962
22971
}(React.Component));
22963
22972
exports.Suggestion = Suggestion;
22964
22973
22965
22974
22975
+ /***/ }),
22976
+ /* 36 */
22977
+ /***/ (function(module, exports, __webpack_require__) {
22978
+
22979
+ "use strict";
22980
+
22981
+ var __extends = (this && this.__extends) || (function () {
22982
+ var extendStatics = Object.setPrototypeOf ||
22983
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22984
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
22985
+ return function (d, b) {
22986
+ extendStatics(d, b);
22987
+ function __() { this.constructor = d; }
22988
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22989
+ };
22990
+ })();
22991
+ Object.defineProperty(exports, "__esModule", { value: true });
22992
+ var React = __webpack_require__(1);
22993
+ var SearchResult_1 = __webpack_require__(37);
22994
+ var SearchResults = /** @class */ (function (_super) {
22995
+ __extends(SearchResults, _super);
22996
+ function SearchResults(props) {
22997
+ return _super.call(this, props) || this;
22998
+ }
22999
+ SearchResults.prototype.render = function () {
23000
+ var _a = this.props, gifObjects = _a.gifObjects, onGifSelected = _a.onGifSelected;
23001
+ return (React.createElement("div", null, gifObjects.map(function (gifObject) { return (React.createElement(SearchResult_1.SearchResult, { key: gifObject.id, gifObject: gifObject, onSelected: onGifSelected })); })));
23002
+ };
23003
+ return SearchResults;
23004
+ }(React.Component));
23005
+ exports.SearchResults = SearchResults;
23006
+
23007
+
23008
+ /***/ }),
23009
+ /* 37 */
23010
+ /***/ (function(module, exports, __webpack_require__) {
23011
+
23012
+ "use strict";
23013
+
23014
+ var __extends = (this && this.__extends) || (function () {
23015
+ var extendStatics = Object.setPrototypeOf ||
23016
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23017
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
23018
+ return function (d, b) {
23019
+ extendStatics(d, b);
23020
+ function __() { this.constructor = d; }
23021
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
23022
+ };
23023
+ })();
23024
+ Object.defineProperty(exports, "__esModule", { value: true });
23025
+ var React = __webpack_require__(1);
23026
+ var SearchResult = /** @class */ (function (_super) {
23027
+ __extends(SearchResult, _super);
23028
+ function SearchResult(props) {
23029
+ var _this = _super.call(this, props) || this;
23030
+ _this.onClick = _this.onClick.bind(_this);
23031
+ return _this;
23032
+ }
23033
+ SearchResult.prototype.onClick = function (event) {
23034
+ event.preventDefault();
23035
+ this.props.onSelected(this.props.gifObject);
23036
+ };
23037
+ SearchResult.prototype.render = function () {
23038
+ var gifObject = this.props.gifObject;
23039
+ console.dir(gifObject);
23040
+ var sourceImage = gifObject.images.fixed_height_small;
23041
+ var style = {
23042
+ width: sourceImage.width + "px",
23043
+ height: sourceImage.height + "px",
23044
+ background: "url(" + sourceImage.gif_url + ")",
23045
+ display: "block"
23046
+ };
23047
+ return React.createElement("a", { href: "javascript:void(0)", onClick: this.onClick, style: style });
23048
+ };
23049
+ return SearchResult;
23050
+ }(React.Component));
23051
+ exports.SearchResult = SearchResult;
23052
+
23053
+
22966
23054
/***/ })
22967
23055
/******/ ]);
22968
23056
});
0 commit comments