diff --git a/src/actions/contacts.js b/src/actions/contacts.js index e3cb4be..4af413a 100644 --- a/src/actions/contacts.js +++ b/src/actions/contacts.js @@ -27,3 +27,11 @@ export const addNetworkListToContact = (networkListId, contactId) => { } } } + +export const CURRENT_SORT_CONTACT = 'CURRENT_SORT_CONTACT' +export const currentSortContact = (currentContact) => { + return { + type: CURRENT_SORT_CONTACT, + payload: currentContact + } +} diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index 96b8208..6afc354 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -1,7 +1,7 @@ import React, { PureComponent, PropTypes } from 'react' import { connect } from 'react-redux' import { submit } from 'redux-form' -import { updateContact } from '../../actions/contacts' +import { updateContact, currentSortContact } from '../../actions/contacts' import {formFieldsContactDetails as formFields} from '../../helpers/formData' import Media from 'react-media' import ZeroContacts from './ZeroContacts' @@ -33,6 +33,10 @@ class SortContactContainer extends PureComponent { contacts: PropTypes.array.isRequired, addedContactIds: PropTypes.array.isRequired } + componentWillMount() { + console.log('WILLMOUNT') + this.getOneContact() + } componentDidMount () { window.addEventListener('keydown', this.handleContainerKeyPress) @@ -63,6 +67,7 @@ class SortContactContainer extends PureComponent { return contacts.filter((contact, index) => { return index === contactIndex }) + } onSubmit (values, dispatch, props) { @@ -124,16 +129,9 @@ class SortContactContainer extends PureComponent { ) } - // NOTE i need to create renderHintText function that i will pass to HintFooter which will show different mila hints if a user clicks on next contact. - - // renderHintText() { - // const hints = ['Tip #1: Use keyboard shortcuts to sort contacts faster!', 'Tip #2: Use left and right arrow keys to sort next contact'] - // - // } - render () { const { curContactNumb, totalContacts, completedProgress, snackOpen } = this.state - // if (this.props.contacts === []) return + return (
@@ -168,7 +166,6 @@ class SortContactContainer extends PureComponent { hintText='hint-text'/> )}/> -
) } @@ -177,7 +174,8 @@ class SortContactContainer extends PureComponent { const mapStateToProps = (state) => { return { contacts: state.contacts, - addedContactIds: state.sortContact.addedContactIds + addedContactIds: state.sortContact.addedContactIds, + currentContact: state.sortContact.theOneContact } } diff --git a/src/reducers/contacts.js b/src/reducers/contacts.js index c0661b8..041894d 100644 --- a/src/reducers/contacts.js +++ b/src/reducers/contacts.js @@ -268,7 +268,6 @@ export default function contacts(state = initialState, { type, payload } = {}) { switch (type) { case UPDATE_CONTACT : - return state.map((contact) => { if (contact.id === payload.contactId) { const updatedContactAttributes = payload.contactFields diff --git a/src/reducers/networklists.js b/src/reducers/networklists.js index 3c47952..629db67 100644 --- a/src/reducers/networklists.js +++ b/src/reducers/networklists.js @@ -61,6 +61,7 @@ const networklists = (state = initialState, action) => { // console.log(action.payload, 'networklists action.payload') // const newNetworkList = Object.assign({}, action.payload) // return [newNetworkList].concat(state) + // NOTE: maybe we can use {type, payload} = {} as params return [ ...state, networklist(undefined, action) diff --git a/src/reducers/sortContactReducer.js b/src/reducers/sortContactReducer.js index 01f001f..14abc96 100644 --- a/src/reducers/sortContactReducer.js +++ b/src/reducers/sortContactReducer.js @@ -1,7 +1,9 @@ import { ADD_CONTACT_TO_NETWORKLIST } from '../actions/networklists' +import { CURRENT_SORT_CONTACT } from '../actions/contacts' const initialState = { - addedContactIds: [] + addedContactIds: [], + theOneContact: [] } export default function sortContactReducer(state = initialState, { type, payload } = {}) { @@ -12,6 +14,11 @@ export default function sortContactReducer(state = initialState, { type, payload } return { ...state, addedContactIds: [...state.addedContactIds, payload.contactId] } + case CURRENT_SORT_CONTACT: + // newCurrentContact = Object.assign({}, payload) + // return [newCurrentContact].concat(state) + return {...state, theOneContact: payload} + default: return state