export const constants = {
  INTERACTION_LIST_SEARCH: 'INTERACTION_LIST_SEARCH',
  UPDTE_SORT_TYPE: 'UPDTE_SORT_TYPE'
};

export const actions = {
  onSearch(keyword) {
    return {
      type: constants.INTERACTION_LIST_SEARCH,
      payload: keyword
    };
  },
  // 更新排序方式
  updateInteractionSortType(sortType: 'byCreatedAt' | 'byUpdatedAt') {
    return {
      type: constants.UPDTE_SORT_TYPE,
      payload: sortType
    };
  }
};

export function reducers(state, { type, payload }) {
  switch (type) {
    case constants.INTERACTION_LIST_SEARCH: {
      return {
        ...state,
        search: payload
      };
    }
    case constants.UPDTE_SORT_TYPE: {
      return {
        ...state,
        sortType: payload
      };
    }
    default:
      return state;
  }
}
