Displaying tweets
This commit is contained in:
parent
9989d0a5ba
commit
6759a05743
8 changed files with 552 additions and 44 deletions
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
// )
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue