import { connect } from 'react-redux' ; import Redux from 'redux' ; import { Quest } from 'shared/schema/Quests' ; import { toPrevious } from '../../actions/Card' ; import { setDialog } from '../../actions/Dialog' ; import { multiplayerDisconnect } from '../../actions/Multiplayer' ; import { exitQuest } from '../../actions/Quest' ; import { deleteSavedQuest } from '../../actions/SavedQuests' ; import { changeSettings } from '../../actions/Settings' ; import { openSnackbar } from '../../actions/Snackbar' ; import { fetchQuestXML , submitUserFeedback } from '../../actions/Web' ; import { MIN_FEEDBACK_LENGTH } from '../../Constants' ; import { getCounters } from '../../multiplayer/Counters' ; import { AppState , CardName , ContentSetsType , FeedbackType , QuestState , SavedQuestMeta , SettingsType , UserState } from '../../reducers/StateTypes' ; import { ParserNode } from '../views/quest/cardtemplates/TemplateTypes' ; import Dialogs , { DispatchProps , StateProps } from './Dialogs' ; const mapStateToProps = ( state ) : StateProps => { return { dialog : state . dialog , multiplayer : state . multiplayer , multiplayerStats : getCounters ( ) , quest : state . quest || { details : { } } as any , selectedSave : ( state . quest && state . quest . savedTS ) ? { details : state . quest . details , ts : state . quest . savedTS } : null , settings : state . settings , user : state . user , } ; } ; function validateFeedback ( text ) { if ( ! text ) { return new Error ( 'Please enter a description so that we can help resolve the issue.' ) ; } if ( text . length < MIN_FEEDBACK_LENGTH ) { return new Error ( 'Issue description must be at least ' + MIN_FEEDBACK_LENGTH + ' characters to provide value.' ) ; } return null ; } export const mapDispatchToProps = ( dispatch ) : DispatchProps => { return { onClose : ( ) => { dispatch ( setDialog ( null ) ) ; } , onDeleteSavedQuest : ( savedQuest ) => { dispatch ( deleteSavedQuest ( savedQuest . details . id , savedQuest . ts ) ) ; dispatch ( setDialog ( null ) ) ; dispatch ( openSnackbar ( 'Save deleted.' ) ) ; } , onExitMultiplayer : ( ) => { dispatch ( multiplayerDisconnect ( ) ) ; dispatch ( setDialog ( null ) ) ; dispatch ( toPrevious ( { matchFn : ( c , n ) => c === 'SPLASH_CARD' , before : false } ) ) ; } , onExitQuest : ( quest , settings , user , text ) : Promise < any > => { dispatch ( setDialog ( null ) ) ; dispatch ( exitQuest ( { } ) ) ; dispatch ( toPrevious ( { matchFn : ( c , n ) => c === 'SPLASH_CARD' , before : false } ) ) ; if ( text && text . length > 0 ) { return dispatch ( submitUserFeedback ( { quest , settings , user , text , type : 'feedback' , anonymous : false , rating : null } ) ) as any ; } return Promise . resolve ( ) ; } , onExpansionSelect : ( contentSets , close = true ) => { if ( close ) { dispatch ( setDialog ( null ) ) ; } dispatch ( changeSettings ( { contentSets } ) ) ; } , onFeedbackSubmit : ( type , quest , settings , user , text ) => { const err = validateFeedback ( text ) ; if ( err ) { return alert ( err . toString ( ) ) ; } dispatch ( submitUserFeedback ( { quest , settings , user , text , type , anonymous : false , rating : null } ) ) ; dispatch ( setDialog ( null ) ) ; } , onMultitouchChange : ( v ) => { dispatch ( changeSettings ( { multitouch : v } ) ) ; } , onPlayerChange : ( numLocalPlayers ) => { dispatch ( changeSettings ( { numLocalPlayers } ) ) ; } , playQuest : ( details ) => { dispatch ( setDialog ( null ) ) ; dispatch ( fetchQuestXML ( { details } ) ) ; } , } ; } ; const DialogsContainer = connect ( mapStateToProps , mapDispatchToProps ) ( Dialogs ) ; export default DialogsContainer ;