Ajout d'un bouton pour réinitialiser le simulateur
parent
9ae2851d27
commit
7c42df7b06
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
<div id="sim" className={classNames({started})}>
|
||||
|
@ -94,6 +101,12 @@ export default class extends React.Component {
|
|||
<div id="questions-answers">
|
||||
{ !R.isEmpty(foldedSteps) &&
|
||||
<div id="foldedSteps">
|
||||
<div id="reinitialise" >
|
||||
<button onClick={reinitalise}>
|
||||
<i className="fa fa-trash" aria-hidden="true"></i>
|
||||
Tout effacer
|
||||
</button>
|
||||
</div>
|
||||
{foldedSteps
|
||||
.map(step => (
|
||||
<step.component
|
||||
|
|
|
@ -25,6 +25,7 @@ export let reduceSteps = (state, action) => {
|
|||
if (action.type == START_CONVERSATION) {
|
||||
return {
|
||||
...returnObject,
|
||||
foldedSteps: [],
|
||||
unfoldedSteps: buildNextSteps(returnObject.analysedSituation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
Loading…
Reference in New Issue