Personal Dashboard

note.js 1.0KB

12345678910111213141516171819202122232425
  1. import { _ } from '../../utils'
  2. import { handleActions } from 'redux-actions'
  3. import { combineReducers } from 'redux'
  4. import * as actions from '../Actions/notes'
  5. const MOCK_NOTES = [
  6. {id: _.uniqueId(), title: 'First note', content: 'This is a little note' },
  7. {id: _.uniqueId(), title: 'Second note', content: '### This is a little md note' },
  8. ]
  9. const selectedNote = handleActions({
  10. [actions.SELECT_NOTE]: (state, action) => state = action.payload,
  11. [actions.UPDATE_SELECTED_NOTE]: (state, action) => ({...state, ...action.payload }),
  12. [actions.UNSELECT_NOTE]: (state, action) => null
  13. }, null)
  14. const notes = handleActions({
  15. [actions.ADD_NOTE]: (state, action) => [...state, { id: _.uniqueId(), title: 'new_note', content: '' }],
  16. [actions.UPDATE_NOTE]: (state, action) => _.updateWhere(state, action.payload, _.idCheck(action.payload.id)),
  17. [actions.REMOVE_NOTE]: (state, action) => _.reject(state, _.idCheck(action.payload.id)),
  18. }, MOCK_NOTES)
  19. const note = combineReducers({ notes, selectedNote })
  20. export default note