Skip to content

Commit

Permalink
6.21 anecdotes, the grand finale
Browse files Browse the repository at this point in the history
  • Loading branch information
robaish committed Jan 7, 2022
1 parent f583c14 commit adee8d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions part6/redux-anecdotes/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"content": "Haste is universal because everyone is in flight from himself.",
"id": "47145",
"votes": 47
"votes": 67
},
{
"content": "Be like water.",
"id": "21149",
"votes": 30
"votes": 46
},
{
"content": "The first 90 percent of the code accounts for the first 90 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
{
"content": "All things must pass.",
"votes": 12,
"votes": 41,
"id": "tqPrIe8"
},
{
Expand Down
1 change: 0 additions & 1 deletion part6/redux-anecdotes/src/reducers/anecdoteReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const voteAnecdote = anecdote => {
return async dispatch => {
const votedAnecdote = {...anecdote, votes: anecdote.votes + 1}
const updatedAnecdote = await anecdoteService.update(votedAnecdote)
console.log(updatedAnecdote)
dispatch({
type: 'VOTE',
data: updatedAnecdote
Expand Down
13 changes: 10 additions & 3 deletions part6/redux-anecdotes/src/reducers/notificationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ const notificationReducer = (state = '', action) => {
}
}

// initialize variable for
let timeoutID

export const setNotification = (notification, seconds) => {
return async dispatch => {
dispatch({
type: 'SET_NOTIFICATION',
notification
})
const milliseconds = seconds * 1000
setTimeout(() => {
// if timeoutID created earlier, clear timeout
if(timeoutID) {
clearTimeout(timeoutID)
}

timeoutID = setTimeout(() => {
dispatch(clearNotification())
}, milliseconds)
}, seconds * 1000)
}
}

Expand Down

0 comments on commit adee8d0

Please sign in to comment.