From be87ccd8782db2e1237b3343818b1c01333639f0 Mon Sep 17 00:00:00 2001 From: Wylkon Cardoso Date: Thu, 3 Oct 2019 23:32:00 -0300 Subject: [PATCH 1/2] fix lint --- src/HandleAPICalls/saga.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/HandleAPICalls/saga.js b/src/HandleAPICalls/saga.js index dfe585b..fd493b5 100644 --- a/src/HandleAPICalls/saga.js +++ b/src/HandleAPICalls/saga.js @@ -3,10 +3,8 @@ import { takeEvery, call } from 'redux-saga/effects'; import { toastr } from 'react-redux-toastr'; import { HANDLE_API_CALLS } from './constants'; - // function that makes the api request and returns a Promise for response function callToAPI(method, url, data) { - // console.log(params); return axios({ method, url, @@ -17,11 +15,17 @@ function callToAPI(method, url, data) { // worker saga: makes the api call when watcher saga sees the action function* handleAPICalls(action) { try { - const response = yield call(callToAPI, action.method, action.url, action.body); + const response = yield call( + callToAPI, + action.method, + action.url, + action.body + ); if (action.handleSuccess) { yield call(action.handleSuccess, response.data); } } catch (err) { + // eslint-disable-next-line no-console console.log(err); if (!action.showToast) { toastr.error('ERROR', 'Failed to request'); @@ -38,8 +42,6 @@ function* callToAPIWatcher() { } /* eslint-disable */ -export { - callToAPIWatcher, -}; +export { callToAPIWatcher }; /* eslint-enable */ From 3da730790dfbd833e639274cf48e4ca839fc2311 Mon Sep 17 00:00:00 2001 From: Wylkon Cardoso Date: Thu, 3 Oct 2019 23:32:28 -0300 Subject: [PATCH 2/2] changed api and integrated with content --- src/RandomQuote/container.jsx | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/RandomQuote/container.jsx b/src/RandomQuote/container.jsx index def40a7..4632b92 100644 --- a/src/RandomQuote/container.jsx +++ b/src/RandomQuote/container.jsx @@ -15,35 +15,20 @@ class RamdomQuoteContainer extends Component { this.props.clearQuote(); this.props.getDataFromAPI( - 'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=', + 'https://api.quotable.io/random', 'GET', - undefined, - (response) => { - // set the quote in state - const dataObject = response[0]; - /** - * refer here for more about this regex: - * https://stackoverflow.com/questions/1499889/remove-html-tags-in-javascript-with-regex - */ - const filterHTMLRegex = /(<([^>]+)>)/ig; - const author = dataObject.title; - const quote = unescape(dataObject.content.replace(filterHTMLRegex, '')).replace(/\r?\n|\r/g, ''); - - this.props.setQuote(quote, author); + { per_page: 1, orderby: 'rand' }, + ({ author, content }) => { + this.props.setQuote(content, author); this.props.disableButton(false); - }, - err => console.log(err), + } + // err => console.log(err), ); } render() { const quote = this.props.quote; - return ( - - ); + return ; } }