Skip to content

Commit

Permalink
97 - Handling our New List View Response
Browse files Browse the repository at this point in the history
  • Loading branch information
CFE committed Jan 13, 2020
1 parent 49dd370 commit 2a6f010
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tweetme2-web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<noscript>You need to enable JavaScript to run this app.</noscript>

<div id='tweet-container'></div>
<div id="tweetme-2" data-username="cfe" data-can-tweet="false"></div>
<div id="tweetme-2" data-username="justin" data-can-tweet="false"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
10 changes: 7 additions & 3 deletions tweetme2-web/src/tweets/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Tweet} from './detail'
export function TweetsList(props) {
const [tweetsInit, setTweetsInit] = useState([])
const [tweets, setTweets] = useState([])
const [nextUrl, setNextUrl] = useState(null)
const [tweetsDidSet, setTweetsDidSet] = useState(false)
useEffect(()=>{
const final = [...props.newTweets].concat(tweetsInit)
Expand All @@ -19,7 +20,8 @@ export function TweetsList(props) {
if (tweetsDidSet === false){
const handleTweetListLookup = (response, status) => {
if (status === 200){
setTweetsInit(response)
setNextUrl(response.next)
setTweetsInit(response.results)
setTweetsDidSet(true)
} else {
alert("There was an error")
Expand All @@ -38,13 +40,15 @@ export function TweetsList(props) {
updateFinalTweets.unshift(tweets)
setTweets(updateFinalTweets)
}
return tweets.map((item, index)=>{
return <React.Fragment>{tweets.map((item, index)=>{
return <Tweet
tweet={item}
didRetweet={handleDidRetweet}
className='my-5 py-5 border bg-white text-dark'
key={`${index}-{item.id}`} />
})
})}
{ nextUrl !== null && <button className='btn btn-outline-primary'>Load next</button>}
</React.Fragment>
}


0 comments on commit 2a6f010

Please sign in to comment.