removed showChannel from actions
This commit is contained in:
parent
855a7dab42
commit
55eb2dd85f
8 changed files with 55 additions and 88 deletions
|
@ -62,7 +62,7 @@ export function addAssetToAssetList (id, error, name, claimId, shortId, claimDat
|
|||
|
||||
export function newChannelRequest (id, name, channelId) {
|
||||
return {
|
||||
type: actions.CHANNEL_REQUEST_ASYNC,
|
||||
type: actions.CHANNEL_REQUEST_NEW,
|
||||
data: {id, name, channelId},
|
||||
};
|
||||
};
|
||||
|
@ -74,18 +74,6 @@ export function addRequestToChannelRequests (id, error, name, longId, shortId) {
|
|||
};
|
||||
}
|
||||
|
||||
// show a channel
|
||||
|
||||
export function showNewChannel (name, shortId, longId) {
|
||||
const id = `c#${name}#${longId}`; // move to the action
|
||||
return {
|
||||
type: actions.CHANNEL_NEW_ASYNC,
|
||||
data: { id, name, shortId, longId },
|
||||
};
|
||||
};
|
||||
|
||||
// add channels to channel list
|
||||
|
||||
export function addNewChannelToChannelList (id, name, shortId, longId, claimsData) {
|
||||
return {
|
||||
type: actions.CHANNEL_NEW_SUCCESS,
|
||||
|
|
|
@ -11,7 +11,7 @@ export const ASSET_NEW_ASYNC = 'ASSET_NEW_ASYNC';
|
|||
export const ASSET_NEW_SUCCESS = `ASSET_NEW_SUCCESS`;
|
||||
|
||||
// channel actions
|
||||
export const CHANNEL_REQUEST_ASYNC = 'CHANNEL_REQUEST_ASYNC';
|
||||
export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW';
|
||||
export const CHANNEL_REQUEST_SUCCESS = 'CHANNEL_REQUEST_SUCCESS';
|
||||
|
||||
export const CHANNEL_NEW_ASYNC = 'CHANNEL_NEW_ASYNC';
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
import { connect } from 'react-redux';
|
||||
import { newChannelRequest, showNewChannel } from 'actions/show';
|
||||
import { newChannelRequest } from 'actions/show';
|
||||
import View from './view';
|
||||
|
||||
const mapStateToProps = ({ show }) => {
|
||||
|
@ -11,7 +10,7 @@ const mapStateToProps = ({ show }) => {
|
|||
const requestChannelId = show.request.data.id;
|
||||
// select request
|
||||
const previousRequest = show.channelRequests[show.request.id] || null;
|
||||
// select channel info
|
||||
// select channel
|
||||
let channel;
|
||||
if (previousRequest) {
|
||||
const channelKey = `c#${previousRequest.name}#${previousRequest.longId}`;
|
||||
|
@ -22,21 +21,15 @@ const mapStateToProps = ({ show }) => {
|
|||
requestType,
|
||||
requestChannelName,
|
||||
requestChannelId,
|
||||
previousRequest,
|
||||
channel,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
// request
|
||||
onNewChannelRequest (requestId, requestChannelName, requestChannelId) {
|
||||
dispatch(newChannelRequest(requestId, requestChannelName, requestChannelId));
|
||||
},
|
||||
// show channel
|
||||
onShowNewChannel: (name, shortId, longId) => {
|
||||
dispatch(showNewChannel(name, shortId, longId));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -11,24 +11,16 @@ function requestIsAChannelRequest ({ requestType }) {
|
|||
|
||||
class ShowChannel extends React.Component {
|
||||
componentDidMount () {
|
||||
const { previousRequest, channel, requestId, requestChannelName, requestChannelId } = this.props;
|
||||
if (!previousRequest) {
|
||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
const { channel, requestId, requestChannelName, requestChannelId } = this.props;
|
||||
if (!channel) {
|
||||
const { name, shortId, longId } = previousRequest;
|
||||
return this.props.onShowNewChannel(name, shortId, longId);
|
||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (requestIsAChannelRequest(nextProps)) {
|
||||
const { previousRequest, channel, requestId, requestChannelName, requestChannelId } = nextProps;
|
||||
if (!previousRequest) {
|
||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
const { channel, requestId, requestChannelName, requestChannelId } = nextProps;
|
||||
if (!channel) {
|
||||
const { name, shortId, longId } = previousRequest;
|
||||
return this.props.onShowNewChannel(name, shortId, longId);
|
||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ const initialState = {
|
|||
data : null,
|
||||
requestId: null,
|
||||
},
|
||||
displayAsset: {
|
||||
error : null,
|
||||
status: LOCAL_CHECK,
|
||||
},
|
||||
channelRequests: {},
|
||||
channelList : {},
|
||||
assetRequests : {},
|
||||
assetList : {},
|
||||
displayAsset : {
|
||||
error : null,
|
||||
status: LOCAL_CHECK,
|
||||
},
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
|
@ -53,7 +53,7 @@ export default function (state = initialState, action) {
|
|||
},
|
||||
},
|
||||
});
|
||||
// successful requests
|
||||
// asset actions
|
||||
case actions.ASSET_REQUEST_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
assetRequests: Object.assign({}, state.assetRequests, {
|
||||
|
@ -64,18 +64,6 @@ export default function (state = initialState, action) {
|
|||
},
|
||||
}),
|
||||
});
|
||||
case actions.CHANNEL_REQUEST_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
channelRequests: Object.assign({}, state.channelRequests, {
|
||||
[action.data.id]: {
|
||||
error : action.data.error,
|
||||
name : action.data.name,
|
||||
longId : action.data.longId,
|
||||
shortId: action.data.shortId,
|
||||
},
|
||||
}),
|
||||
});
|
||||
// updates to asset list
|
||||
case actions.ASSET_NEW_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
assetList: Object.assign({}, state.assetList, {
|
||||
|
@ -88,7 +76,18 @@ export default function (state = initialState, action) {
|
|||
},
|
||||
}),
|
||||
});
|
||||
// updates to channel list
|
||||
// channel actions
|
||||
case actions.CHANNEL_REQUEST_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
channelRequests: Object.assign({}, state.channelRequests, {
|
||||
[action.data.id]: {
|
||||
error : action.data.error,
|
||||
name : action.data.name,
|
||||
longId : action.data.longId,
|
||||
shortId: action.data.shortId,
|
||||
},
|
||||
}),
|
||||
});
|
||||
case actions.CHANNEL_NEW_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
channelList: Object.assign({}, state.channelList, {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import { all } from 'redux-saga/effects';
|
||||
import { watchNewAssetRequest, watchNewChannelRequest } from './request';
|
||||
import { watchNewAssetRequest } from './show_asset';
|
||||
import { watchNewChannelRequest, watchUpdateChannelClaims } from './show_channel';
|
||||
import { watchFileIsRequested } from './file';
|
||||
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
|
||||
|
||||
export default function* rootSaga () {
|
||||
yield all([
|
||||
watchNewAssetRequest(),
|
||||
watchNewChannelRequest(),
|
||||
watchShowNewChannel(),
|
||||
watchUpdateChannelClaims(),
|
||||
watchFileIsRequested(),
|
||||
watchShowNewChannelClaimsRequest(),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||
import * as actions from 'constants/show_action_types';
|
||||
import { addRequestToAssetRequests, updateRequestError, addRequestToChannelRequests, showNewChannel, addAssetToAssetList } from 'actions/show';
|
||||
import { addRequestToAssetRequests, updateRequestError, addAssetToAssetList } from 'actions/show';
|
||||
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||
import { getChannelData } from 'api/channelApi';
|
||||
|
||||
function* newAssetRequest (action) {
|
||||
const { id, name, modifier } = action.data;
|
||||
|
@ -25,7 +24,7 @@ function* newAssetRequest (action) {
|
|||
} catch (error) {
|
||||
return yield put(updateRequestError(error.message));
|
||||
}
|
||||
// get claim data
|
||||
// get asset claim data
|
||||
console.log(`getting asset claim data ${name} ${longId}`);
|
||||
let claimData;
|
||||
try {
|
||||
|
@ -40,24 +39,6 @@ function* newAssetRequest (action) {
|
|||
yield put(updateRequestError(null));
|
||||
};
|
||||
|
||||
function* newChannelRequest (action) {
|
||||
const { id, name, channelId } = action.data;
|
||||
console.log('getting channel long id');
|
||||
let data;
|
||||
try {
|
||||
({data} = yield call(getChannelData, name, channelId));
|
||||
} catch (error) {
|
||||
return yield put(updateRequestError(error.message));
|
||||
}
|
||||
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
|
||||
yield put(addRequestToChannelRequests(id, null, name, longId, shortId));
|
||||
yield put(showNewChannel(name, shortId, longId));
|
||||
}
|
||||
|
||||
export function* watchNewAssetRequest () {
|
||||
yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest);
|
||||
};
|
||||
|
||||
export function* watchNewChannelRequest () {
|
||||
yield takeLatest(actions.CHANNEL_REQUEST_ASYNC, newChannelRequest);
|
||||
};
|
|
@ -1,25 +1,40 @@
|
|||
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||
import * as actions from 'constants/show_action_types';
|
||||
import { updateRequestError, addNewChannelToChannelList, updateChannelClaims } from 'actions/show';
|
||||
import { getChannelClaims } from 'api/channelApi';
|
||||
import { addNewChannelToChannelList, addRequestToChannelRequests, updateRequestError, updateChannelClaims } from 'actions/show';
|
||||
import { getChannelClaims, getChannelData } from 'api/channelApi';
|
||||
|
||||
function* getChannelClaimsAndShowChannel (action) {
|
||||
const { id, name, shortId, longId } = action.data;
|
||||
function* newChannelRequest (action) {
|
||||
const { id, name, channelId } = action.data;
|
||||
// get channel long id
|
||||
console.log('getting channel long id and short id');
|
||||
let longId, shortId;
|
||||
try {
|
||||
({ data: {longChannelClaimId: longId, shortChannelClaimId: shortId} } = yield call(getChannelData, name, channelId));
|
||||
} catch (error) {
|
||||
return yield put(updateRequestError(error.message));
|
||||
}
|
||||
// store the request in the channel requests list
|
||||
yield put(addRequestToChannelRequests(id, null, name, longId, shortId));
|
||||
// get channel claims data
|
||||
console.log('getting channel claims data');
|
||||
let claimsData;
|
||||
try {
|
||||
({ data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
||||
} catch (error) {
|
||||
return yield put(updateRequestError(error.message));
|
||||
}
|
||||
yield put(addNewChannelToChannelList(id, name, shortId, longId, claimsData));
|
||||
// store the channel data in the channel list
|
||||
const channelKey = `c#${name}#${longId}`;
|
||||
yield put(addNewChannelToChannelList(channelKey, name, shortId, longId, claimsData));
|
||||
// clear any request errors
|
||||
yield put(updateRequestError(null));
|
||||
}
|
||||
|
||||
export function* watchShowNewChannel () {
|
||||
yield takeLatest(actions.CHANNEL_NEW_ASYNC, getChannelClaimsAndShowChannel);
|
||||
export function* watchNewChannelRequest () {
|
||||
yield takeLatest(actions.CHANNEL_REQUEST_NEW, newChannelRequest);
|
||||
};
|
||||
|
||||
function* getNewClaimsAndUpdateClaimsList (action) {
|
||||
function* getNewClaimsAndUpdateChannel (action) {
|
||||
const { channelKey, name, longId, page } = action.data;
|
||||
let claimsData;
|
||||
try {
|
||||
|
@ -30,6 +45,6 @@ function* getNewClaimsAndUpdateClaimsList (action) {
|
|||
yield put(updateChannelClaims(channelKey, claimsData));
|
||||
}
|
||||
|
||||
export function* watchShowNewChannelClaimsRequest () {
|
||||
yield takeLatest(actions.CHANNEL_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateClaimsList);
|
||||
export function* watchUpdateChannelClaims () {
|
||||
yield takeLatest(actions.CHANNEL_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateChannel);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue