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
|
// 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
|
// show a channel
|
||||||
|
|
||||||
export function updateShowChannelError (error) {
|
// export function updateShowChannelError (error) {
|
||||||
return {
|
// return {
|
||||||
type: actions.SHOW_CHANNEL_ERROR,
|
// type: actions.SHOW_CHANNEL_ERROR,
|
||||||
data: error,
|
// data: error,
|
||||||
};
|
// };
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
export function updateChannelData (name, longId, shortId) {
|
// export function updateChannelData (name, longId, shortId) {
|
||||||
return {
|
// return {
|
||||||
type: actions.CHANNEL_DATA_UPDATE,
|
// type: actions.CHANNEL_DATA_UPDATE,
|
||||||
data: { name, longId, shortId },
|
// data: { name, longId, shortId },
|
||||||
};
|
// };
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
// export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
||||||
return {
|
// return {
|
||||||
type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
// type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
||||||
data: { claims, currentPage, totalPages, totalClaims },
|
// data: { claims, currentPage, totalPages, totalClaims },
|
||||||
};
|
// };
|
||||||
};
|
// };
|
||||||
|
|
||||||
// display a file
|
// display a file
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Request from 'utils/request';
|
import Request from 'utils/request';
|
||||||
|
|
||||||
export function getLongClaimId (name, modifier) {
|
export function getLongChannelClaimId (name, modifier) {
|
||||||
let body = {};
|
let body = {};
|
||||||
// create request params
|
// create request params
|
||||||
if (modifier) {
|
if (modifier) {
|
||||||
|
@ -25,12 +25,12 @@ export function getLongClaimId (name, modifier) {
|
||||||
return Request(url, params);
|
return Request(url, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getShortId (name, claimId) {
|
export function getShortChannelId (name, claimId) {
|
||||||
const url = `/api/claim/short-id/${claimId}/${name}`;
|
const url = `/api/claim/short-id/${claimId}/${name}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getClaimData (name, claimId) {
|
export function getChannelData (name, claimId) {
|
||||||
const url = `/api/claim/data/${name}/${claimId}`;
|
const url = `/api/claim/data/${name}/${claimId}`;
|
||||||
return Request(url);
|
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 ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
|
||||||
export const SHOW_NEW_ASSET = 'SHOW_NEW_ASSET';
|
export const SHOW_NEW_ASSET = 'SHOW_NEW_ASSET';
|
||||||
export const SHOW_ASSET_CLEAR = 'SHOW_ASSET_CLEAR';
|
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');
|
console.log('repeat request');
|
||||||
const { assets } = this.props;
|
const { assets } = this.props;
|
||||||
const { error: requestError, name, claimId } = request;
|
const { error: requestError, name, claimId } = request;
|
||||||
const assetId = `a#${name}#${claimId}`;
|
|
||||||
// if error, return and update state with error
|
// if error, return and update state with error
|
||||||
if (requestError) {
|
if (requestError) {
|
||||||
return this.props.onRequestError(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
|
if (assets[assetId]) { // case: the asset data already exists
|
||||||
let { error, name, claimId, shortId, claimData } = assets[assetId];
|
let { error, name, claimId, shortId, claimData } = assets[assetId];
|
||||||
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {updateChannelData, updateShowChannelError} from 'actions/show';
|
import {newChannelRequest, updateRequestError} from 'actions/show';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
requestId : show.request.id,
|
requestId : show.request.id,
|
||||||
|
requestType : show.request.type,
|
||||||
requestChannelName: show.request.data.name,
|
requestChannelName: show.request.data.name,
|
||||||
requestChannelId : show.request.data.id,
|
requestChannelId : show.request.data.id,
|
||||||
|
requestList : show.channelRequests,
|
||||||
|
channels : show.channels,
|
||||||
error : show.showChannel.error,
|
error : show.showChannel.error,
|
||||||
name : show.showChannel.channelData.name,
|
name : show.showChannel.channelData.name,
|
||||||
shortId : show.showChannel.channelData.shortId,
|
shortId : show.showChannel.channelData.shortId,
|
||||||
|
@ -16,15 +19,22 @@ const mapStateToProps = ({ show }) => {
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
onShowChannelError: (error) => {
|
// onShowChannelError: (error) => {
|
||||||
dispatch(updateShowChannelError(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) => {
|
onRequestError: (error) => {
|
||||||
dispatch(updateChannelData(name, longId, shortId));
|
dispatch(updateRequestError(error, null, null));
|
||||||
dispatch(updateShowChannelError(null)); // clear any errors
|
|
||||||
},
|
|
||||||
onChannelDataClear: () => {
|
|
||||||
dispatch(updateChannelData(null, null, null));
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,17 +4,59 @@ import NavBar from 'containers/NavBar';
|
||||||
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||||
import request from 'utils/request';
|
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 {
|
class ShowChannel extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
console.log('showchannel did mount');
|
console.log('showchannel did mount');
|
||||||
const {requestChannelName, requestChannelId} = this.props;
|
const {requestId, requestName, requestChannelId, requestList} = this.props;
|
||||||
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
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) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.channelRequests !== this.props.channelRequests) {
|
console.log('showchannel will receive new props');
|
||||||
const {requestChannelName, requestChannelId} = nextProps;
|
if (requestIsAChannelRequest(nextProps) && channelNameOrIdChanged(nextProps, this.props)) {
|
||||||
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
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) {
|
getAndStoreChannelData (name, id) {
|
||||||
console.log('getting and storing channel data for channel:', name, id);
|
console.log('getting and storing channel data for channel:', name, id);
|
||||||
|
|
|
@ -9,21 +9,6 @@ const initialState = {
|
||||||
data : null,
|
data : null,
|
||||||
requestId: null,
|
requestId: null,
|
||||||
},
|
},
|
||||||
// channelRequest: {
|
|
||||||
// name: null,
|
|
||||||
// id : null,
|
|
||||||
// },
|
|
||||||
// assetRequest: {
|
|
||||||
// name : null,
|
|
||||||
// modifier: {
|
|
||||||
// id : null,
|
|
||||||
// channel: {
|
|
||||||
// name: null,
|
|
||||||
// id : null,
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// extension: null,
|
|
||||||
// },
|
|
||||||
showChannel: {
|
showChannel: {
|
||||||
error : null,
|
error : null,
|
||||||
channelData: {
|
channelData: {
|
||||||
|
@ -135,26 +120,35 @@ export default function (state = initialState, action) {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
// request a channel
|
// 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
|
// show a channel
|
||||||
case actions.SHOW_CHANNEL_ERROR:
|
// case actions.SHOW_CHANNEL_ERROR:
|
||||||
return Object.assign({}, state, {
|
// return Object.assign({}, state, {
|
||||||
showChannel: Object.assign({}, state.showChannel, {
|
// showChannel: Object.assign({}, state.showChannel, {
|
||||||
error: action.data,
|
// error: action.data,
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
case actions.CHANNEL_DATA_UPDATE:
|
// case actions.CHANNEL_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
// return Object.assign({}, state, {
|
||||||
showChannel: Object.assign({}, state.showChannel, {
|
// showChannel: Object.assign({}, state.showChannel, {
|
||||||
channelData: action.data,
|
// channelData: action.data,
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
case actions.CHANNEL_CLAIMS_DATA_UPDATE:
|
// case actions.CHANNEL_CLAIMS_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
// return Object.assign({}, state, {
|
||||||
showChannel: Object.assign({}, state.showChannel, {
|
// showChannel: Object.assign({}, state.showChannel, {
|
||||||
channelClaimsData: action.data,
|
// channelClaimsData: action.data,
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
// display an asset
|
// display an asset
|
||||||
case actions.FILE_AVAILABILITY_UPDATE:
|
case actions.FILE_AVAILABILITY_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
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 { 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 { UNAVAILABLE, AVAILABLE } from 'constants/asset_display_states';
|
||||||
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
|
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
|
||||||
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||||
|
import { getLongChannelClaimId, getShortChannelId, getChannelData } from 'api/channelApi';
|
||||||
|
|
||||||
function* newAssetRequest (action) {
|
function* newAssetRequest (action) {
|
||||||
const { id, name, modifier } = action.data;
|
const { id, name, modifier } = action.data;
|
||||||
|
@ -11,7 +12,6 @@ function* newAssetRequest (action) {
|
||||||
try {
|
try {
|
||||||
({success, message, data: longId} = yield call(getLongClaimId, name, modifier));
|
({success, message, data: longId} = yield call(getLongClaimId, name, modifier));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error making getLongClaimId call', error);
|
|
||||||
yield put(addAssetRequest(id, error.message, name, null));
|
yield put(addAssetRequest(id, error.message, name, null));
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -20,6 +20,20 @@ function* newAssetRequest (action) {
|
||||||
yield put(addAssetRequest(id, message, name, null));
|
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) {
|
function* getAssetDataAndShowAsset (action) {
|
||||||
const {id, name, claimId} = action.data;
|
const {id, name, claimId} = action.data;
|
||||||
// if no error, get short Id
|
// if no error, get short Id
|
||||||
|
@ -83,6 +97,10 @@ export function* watchNewAssetRequest () {
|
||||||
yield takeLatest(actions.NEW_ASSET_REQUEST, newAssetRequest);
|
yield takeLatest(actions.NEW_ASSET_REQUEST, newAssetRequest);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function* watchNewChannelRequest () {
|
||||||
|
yield takeLatest(actions.NEW_CHANNEL_REQUEST, newChannelRequest);
|
||||||
|
};
|
||||||
|
|
||||||
export function* watchShowNewAsset () {
|
export function* watchShowNewAsset () {
|
||||||
yield takeLatest(actions.SHOW_NEW_ASSET, getAssetDataAndShowAsset);
|
yield takeLatest(actions.SHOW_NEW_ASSET, getAssetDataAndShowAsset);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue