diff --git a/dist/index.cjs.js b/dist/index.cjs.js index cd5a09e..68c2ed3 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -194,6 +194,14 @@ var UnsplashWrapper = function () { return _this2.unsplash.search.photos(search, page, perPage).then(_this2.processResponse); }; + this.getPhoto = function (id) { + var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + width = _ref2.width, + height = _ref2.height; + + return _this2.unsplash.photos.getPhoto(id, width, height).then(_this2.processResponse); + }; + this.downloadPhoto = function (photo) { return _this2.unsplash.photos.downloadPhoto(photo).then(_this2.processResponse); }; @@ -857,9 +865,17 @@ var UnsplashPicker = function (_React$Component) { _this.downloadPhoto = function (photo) { _this.setState({ loadingPhoto: photo }); - return _this.state.unsplash.downloadPhoto(photo).then(function (r) { + var preferredSize = _this.props.preferredSize; + + var download = _this.state.unsplash.downloadPhoto(photo); + + var downloadPromise = preferredSize ? _this.state.unsplash.getPhoto(photo.id, preferredSize).then(function (r) { + return r.urls.custom; + }) : download.then(function (r) { return r.url; - }).then(fetch).catch(function (e) { + }); + + return downloadPromise.then(fetch).catch(function (e) { return _this.setState({ error: e.message, isLoadingSearch: false }); }); }; @@ -1124,6 +1140,10 @@ UnsplashPicker.propTypes = { highlightColor: string$8, onFinishedUploading: func$5, defaultSearch: string$8, + preferredSize: shape$4({ + width: number$3.isRequired, + height: number$3.isRequired + }), __debug_chaosMonkey: bool }; UnsplashPicker.defaultProps = { @@ -1134,6 +1154,7 @@ UnsplashPicker.defaultProps = { highlightColor: "#00adf0", onFinishedUploading: noop, defaultSearch: "", + preferredSize: null, __debug_chaosMonkey: false }; diff --git a/dist/index.esm.js b/dist/index.esm.js index d71320d..4767490 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -188,6 +188,14 @@ var UnsplashWrapper = function () { return _this2.unsplash.search.photos(search, page, perPage).then(_this2.processResponse); }; + this.getPhoto = function (id) { + var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + width = _ref2.width, + height = _ref2.height; + + return _this2.unsplash.photos.getPhoto(id, width, height).then(_this2.processResponse); + }; + this.downloadPhoto = function (photo) { return _this2.unsplash.photos.downloadPhoto(photo).then(_this2.processResponse); }; @@ -851,9 +859,17 @@ var UnsplashPicker = function (_React$Component) { _this.downloadPhoto = function (photo) { _this.setState({ loadingPhoto: photo }); - return _this.state.unsplash.downloadPhoto(photo).then(function (r) { + var preferredSize = _this.props.preferredSize; + + var download = _this.state.unsplash.downloadPhoto(photo); + + var downloadPromise = preferredSize ? _this.state.unsplash.getPhoto(photo.id, preferredSize).then(function (r) { + return r.urls.custom; + }) : download.then(function (r) { return r.url; - }).then(fetch).catch(function (e) { + }); + + return downloadPromise.then(fetch).catch(function (e) { return _this.setState({ error: e.message, isLoadingSearch: false }); }); }; @@ -1118,6 +1134,10 @@ UnsplashPicker.propTypes = { highlightColor: string$8, onFinishedUploading: func$5, defaultSearch: string$8, + preferredSize: shape$4({ + width: number$3.isRequired, + height: number$3.isRequired + }), __debug_chaosMonkey: bool }; UnsplashPicker.defaultProps = { @@ -1128,6 +1148,7 @@ UnsplashPicker.defaultProps = { highlightColor: "#00adf0", onFinishedUploading: noop, defaultSearch: "", + preferredSize: null, __debug_chaosMonkey: false }; diff --git a/dist/index.umd.js b/dist/index.umd.js index 0b4d40f..5821890 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -2857,6 +2857,14 @@ return _this2.unsplash.search.photos(search, page, perPage).then(_this2.processResponse); }; + this.getPhoto = function (id) { + var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + width = _ref2.width, + height = _ref2.height; + + return _this2.unsplash.photos.getPhoto(id, width, height).then(_this2.processResponse); + }; + this.downloadPhoto = function (photo) { return _this2.unsplash.photos.downloadPhoto(photo).then(_this2.processResponse); }; @@ -4337,9 +4345,17 @@ _this.downloadPhoto = function (photo) { _this.setState({ loadingPhoto: photo }); - return _this.state.unsplash.downloadPhoto(photo).then(function (r) { + var preferredSize = _this.props.preferredSize; + + var download = _this.state.unsplash.downloadPhoto(photo); + + var downloadPromise = preferredSize ? _this.state.unsplash.getPhoto(photo.id, preferredSize).then(function (r) { + return r.urls.custom; + }) : download.then(function (r) { return r.url; - }).then(fetch).catch(function (e) { + }); + + return downloadPromise.then(fetch).catch(function (e) { return _this.setState({ error: e.message, isLoadingSearch: false }); }); }; @@ -4604,6 +4620,10 @@ highlightColor: string$8, onFinishedUploading: func$5, defaultSearch: string$8, + preferredSize: shape$4({ + width: number$3.isRequired, + height: number$3.isRequired + }), __debug_chaosMonkey: bool }; UnsplashPicker.defaultProps = { @@ -4614,6 +4634,7 @@ highlightColor: "#00adf0", onFinishedUploading: noop, defaultSearch: "", + preferredSize: null, __debug_chaosMonkey: false }; diff --git a/package.json b/package.json index 7333260..b4b2e5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unsplash-react", - "version": "0.1.4", + "version": "0.1.5", "description": "Upload images from unsplash into your app", "source": "src/index.js", "main": "dist/index.cjs.js",