From 7c42df7b06da8279401816039c9cfd80c58c77df Mon Sep 17 00:00:00 2001 From: mama Date: Tue, 2 May 2017 17:24:28 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20bouton=20pour=20r=C3=A9initialis?= =?UTF-8?q?er=20le=20simulateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/Simulateur.css | 14 +++++ source/components/Simulateur.js | 17 +++++- source/engine/generateQuestions.js | 1 + source/reducers-conversation.js | 97 ------------------------------ 4 files changed, 30 insertions(+), 99 deletions(-) delete mode 100644 source/reducers-conversation.js diff --git a/source/components/Simulateur.css b/source/components/Simulateur.css index ce792d98d..06e834de9 100644 --- a/source/components/Simulateur.css +++ b/source/components/Simulateur.css @@ -95,3 +95,17 @@ box-shadow: none; opacity: .95; } + +#reinitialise { + margin-bottom: 1em; + text-align: center; +} +#reinitialise button { + font-size: 80%; + color: #4A89DC; + border: none; +} +#reinitialise button i { + margin-right: .3em; + vertical-align: top +} diff --git a/source/components/Simulateur.js b/source/components/Simulateur.js index d311e5aa1..c3bafcfde 100644 --- a/source/components/Simulateur.js +++ b/source/components/Simulateur.js @@ -1,6 +1,6 @@ import React, {Component} from 'react' import './CDD.css' -import {reduxForm, formValueSelector} from 'redux-form' +import {reduxForm, formValueSelector, reset} from 'redux-form' import {connect} from 'react-redux' import './conversation/conversation.css' import {START_CONVERSATION} from '../actions' @@ -26,6 +26,7 @@ let situationSelector = formValueSelector('conversation') }), dispatch => ({ startConversation: rootVariable => dispatch({type: START_CONVERSATION, rootVariable}), + resetForm: rootVariable => dispatch(reset('conversation')) }) ) export default class extends React.Component { @@ -52,7 +53,13 @@ export default class extends React.Component { started = !this.props.match.params.intro, {foldedSteps, unfoldedSteps, situation} = this.props, sim = path => - R.path(R.unless(R.is(Array), R.of)(path))(this.simulateur) + R.path(R.unless(R.is(Array), R.of)(path))(this.simulateur), + objectif = this.simulateur.objectif, + reinitalise = () => { + this.props.resetForm(objectif); + this.props.startConversation(objectif); + } + return (
@@ -94,6 +101,12 @@ export default class extends React.Component {
{ !R.isEmpty(foldedSteps) &&
+
+ +
{foldedSteps .map(step => ( { if (action.type == START_CONVERSATION) { return { ...returnObject, + foldedSteps: [], unfoldedSteps: buildNextSteps(returnObject.analysedSituation) } } diff --git a/source/reducers-conversation.js b/source/reducers-conversation.js deleted file mode 100644 index ce47955bc..000000000 --- a/source/reducers-conversation.js +++ /dev/null @@ -1,97 +0,0 @@ -import { combineReducers } from 'redux' -import {reducer as formReducer} from 'redux-form' - -import { SUBMIT_STEP, EDIT_STEP, UNSUBMIT_ALL} from './actions' -import { - SIMULATION_UPDATE_REQUEST, SIMULATION_UPDATE_SUCCESS, - TOGGLE_TOP_SECTION, TOGGLE_ADVANCED_SECTION, -} from './actions' -import computeThemeColours from './themeColours' -import {change} from 'redux-form' - -function steps(state = new Map(), {type, name, ignored}) { - switch (type) { - case SUBMIT_STEP: - return new Map([ ...state ]).set( - name, - ignored ? 'ignored' : 'filled' - ) - case EDIT_STEP: - return new Map([ ...state ]).set( - name, - 'editing' - ) - case UNSUBMIT_ALL: - return new Map() - default: - return state - } -} - -function pending(state = false, action) { - switch (action.type) { - case SIMULATION_UPDATE_REQUEST: - return true - case SIMULATION_UPDATE_SUCCESS: - return false - default: - return state - } -} - -function results(state = {}, {type, results}) { - switch (type) { - case SIMULATION_UPDATE_SUCCESS: - return results.values - default: - return state - } -} - -function activeSections(state = {top: 'input', advanced: false}, {type}) { - switch (type) { - // What is the active top section, input or details ? - case TOGGLE_TOP_SECTION: - return Object.assign({}, state, {top: state.top === 'input' ? 'details' : 'input' }) - // Is the advanced input active ? - case TOGGLE_ADVANCED_SECTION: - return Object.assign({}, state, {advanced: !state.advanced}) - default: - return state - } -} - -function inputChanged(state = false, {type}) { - switch(type) { - case change().type: - return true - default: - return state - } -} - -function themeColours(state = computeThemeColours(), {type, colour}) { - if (type == 'CHANGE_THEME_COLOUR') - return computeThemeColours(colour) - else return state -} - -export default combineReducers({ - // this is handled by redux-form, pas touche ! - form: formReducer, - - /* Have forms been filled or ignored ? - false means the user is reconsidering its previous input */ - steps, - - // Is an (advanced simulation) request pending ? - pending, - results, - - activeSections, - - // Has the user edited one form field ? - inputChanged, - - themeColours, -})