added new channel request handling
This commit is contained in:
parent
d1a71cf74f
commit
8672f7f41a
8 changed files with 157 additions and 76 deletions
|
@ -75,29 +75,42 @@ export function clearShowAsset () {
|
|||
|
||||
// request for a channel
|
||||
|
||||
export function newChannelRequest (id, name, channelId) {
|
||||
return {
|
||||
type: actions.NEW_CHANNEL_REQUEST,
|
||||
data: {id, name, channelId},
|
||||
};
|
||||
};
|
||||
|
||||
export function addChannelRequest (id, error, name, claimId) {
|
||||
return {
|
||||
type: actions.CHANNEL_REQUEST_ADD,
|
||||
data: { id, error, name, claimId },
|
||||
};
|
||||
}
|
||||
|
||||
// show a channel
|
||||
|
||||
export function updateShowChannelError (error) {
|
||||
return {
|
||||
type: actions.SHOW_CHANNEL_ERROR,
|
||||
data: error,
|
||||
};
|
||||
};
|
||||
|
||||
export function updateChannelData (name, longId, shortId) {
|
||||
return {
|
||||
type: actions.CHANNEL_DATA_UPDATE,
|
||||
data: { name, longId, shortId },
|
||||
};
|
||||
};
|
||||
|
||||
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
||||
return {
|
||||
type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
||||
data: { claims, currentPage, totalPages, totalClaims },
|
||||
};
|
||||
};
|
||||
// export function updateShowChannelError (error) {
|
||||
// return {
|
||||
// type: actions.SHOW_CHANNEL_ERROR,
|
||||
// data: error,
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// export function updateChannelData (name, longId, shortId) {
|
||||
// return {
|
||||
// type: actions.CHANNEL_DATA_UPDATE,
|
||||
// data: { name, longId, shortId },
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
||||
// return {
|
||||
// type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
||||
// data: { claims, currentPage, totalPages, totalClaims },
|
||||
// };
|
||||
// };
|
||||
|
||||
// display a file
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Request from 'utils/request';
|
||||
|
||||
export function getLongClaimId (name, modifier) {
|
||||
export function getLongChannelClaimId (name, modifier) {
|
||||
let body = {};
|
||||
// create request params
|
||||
if (modifier) {
|
||||
|
@ -25,12 +25,12 @@ export function getLongClaimId (name, modifier) {
|
|||
return Request(url, params);
|
||||
};
|
||||
|
||||
export function getShortId (name, claimId) {
|
||||
export function getShortChannelId (name, claimId) {
|
||||
const url = `/api/claim/short-id/${claimId}/${name}`;
|
||||
return Request(url);
|
||||
};
|
||||
|
||||
export function getClaimData (name, claimId) {
|
||||
export function getChannelData (name, claimId) {
|
||||
const url = `/api/claim/data/${name}/${claimId}`;
|
||||
return Request(url);
|
||||
};
|
||||
|
|
|
@ -18,3 +18,7 @@ export const NEW_ASSET_REQUEST = 'NEW_ASSET_REQUEST';
|
|||
export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
|
||||
export const SHOW_NEW_ASSET = 'SHOW_NEW_ASSET';
|
||||
export const SHOW_ASSET_CLEAR = 'SHOW_ASSET_CLEAR';
|
||||
|
||||
export const NEW_CHANNEL_REQUEST = 'NEW_CHANNEL_REQUEST';
|
||||
export const CHANNEL_REQUEST_ADD = 'CHANNEL_REQUEST_ADD';
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@ class ShowAsset extends React.Component {
|
|||
console.log('repeat request');
|
||||
const { assets } = this.props;
|
||||
const { error: requestError, name, claimId } = request;
|
||||
const assetId = `a#${name}#${claimId}`;
|
||||
// if error, return and update state with error
|
||||
if (requestError) {
|
||||
return this.props.onRequestError(requestError);
|
||||
}
|
||||
// update the show asset data in the store
|
||||
// update the showAsset data in the store
|
||||
const assetId = `a#${name}#${claimId}`;
|
||||
if (assets[assetId]) { // case: the asset data already exists
|
||||
let { error, name, claimId, shortId, claimData } = assets[assetId];
|
||||
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { connect } from 'react-redux';
|
||||
import {updateChannelData, updateShowChannelError} from 'actions/show';
|
||||
import {newChannelRequest, updateRequestError} from 'actions/show';
|
||||
import View from './view';
|
||||
|
||||
const mapStateToProps = ({ show }) => {
|
||||
return {
|
||||
requestId : show.request.id,
|
||||
requestType : show.request.type,
|
||||
requestChannelName: show.request.data.name,
|
||||
requestChannelId : show.request.data.id,
|
||||
requestList : show.channelRequests,
|
||||
channels : show.channels,
|
||||
error : show.showChannel.error,
|
||||
name : show.showChannel.channelData.name,
|
||||
shortId : show.showChannel.channelData.shortId,
|
||||
|
@ -16,15 +19,22 @@ const mapStateToProps = ({ show }) => {
|
|||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
onShowChannelError: (error) => {
|
||||
dispatch(updateShowChannelError(error));
|
||||
// onShowChannelError: (error) => {
|
||||
// dispatch(updateShowChannelError(error));
|
||||
// },
|
||||
// onChannelDataUpdate: (name, longId, shortId) => {
|
||||
// dispatch(updateChannelData(name, longId, shortId));
|
||||
// dispatch(updateShowChannelError(null)); // clear any errors
|
||||
// },
|
||||
// onChannelDataClear: () => {
|
||||
// dispatch(updateChannelData(null, null, null));
|
||||
// },
|
||||
// new
|
||||
onNewChannelRequest (id, name, channelId) {
|
||||
dispatch(newChannelRequest(id, name, channelId));
|
||||
},
|
||||
onChannelDataUpdate: (name, longId, shortId) => {
|
||||
dispatch(updateChannelData(name, longId, shortId));
|
||||
dispatch(updateShowChannelError(null)); // clear any errors
|
||||
},
|
||||
onChannelDataClear: () => {
|
||||
dispatch(updateChannelData(null, null, null));
|
||||
onRequestError: (error) => {
|
||||
dispatch(updateRequestError(error, null, null));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,17 +4,59 @@ import NavBar from 'containers/NavBar';
|
|||
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||
import request from 'utils/request';
|
||||
|
||||
import { CHANNEL } from 'constants/show_request_types';
|
||||
|
||||
function requestIsAChannelRequest ({ requestType }) {
|
||||
return requestType === CHANNEL;
|
||||
}
|
||||
|
||||
function channelNameOrIdChanged (nextProps, props) {
|
||||
return (nextProps.requestChannelName !== props.requestChannelName || nextProps.requestChannelName !== props.requestChannelName);
|
||||
}
|
||||
|
||||
function existingRequest (requestId, requestList) {
|
||||
return requestList[requestId];
|
||||
}
|
||||
|
||||
class ShowChannel extends React.Component {
|
||||
componentDidMount () {
|
||||
console.log('showchannel did mount');
|
||||
const {requestChannelName, requestChannelId} = this.props;
|
||||
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
||||
const {requestId, requestName, requestChannelId, requestList} = this.props;
|
||||
if (existingRequest(requestId, requestList)) {
|
||||
// const validRequest = existingRequest(requestId, requestList);
|
||||
// this.onRepeatChannelRequest(validRequest);
|
||||
console.log('weird, we got a repeat channel request on an unmounted ShowChannel component');
|
||||
} else {
|
||||
this.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||
}
|
||||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (nextProps.channelRequests !== this.props.channelRequests) {
|
||||
const {requestChannelName, requestChannelId} = nextProps;
|
||||
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
||||
}
|
||||
console.log('showchannel will receive new props');
|
||||
if (requestIsAChannelRequest(nextProps) && channelNameOrIdChanged(nextProps, this.props)) {
|
||||
const {requestId, requestList} = nextProps;
|
||||
if (existingRequest(requestId, requestList)) {
|
||||
const request = requestList[requestId];
|
||||
this.onRepeatChannelRequest(request);
|
||||
} else {
|
||||
console.log('weird, we got a new channel request on a mounted ShowChannel component');
|
||||
}
|
||||
};
|
||||
}
|
||||
onNewChannelRequest (requestId, requestName, requestChannelId) {
|
||||
// validate the request (i.e. get channel full claim id)
|
||||
// update teh request list
|
||||
// if error, return early (set the request error in the store)
|
||||
// if the request is valid...
|
||||
// add it to the requestList
|
||||
// update showChannel to reflect the channel details
|
||||
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||
}
|
||||
onRepeatChannelRequest ({ id, error, name, claimId }) {
|
||||
// if error, return early (set the request error in the store)
|
||||
// if the request is valid...
|
||||
// update showChannel to reflect the channel details
|
||||
// see if they are available
|
||||
// retrieve them if they are not available
|
||||
}
|
||||
getAndStoreChannelData (name, id) {
|
||||
console.log('getting and storing channel data for channel:', name, id);
|
||||
|
|
|
@ -9,21 +9,6 @@ const initialState = {
|
|||
data : null,
|
||||
requestId: null,
|
||||
},
|
||||
// channelRequest: {
|
||||
// name: null,
|
||||
// id : null,
|
||||
// },
|
||||
// assetRequest: {
|
||||
// name : null,
|
||||
// modifier: {
|
||||
// id : null,
|
||||
// channel: {
|
||||
// name: null,
|
||||
// id : null,
|
||||
// },
|
||||
// },
|
||||
// extension: null,
|
||||
// },
|
||||
showChannel: {
|
||||
error : null,
|
||||
channelData: {
|
||||
|
@ -135,26 +120,35 @@ export default function (state = initialState, action) {
|
|||
}),
|
||||
});
|
||||
// request a channel
|
||||
|
||||
case actions.CHANNEL_REQUEST_ADD:
|
||||
return Object.assign({}, state, {
|
||||
channelRequests: Object.assign({}, state.assetRequests, {
|
||||
[action.data.id]: {
|
||||
error : action.data.error,
|
||||
name : action.data.name,
|
||||
claimId: action.data.claimId,
|
||||
},
|
||||
}),
|
||||
});
|
||||
// show a channel
|
||||
case actions.SHOW_CHANNEL_ERROR:
|
||||
return Object.assign({}, state, {
|
||||
showChannel: Object.assign({}, state.showChannel, {
|
||||
error: action.data,
|
||||
}),
|
||||
});
|
||||
case actions.CHANNEL_DATA_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
showChannel: Object.assign({}, state.showChannel, {
|
||||
channelData: action.data,
|
||||
}),
|
||||
});
|
||||
case actions.CHANNEL_CLAIMS_DATA_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
showChannel: Object.assign({}, state.showChannel, {
|
||||
channelClaimsData: action.data,
|
||||
}),
|
||||
});
|
||||
// case actions.SHOW_CHANNEL_ERROR:
|
||||
// return Object.assign({}, state, {
|
||||
// showChannel: Object.assign({}, state.showChannel, {
|
||||
// error: action.data,
|
||||
// }),
|
||||
// });
|
||||
// case actions.CHANNEL_DATA_UPDATE:
|
||||
// return Object.assign({}, state, {
|
||||
// showChannel: Object.assign({}, state.showChannel, {
|
||||
// channelData: action.data,
|
||||
// }),
|
||||
// });
|
||||
// case actions.CHANNEL_CLAIMS_DATA_UPDATE:
|
||||
// return Object.assign({}, state, {
|
||||
// showChannel: Object.assign({}, state.showChannel, {
|
||||
// channelClaimsData: action.data,
|
||||
// }),
|
||||
// });
|
||||
// display an asset
|
||||
case actions.FILE_AVAILABILITY_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||
import * as actions from 'constants/show_action_types';
|
||||
import { addAssetRequest, updateShowAsset, updateFileAvailability, updateDisplayAssetError } from 'actions/show';
|
||||
import { addAssetRequest, updateShowAsset, addChannelRequest, updateShowChannel, updateFileAvailability, updateDisplayAssetError } from 'actions/show';
|
||||
import { UNAVAILABLE, AVAILABLE } from 'constants/asset_display_states';
|
||||
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
|
||||
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||
import { getLongChannelClaimId, getShortChannelId, getChannelData } from 'api/channelApi';
|
||||
|
||||
function* newAssetRequest (action) {
|
||||
const { id, name, modifier } = action.data;
|
||||
|
@ -11,7 +12,6 @@ function* newAssetRequest (action) {
|
|||
try {
|
||||
({success, message, data: longId} = yield call(getLongClaimId, name, modifier));
|
||||
} catch (error) {
|
||||
console.log('error making getLongClaimId call', error);
|
||||
yield put(addAssetRequest(id, error.message, name, null));
|
||||
}
|
||||
if (success) {
|
||||
|
@ -20,6 +20,20 @@ function* newAssetRequest (action) {
|
|||
yield put(addAssetRequest(id, message, name, null));
|
||||
};
|
||||
|
||||
function* newChannelRequest (action) {
|
||||
const { id, name, channelId } = action.data;
|
||||
let success, message, longChannelId;
|
||||
try {
|
||||
({success, message, data: longChannelId} = yield call(getLongChannelClaimId, name, channelId));
|
||||
} catch (error) {
|
||||
yield put(addChannelRequest(id, error.message, name, null));
|
||||
}
|
||||
if (success) {
|
||||
return yield put(addChannelRequest(id, null, name, longChannelId));
|
||||
}
|
||||
yield put(addChannelRequest(id, message, name, null));
|
||||
}
|
||||
|
||||
function* getAssetDataAndShowAsset (action) {
|
||||
const {id, name, claimId} = action.data;
|
||||
// if no error, get short Id
|
||||
|
@ -83,6 +97,10 @@ export function* watchNewAssetRequest () {
|
|||
yield takeLatest(actions.NEW_ASSET_REQUEST, newAssetRequest);
|
||||
};
|
||||
|
||||
export function* watchNewChannelRequest () {
|
||||
yield takeLatest(actions.NEW_CHANNEL_REQUEST, newChannelRequest);
|
||||
};
|
||||
|
||||
export function* watchShowNewAsset () {
|
||||
yield takeLatest(actions.SHOW_NEW_ASSET, getAssetDataAndShowAsset);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue