added actions and saga for updating claims list

This commit is contained in:
bill bittner 2018-02-09 10:02:13 -08:00
parent 98992b754b
commit 2781e30134
7 changed files with 65 additions and 30 deletions

View file

@ -124,17 +124,19 @@ export function clearShowChannel () {
// update channel data
// export function updateChannelClaims () {
// return {
// type: actions.CHANNEL_LIST_UPDATE, // updates claims in channel in channel list
// }
// }
export function updateChannelClaimsAsync (channelListId, name, longId, page) {
return {
type: actions.CHANNEL_LIST_CLAIMS_UPDATE_ASYNC,
data: {channelListId, name, longId, page},
};
};
// export function updateShowChannelClaims () {
// return {
// type: actions.SHOW_CHANNEL_CLAIMS_UPDATE, // update claims in show channel
// }
// }
export function updateChannelClaims (channelListId, claimsData) {
return {
type: actions.CHANNEL_LIST_CLAIMS_UPDATE,
data: {channelListId, claimsData},
};
};
// add channels to channel list

View file

@ -22,6 +22,8 @@ export const SHOW_CHANNEL_UPDATE = 'SHOW_CHANNEL_UPDATE';
export const SHOW_CHANNEL_CLEAR = 'SHOW_CHANNEL_CLEAR';
export const CHANNEL_LIST_ADD = 'CHANNEL_LIST_ADD';
export const CHANNEL_LIST_CLAIMS_UPDATE_ASYNC = 'CHANNEL_LIST_CLAIMS_UPDATE_ASYNC';
export const CHANNEL_LIST_CLAIMS_UPDATE = 'CHANNEL_LIST_CLAIMS_UPDATE';
// asset/file display actions
export const FILE_REQUESTED = 'FILE_REQUESTED';

View file

@ -1,19 +1,20 @@
import { connect } from 'react-redux';
import { } from 'actions/show';
import { updateChannelClaimsAsync } from 'actions/show';
import View from './view';
const mapStateToProps = ({ show }) => {
return {
channel: show.channelList[show.showChannel.id],
showChannelId: show.showChannel.id,
channel : show.channelList[show.showChannel.id],
};
};
// const mapDispatchToProps = dispatch => {
// return {
// onChannelPageUpdate: (channelRecordId, name, longId, page) => {
// dispatch(updateChannelClaims(channelRecordId, name, longId, page));
// },
// };
// };
const mapDispatchToProps = dispatch => {
return {
onChannelPageUpdate: (showChannelId, name, longId, page) => {
dispatch(updateChannelClaimsAsync(showChannelId, name, longId, page));
},
};
};
export default connect(mapStateToProps, null)(View);
export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -7,18 +7,21 @@ class ChannelClaimsDisplay extends React.Component {
this.showNextResultsPage = this.showNextResultsPage.bind(this);
this.showPreviousResultsPage = this.showPreviousResultsPage.bind(this);
}
showNewPage (page) {
console.log(`update claims data with new page ${page}`);
this.props.onChannelPageUpdate(page);
}
showPreviousResultsPage () {
const previousPage = parseInt(this.props.currentPage) - 1;
const { channel: { claimsData: { currentPage } } } = this.props;
const previousPage = parseInt(currentPage) - 1;
this.showNewPage(previousPage);
}
showNextResultsPage () {
const nextPage = parseInt(this.props.currentPage) + 1;
const { channel: { claimsData: { currentPage } } } = this.props;
const nextPage = parseInt(currentPage) + 1;
this.showNewPage(nextPage);
}
showNewPage (page) {
const { showChannelId, channel: { channelData: { name, longId } } } = this.props;
console.log(`update claims data on channel ${showChannelId} with new page ${page}`);
this.props.onChannelPageUpdate(showChannelId, name, longId, page);
}
render () {
const { channel: { error, claimsData: { claims, currentPage, totalPages } } } = this.props;
return (

View file

@ -144,6 +144,14 @@ export default function (state = initialState, action) {
},
}),
});
case actions.CHANNEL_LIST_CLAIMS_UPDATE:
return Object.assign({}, state, {
channelList: Object.assign({}, state.channelList, {
[action.data.channelListId]: Object.assign({}, state.channelList[action.data.channelListId], {
claimsData: action.data.claimsData,
}),
}),
});
// display an asset
case actions.FILE_AVAILABILITY_UPDATE:
return Object.assign({}, state, {

View file

@ -1,7 +1,7 @@
import { all } from 'redux-saga/effects';
import { watchNewAssetRequest, watchNewChannelRequest } from './request';
import { watchFileIsRequested } from './file';
import { watchShowNewChannel } from './show_channel';
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
import { watchShowNewAsset } from './show_asset';
export default function* rootSaga () {
@ -11,5 +11,6 @@ export default function* rootSaga () {
watchShowNewAsset(),
watchShowNewChannel(),
watchFileIsRequested(),
watchShowNewChannelClaimsRequest(),
]);
}

View file

@ -1,9 +1,9 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { updateShowChannel, addNewChannelToChannelList } from 'actions/show';
import { updateShowChannel, addNewChannelToChannelList, updateChannelClaims } from 'actions/show';
import { getChannelClaims } from 'api/channelApi';
function* getNewChannelDataAndShowChannel (action) {
function* getChannelClaimsAndShowChannel (action) {
const { id, channelData: {name, shortId, longId} } = action.data;
let success, message, claimsData;
try {
@ -20,5 +20,23 @@ function* getNewChannelDataAndShowChannel (action) {
}
export function* watchShowNewChannel () {
yield takeLatest(actions.SHOW_CHANNEL_NEW, getNewChannelDataAndShowChannel);
yield takeLatest(actions.SHOW_CHANNEL_NEW, getChannelClaimsAndShowChannel);
};
function* getNewClaimsAndUpdateClaimsList (action) {
const { channelListId, name, longId, page } = action.data;
let success, message, claimsData;
try {
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, page));
} catch (error) {
return yield put(updateShowChannel(error.message, null));
}
if (!success) {
return yield put(updateShowChannel(message, null));
}
yield put(updateChannelClaims(channelListId, claimsData));
}
export function* watchShowNewChannelClaimsRequest () {
yield takeLatest(actions.CHANNEL_LIST_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateClaimsList);
}