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) {
|
export function newChannelRequest (id, name, channelId) {
|
||||||
return {
|
return {
|
||||||
type: actions.CHANNEL_REQUEST_ASYNC,
|
type: actions.CHANNEL_REQUEST_NEW,
|
||||||
data: {id, name, channelId},
|
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) {
|
export function addNewChannelToChannelList (id, name, shortId, longId, claimsData) {
|
||||||
return {
|
return {
|
||||||
type: actions.CHANNEL_NEW_SUCCESS,
|
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`;
|
export const ASSET_NEW_SUCCESS = `ASSET_NEW_SUCCESS`;
|
||||||
|
|
||||||
// channel actions
|
// 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_REQUEST_SUCCESS = 'CHANNEL_REQUEST_SUCCESS';
|
||||||
|
|
||||||
export const CHANNEL_NEW_ASYNC = 'CHANNEL_NEW_ASYNC';
|
export const CHANNEL_NEW_ASYNC = 'CHANNEL_NEW_ASYNC';
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { newChannelRequest, showNewChannel } from 'actions/show';
|
import { newChannelRequest } from 'actions/show';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
|
@ -11,7 +10,7 @@ const mapStateToProps = ({ show }) => {
|
||||||
const requestChannelId = show.request.data.id;
|
const requestChannelId = show.request.data.id;
|
||||||
// select request
|
// select request
|
||||||
const previousRequest = show.channelRequests[show.request.id] || null;
|
const previousRequest = show.channelRequests[show.request.id] || null;
|
||||||
// select channel info
|
// select channel
|
||||||
let channel;
|
let channel;
|
||||||
if (previousRequest) {
|
if (previousRequest) {
|
||||||
const channelKey = `c#${previousRequest.name}#${previousRequest.longId}`;
|
const channelKey = `c#${previousRequest.name}#${previousRequest.longId}`;
|
||||||
|
@ -22,21 +21,15 @@ const mapStateToProps = ({ show }) => {
|
||||||
requestType,
|
requestType,
|
||||||
requestChannelName,
|
requestChannelName,
|
||||||
requestChannelId,
|
requestChannelId,
|
||||||
previousRequest,
|
|
||||||
channel,
|
channel,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
// request
|
|
||||||
onNewChannelRequest (requestId, requestChannelName, requestChannelId) {
|
onNewChannelRequest (requestId, requestChannelName, requestChannelId) {
|
||||||
dispatch(newChannelRequest(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 {
|
class ShowChannel extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { previousRequest, channel, requestId, requestChannelName, requestChannelId } = this.props;
|
const { channel, requestId, requestChannelName, requestChannelId } = this.props;
|
||||||
if (!previousRequest) {
|
|
||||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
|
||||||
}
|
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
const { name, shortId, longId } = previousRequest;
|
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||||
return this.props.onShowNewChannel(name, shortId, longId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (requestIsAChannelRequest(nextProps)) {
|
if (requestIsAChannelRequest(nextProps)) {
|
||||||
const { previousRequest, channel, requestId, requestChannelName, requestChannelId } = nextProps;
|
const { channel, requestId, requestChannelName, requestChannelId } = nextProps;
|
||||||
if (!previousRequest) {
|
|
||||||
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
|
||||||
}
|
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
const { name, shortId, longId } = previousRequest;
|
return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||||
return this.props.onShowNewChannel(name, shortId, longId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ const initialState = {
|
||||||
data : null,
|
data : null,
|
||||||
requestId: null,
|
requestId: null,
|
||||||
},
|
},
|
||||||
displayAsset: {
|
|
||||||
error : null,
|
|
||||||
status: LOCAL_CHECK,
|
|
||||||
},
|
|
||||||
channelRequests: {},
|
channelRequests: {},
|
||||||
channelList : {},
|
channelList : {},
|
||||||
assetRequests : {},
|
assetRequests : {},
|
||||||
assetList : {},
|
assetList : {},
|
||||||
|
displayAsset : {
|
||||||
|
error : null,
|
||||||
|
status: LOCAL_CHECK,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function (state = initialState, action) {
|
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:
|
case actions.ASSET_REQUEST_SUCCESS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
assetRequests: Object.assign({}, state.assetRequests, {
|
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:
|
case actions.ASSET_NEW_SUCCESS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
assetList: Object.assign({}, state.assetList, {
|
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:
|
case actions.CHANNEL_NEW_SUCCESS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
channelList: Object.assign({}, state.channelList, {
|
channelList: Object.assign({}, state.channelList, {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import { all } from 'redux-saga/effects';
|
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 { watchFileIsRequested } from './file';
|
||||||
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
|
|
||||||
|
|
||||||
export default function* rootSaga () {
|
export default function* rootSaga () {
|
||||||
yield all([
|
yield all([
|
||||||
watchNewAssetRequest(),
|
watchNewAssetRequest(),
|
||||||
watchNewChannelRequest(),
|
watchNewChannelRequest(),
|
||||||
watchShowNewChannel(),
|
watchUpdateChannelClaims(),
|
||||||
watchFileIsRequested(),
|
watchFileIsRequested(),
|
||||||
watchShowNewChannelClaimsRequest(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { call, put, takeLatest } from 'redux-saga/effects';
|
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||||
import * as actions from 'constants/show_action_types';
|
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 { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||||
import { getChannelData } from 'api/channelApi';
|
|
||||||
|
|
||||||
function* newAssetRequest (action) {
|
function* newAssetRequest (action) {
|
||||||
const { id, name, modifier } = action.data;
|
const { id, name, modifier } = action.data;
|
||||||
|
@ -25,7 +24,7 @@ function* newAssetRequest (action) {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return yield put(updateRequestError(error.message));
|
return yield put(updateRequestError(error.message));
|
||||||
}
|
}
|
||||||
// get claim data
|
// get asset claim data
|
||||||
console.log(`getting asset claim data ${name} ${longId}`);
|
console.log(`getting asset claim data ${name} ${longId}`);
|
||||||
let claimData;
|
let claimData;
|
||||||
try {
|
try {
|
||||||
|
@ -40,24 +39,6 @@ function* newAssetRequest (action) {
|
||||||
yield put(updateRequestError(null));
|
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 () {
|
export function* watchNewAssetRequest () {
|
||||||
yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest);
|
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 { call, put, takeLatest } from 'redux-saga/effects';
|
||||||
import * as actions from 'constants/show_action_types';
|
import * as actions from 'constants/show_action_types';
|
||||||
import { updateRequestError, addNewChannelToChannelList, updateChannelClaims } from 'actions/show';
|
import { addNewChannelToChannelList, addRequestToChannelRequests, updateRequestError, updateChannelClaims } from 'actions/show';
|
||||||
import { getChannelClaims } from 'api/channelApi';
|
import { getChannelClaims, getChannelData } from 'api/channelApi';
|
||||||
|
|
||||||
function* getChannelClaimsAndShowChannel (action) {
|
function* newChannelRequest (action) {
|
||||||
const { id, name, shortId, longId } = action.data;
|
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;
|
let claimsData;
|
||||||
try {
|
try {
|
||||||
({ data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
({ data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return yield put(updateRequestError(error.message));
|
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));
|
yield put(updateRequestError(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* watchShowNewChannel () {
|
export function* watchNewChannelRequest () {
|
||||||
yield takeLatest(actions.CHANNEL_NEW_ASYNC, getChannelClaimsAndShowChannel);
|
yield takeLatest(actions.CHANNEL_REQUEST_NEW, newChannelRequest);
|
||||||
};
|
};
|
||||||
|
|
||||||
function* getNewClaimsAndUpdateClaimsList (action) {
|
function* getNewClaimsAndUpdateChannel (action) {
|
||||||
const { channelKey, name, longId, page } = action.data;
|
const { channelKey, name, longId, page } = action.data;
|
||||||
let claimsData;
|
let claimsData;
|
||||||
try {
|
try {
|
||||||
|
@ -30,6 +45,6 @@ function* getNewClaimsAndUpdateClaimsList (action) {
|
||||||
yield put(updateChannelClaims(channelKey, claimsData));
|
yield put(updateChannelClaims(channelKey, claimsData));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* watchShowNewChannelClaimsRequest () {
|
export function* watchUpdateChannelClaims () {
|
||||||
yield takeLatest(actions.CHANNEL_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateClaimsList);
|
yield takeLatest(actions.CHANNEL_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateChannel);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue