Displaying tweets

This commit is contained in:
Rodrigo Pedroso 2019-06-21 00:06:42 -04:00
commit 6759a05743
8 changed files with 552 additions and 44 deletions

View file

@ -11,8 +11,9 @@ export class Post extends Component {
return (
<ul className="list-group list-group-flush">
{this.props.articles.map(el => (
<li className="list-group-item" key={el.id}>
{el.title}
<li className="list-group-item" key={el.id_str}>
<p>{el.created_at}</p>
<p>{el.text}</p>
</li>
))}
</ul>

View file

@ -14,7 +14,7 @@ function rootReducer(state = initialState, action) {
else if (action.type === "DATA_LOADED") {
return Object.assign({}, state, {
remoteArticles: state.remoteArticles.concat(action.payload)
remoteArticles: state.remoteArticles.concat(action.payload.message.statuses)
})
}

View file

@ -1,51 +1,24 @@
import { takeEvery, call, put } from "redux-saga/effects"
import { takeEvery, call, put } from 'redux-saga/effects'
export default function* watcherSaga() {
yield takeEvery("DATA_REQUESTED", workerSaga)
yield takeEvery("DATA_REQUESTED", workerSaga)
}
function* workerSaga() {
try {
const payload = yield call(getData)
yield put({ type: "DATA_LOADED", payload })
} catch (e) {
yield put({ type: "API_ERRORED", payload: e })
}
try {
const payload = yield call(getData)
yield put({ type: "DATA_LOADED", payload })
} catch (e) {
yield put({ type: "API_ERRORED", payload: e })
}
}
function getData() {
// const token = 'token'
return fetch("http://localhost:3030/api/twitter?hashtag=tesla").then(res1 =>
res1.json()
)
// let myHeaders = new Headers({
// 'Content-Type': 'text/plain',
// 'Content-Length': content.length.toString(),
// 'X-Custom-Header': 'ProcessThisImmediately',
// Authorization: `OAuth ${token}`
// })
// let heads = {
// authorization: 'OAuth oauth_consumer_key="consumer-key-for-app"',
// oauth_nonce="generated-nonce",
// oauth_signature="generated-signature",
// oauth_signature_method="HMAC-SHA1",
// oauth_timestamp="generated-timestamp",
// oauth_token="access-token-for-authed-user",
// oauth_version="1.0"
// }
// let config = {
// method: 'GET',
// headers: myHeaders,
// }
// let url = 'https://api.twitter.com/1.1/search/tweets.json?q=from%3Atwitterdev&result_type=mixed&count=2'
// return fetch(url, config).then(response => {
// console.log(response)
// return fetch("https://jsonplaceholder.typicode.com/posts").then(response =>
// response.json()
// })
return fetch("https://jsonplaceholder.typicode.com/posts").then(response =>
response.json()
)
// )
}