From c204e8cdea3b2fe5575d6ea4800c8d8544eb24fe Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Fri, 8 Jul 2016 12:06:02 -0700 Subject: [PATCH] Feature(toasts): make toast short lived by default --- common/app/redux/actions.js | 14 ---------- .../components/classic/Tool-Panel.jsx | 6 +++-- .../routes/challenges/redux/answer-saga.js | 5 +++- .../challenges/redux/completion-saga.js | 27 ++++++------------- common/app/toasts/redux/actions.js | 2 +- 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/common/app/redux/actions.js b/common/app/redux/actions.js index 4be119253c..aa9942a113 100644 --- a/common/app/redux/actions.js +++ b/common/app/redux/actions.js @@ -5,20 +5,6 @@ import types from './types'; // updateTitle(title: String) => Action export const updateTitle = createAction(types.updateTitle); -let id = 0; -// makeToast({ type?: String, message: String, title: String }) => Action -export const makeToast = createAction( - types.makeToast, - toast => { - id += 1; - return { - ...toast, - id, - type: toast.type || 'info' - }; - } -); - // fetchUser() => Action // used in combination with fetch-user-saga export const fetchUser = createAction(types.fetchUser); diff --git a/common/app/routes/challenges/components/classic/Tool-Panel.jsx b/common/app/routes/challenges/components/classic/Tool-Panel.jsx index ebfe66fdb7..27883ba235 100644 --- a/common/app/routes/challenges/components/classic/Tool-Panel.jsx +++ b/common/app/routes/challenges/components/classic/Tool-Panel.jsx @@ -18,7 +18,8 @@ export default class ToolPanel extends PureComponent { makeHint() { this.props.makeToast({ - message: this.props.hint + message: this.props.hint, + timeout: 4000 }); this.props.updateHint(); } @@ -27,7 +28,8 @@ export default class ToolPanel extends PureComponent { this.props.makeToast({ message: 'This will restore your code editor to its original state.', action: 'clear my code', - actionCreator: 'resetChallenge' + actionCreator: 'resetChallenge', + timeout: 4000 }); } diff --git a/common/app/routes/challenges/redux/answer-saga.js b/common/app/routes/challenges/redux/answer-saga.js index def66ecb90..f5bb4aece6 100644 --- a/common/app/routes/challenges/redux/answer-saga.js +++ b/common/app/routes/challenges/redux/answer-saga.js @@ -55,7 +55,10 @@ export default function answerSaga(action$, getState) { if (answer !== finalAnswer) { let infoAction; if (info) { - infoAction = makeToast({ message: info }); + infoAction = makeToast({ + message: info, + timeout: 5000 + }); } return Observable diff --git a/common/app/routes/challenges/redux/completion-saga.js b/common/app/routes/challenges/redux/completion-saga.js index e90368fdcc..ba92539232 100644 --- a/common/app/routes/challenges/redux/completion-saga.js +++ b/common/app/routes/challenges/redux/completion-saga.js @@ -9,28 +9,18 @@ import { import { makeToast } from '../../../toasts/redux/actions'; import { challengeSelector } from './selectors'; -import { backEndProject } from '../../../utils/challengeTypes'; import { randomCompliment } from '../../../utils/get-words'; +import { backEndProject } from '../../../utils/challengeTypes'; import { postJSON$ } from '../../../../utils/ajax-stream'; function postChallenge(url, body, username) { const saveChallenge$ = postJSON$(url, body) .retry(3) - .flatMap(({ alreadyCompleted, points }) => { - return Observable.of( - makeToast({ - message: randomCompliment() + - (alreadyCompleted ? '!' : '! First time Completed!') - }), - updateUserPoints(username, points) - ); + .map(({ points }) => { + return updateUserPoints(username, points); }) .catch(createErrorObservable); - - const challengeCompleted$ = Observable.of( - moveToNextChallenge(), - username ? makeToast({ message: ' Saving...' }) : null - ); + const challengeCompleted$ = Observable.of(moveToNextChallenge()); return Observable.merge(saveChallenge$, challengeCompleted$); } @@ -40,9 +30,10 @@ function submitModern(type, state) { if (type === types.checkChallenge) { return Observable.of( makeToast({ - message: 'Go to my next challenge.', + message: `${randomCompliment()} Go to next challenge.`, action: 'Submit', - actionCreator: 'submitChallenge' + actionCreator: 'submitChallenge', + timeout: 10000 }) ); } @@ -61,9 +52,7 @@ function submitModern(type, state) { return postChallenge('/modern-challenge-completed', body, user); } } - return Observable.just(makeToast({ - message: 'Not all tests are passing, yet.' - })); + return Observable.just(makeToast({ message: 'Not quite there, yet.' })); } function submitProject(type, state, { solution, githubLink }) { diff --git a/common/app/toasts/redux/actions.js b/common/app/toasts/redux/actions.js index bb8a257720..ec13f62797 100644 --- a/common/app/toasts/redux/actions.js +++ b/common/app/toasts/redux/actions.js @@ -9,7 +9,7 @@ export const makeToast = createAction( // assign current value of key to new toast // and then increment key value key: key++, - dismissAfter: timeout || 10000, + dismissAfter: timeout || 2000, position: rest.position === 'left' ? 'left' : 'right' }) );