Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify place the up work button by employees #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chimame
Copy link
Member

@chimame chimame commented Jun 29, 2016

#5 の対応をしてました。

reducers部分がメインですが、これでいいのか…

return {
...state,
at_work: !state.at_work
members: state.members.map((element) => {return (element.id === target_member.id ? target_member : element)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduxのチュートリアルと同じように、members と member のReducerを作ればいいんじゃないニャ?

[参考]
http://redux.js.org/docs/basics/ExampleTodoList.html

@chimame
Copy link
Member Author

chimame commented Jul 4, 2016

memberのreducerとなる部分を分離してみました。
けどこうなるとreducers/index.jsからreducers/member/index.jsとreducers/memberList/index.jsに分割したくなります。

reducers/index.jsは

import { handleActions } from 'redux-actions'
import reducerMap from './memberList'

const initialState = {
  members: [
    {id: 1, name: "高垣 楓", checkin_time: "2016/06/25 09:00", checkout_time: "2016/06/25 15:00", at_work: false},
    {id: 2, name: "速水 奏", checkin_time: "2016/06/25 09:20", checkout_time: "2016/06/25 17:00", at_work: false}
  ]
}

export default handleActions(reducerMap, initialState)

reducers/memberList/index.jsは

import memberRecuer from '../member'

const memberListReducer = {
  show_members(state, action) {
    return action.members.payload
  },
  add_recorder(state, action) {
    return state.concat([action.payload])
  },
  up_work(state, action) {
    return {
      ...state,
      members: state.members.map(t => memberRecuer.up_work(t, action))
    }
  }
}

export default memberListReducer

reducers/member/index.jsは

const memberRecuer = {
  up_work(state, action) {
    if (state.id !== action.payload) {
      return state
    }

    let today = new Date()
    let now   = `${today.getFullYear()}/${('0' + (today.getMonth() + 1)).slice(-2)}/${('0' + today.getDate()).slice(-2)} ${('0' + today.getHours()).slice(-2)}:${('0' + today.getMinutes()).slice(-2)}`

    return {
      ...state,
      checkin_time:   (!state.at_work ? now : state.checkin_time),
      checkout_time:  (!state.at_work ? ""  : now),
      at_work:        !state.at_work
    }
  }
}

export default memberRecuer

みたいな感じの方がいいのかな?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants