finished onNewChannelRequest
This commit is contained in:
parent
8672f7f41a
commit
2363fe8717
8 changed files with 67 additions and 95 deletions
|
@ -82,10 +82,10 @@ export function newChannelRequest (id, name, channelId) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function addChannelRequest (id, error, name, claimId) {
|
export function addChannelRequest (id, error, name, data) {
|
||||||
return {
|
return {
|
||||||
type: actions.CHANNEL_REQUEST_ADD,
|
type: actions.CHANNEL_REQUEST_ADD,
|
||||||
data: { id, error, name, claimId },
|
data: { id, error, name, data },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,12 +105,11 @@ export function addChannelRequest (id, error, name, claimId) {
|
||||||
// };
|
// };
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
export function clearShowChannel () {
|
||||||
// return {
|
return {
|
||||||
// type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
type: actions.SHOW_CHANNEL_CLEAR,
|
||||||
// data: { claims, currentPage, totalPages, totalClaims },
|
};
|
||||||
// };
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
// display a file
|
// display a file
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,14 @@
|
||||||
import Request from 'utils/request';
|
import Request from 'utils/request';
|
||||||
|
import request from '../utils/request';
|
||||||
|
|
||||||
export function getLongChannelClaimId (name, modifier) {
|
export function getChannelData (name, id) {
|
||||||
let body = {};
|
console.log('getting and storing channel data for channel:', name, id);
|
||||||
// create request params
|
if (!id) id = 'none';
|
||||||
if (modifier) {
|
const url = `/api/channel/data/${name}/${id}`;
|
||||||
if (modifier.id) {
|
return request(url)
|
||||||
body['claimId'] = modifier.id;
|
|
||||||
} else {
|
|
||||||
body['channelName'] = modifier.channel.name;
|
|
||||||
body['channelClaimId'] = modifier.channel.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body['claimName'] = name;
|
|
||||||
const params = {
|
|
||||||
method : 'POST',
|
|
||||||
headers: new Headers({
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
}),
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
}
|
|
||||||
// crate url
|
|
||||||
const url = `/api/claim/long-id`;
|
|
||||||
// return the request promise
|
|
||||||
return Request(url, params);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getShortChannelId (name, claimId) {
|
export function getChannelClaims (name, claimId) {
|
||||||
const url = `/api/claim/short-id/${claimId}/${name}`;
|
|
||||||
return Request(url);
|
|
||||||
};
|
|
||||||
|
|
||||||
export function getChannelData (name, claimId) {
|
|
||||||
const url = `/api/claim/data/${name}/${claimId}`;
|
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,9 +16,12 @@ export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
|
||||||
// new
|
// new
|
||||||
export const NEW_ASSET_REQUEST = 'NEW_ASSET_REQUEST';
|
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 NEW_CHANNEL_REQUEST = 'NEW_CHANNEL_REQUEST';
|
||||||
export const CHANNEL_REQUEST_ADD = 'CHANNEL_REQUEST_ADD';
|
export const CHANNEL_REQUEST_ADD = 'CHANNEL_REQUEST_ADD';
|
||||||
|
|
||||||
|
export const SHOW_NEW_CHANNEL = 'SHOW_NEW_CHANNEL';
|
||||||
|
export const SHOW_CHANNEL_CLEAR = 'SHOW_CHANNEL_CLEAR';
|
||||||
|
|
|
@ -22,7 +22,7 @@ class ShowAsset extends React.Component {
|
||||||
// if the component received new assetRequests, check again to see if the current request matches one
|
// if the component received new assetRequests, check again to see if the current request matches one
|
||||||
if (assetRequests[requestId]) { // case: the assetRequest exists
|
if (assetRequests[requestId]) { // case: the assetRequest exists
|
||||||
const request = assetRequests[requestId];
|
const request = assetRequests[requestId];
|
||||||
this.onRepeatRequest(requestId, request);
|
this.onRepeatRequest(request);
|
||||||
} else { // case: the asset request does not exist
|
} else { // case: the asset request does not exist
|
||||||
this.onNewRequest(requestId, requestName, requestModifier);
|
this.onNewRequest(requestId, requestName, requestModifier);
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,18 @@ class ShowAsset extends React.Component {
|
||||||
console.log('new request');
|
console.log('new request');
|
||||||
this.props.onNewRequest(id, requestName, requestModifier);
|
this.props.onNewRequest(id, requestName, requestModifier);
|
||||||
}
|
}
|
||||||
onRepeatRequest (requestId, request) {
|
onRepeatRequest ({ error, name, claimId }) {
|
||||||
console.log('repeat request');
|
console.log('repeat request');
|
||||||
const { assets } = this.props;
|
|
||||||
const { error: requestError, name, claimId } = request;
|
|
||||||
// if error, return and update state with error
|
// if error, return and update state with error
|
||||||
if (requestError) {
|
if (error) {
|
||||||
return this.props.onRequestError(requestError);
|
return this.props.onRequestError(error);
|
||||||
}
|
}
|
||||||
// update the showAsset data in the store
|
// update the showAsset data in the store
|
||||||
|
const { assets } = this.props;
|
||||||
const assetId = `a#${name}#${claimId}`;
|
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: assetError, name, claimId, shortId, claimData } = assets[assetId];
|
||||||
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
this.props.onShowExistingAsset(assetId, assetError, name, claimId, shortId, claimData);
|
||||||
} else { // case: the asset data does not exist yet
|
} else { // case: the asset data does not exist yet
|
||||||
this.props.onShowNewAsset(assetId, name, claimId);
|
this.props.onShowNewAsset(assetId, name, claimId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {newChannelRequest, updateRequestError} from 'actions/show';
|
import {newChannelRequest, updateRequestError, clearShowChannel} from 'actions/show';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
|
@ -19,6 +19,15 @@ const mapStateToProps = ({ show }) => {
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
|
onNewChannelRequest (id, name, channelId) {
|
||||||
|
dispatch(newChannelRequest(id, name, channelId));
|
||||||
|
},
|
||||||
|
onRequestError: (error) => {
|
||||||
|
dispatch(updateRequestError(error, null, null));
|
||||||
|
},
|
||||||
|
onShowChannelClear: () => {
|
||||||
|
dispatch(clearShowChannel());
|
||||||
|
},
|
||||||
// onShowChannelError: (error) => {
|
// onShowChannelError: (error) => {
|
||||||
// dispatch(updateShowChannelError(error));
|
// dispatch(updateShowChannelError(error));
|
||||||
// },
|
// },
|
||||||
|
@ -26,16 +35,6 @@ const mapDispatchToProps = dispatch => {
|
||||||
// dispatch(updateChannelData(name, longId, shortId));
|
// dispatch(updateChannelData(name, longId, shortId));
|
||||||
// dispatch(updateShowChannelError(null)); // clear any errors
|
// dispatch(updateShowChannelError(null)); // clear any errors
|
||||||
// },
|
// },
|
||||||
// onChannelDataClear: () => {
|
|
||||||
// dispatch(updateChannelData(null, null, null));
|
|
||||||
// },
|
|
||||||
// new
|
|
||||||
onNewChannelRequest (id, name, channelId) {
|
|
||||||
dispatch(newChannelRequest(id, name, channelId));
|
|
||||||
},
|
|
||||||
onRequestError: (error) => {
|
|
||||||
dispatch(updateRequestError(error, null, null));
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
||||||
import ErrorPage from 'components/ErrorPage';
|
import ErrorPage from 'components/ErrorPage';
|
||||||
import NavBar from 'containers/NavBar';
|
import NavBar from 'containers/NavBar';
|
||||||
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||||
import request from 'utils/request';
|
|
||||||
|
|
||||||
import { CHANNEL } from 'constants/show_request_types';
|
import { CHANNEL } from 'constants/show_request_types';
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ class ShowChannel extends React.Component {
|
||||||
if (existingRequest(requestId, requestList)) {
|
if (existingRequest(requestId, requestList)) {
|
||||||
// const validRequest = existingRequest(requestId, requestList);
|
// const validRequest = existingRequest(requestId, requestList);
|
||||||
// this.onRepeatChannelRequest(validRequest);
|
// this.onRepeatChannelRequest(validRequest);
|
||||||
console.log('weird, we got a repeat channel request on an unmounted ShowChannel component');
|
console.log('we got a repeat channel request on an unmounted ShowChannel component');
|
||||||
} else {
|
} else {
|
||||||
this.onNewChannelRequest(requestId, requestName, requestChannelId);
|
this.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +37,7 @@ class ShowChannel extends React.Component {
|
||||||
const request = requestList[requestId];
|
const request = requestList[requestId];
|
||||||
this.onRepeatChannelRequest(request);
|
this.onRepeatChannelRequest(request);
|
||||||
} else {
|
} else {
|
||||||
console.log('weird, we got a new channel request on a mounted ShowChannel component');
|
console.log('we got a new channel request on a mounted ShowChannel component');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -52,30 +51,14 @@ class ShowChannel extends React.Component {
|
||||||
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||||
}
|
}
|
||||||
onRepeatChannelRequest ({ id, error, name, claimId }) {
|
onRepeatChannelRequest ({ id, error, name, claimId }) {
|
||||||
// if error, return early (set the request error in the store)
|
// if error, return and update state with error
|
||||||
// if the request is valid...
|
if (error) {
|
||||||
// update showChannel to reflect the channel details
|
return this.props.onRequestError(error);
|
||||||
// see if they are available
|
|
||||||
// retrieve them if they are not available
|
|
||||||
}
|
}
|
||||||
getAndStoreChannelData (name, id) {
|
// if no error, get the channel's claims data
|
||||||
console.log('getting and storing channel data for channel:', name, id);
|
|
||||||
if (!id) id = 'none';
|
|
||||||
const url = `/api/channel/data/${name}/${id}`;
|
|
||||||
return request(url)
|
|
||||||
.then(({ success, message, data }) => {
|
|
||||||
console.log('api/channel/data/ response:', data);
|
|
||||||
if (!success) {
|
|
||||||
return this.props.onShowChannelError(message);
|
|
||||||
}
|
|
||||||
this.props.onChannelDataUpdate(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
return this.props.onShowChannelError(error.message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.props.onChannelDataClear();
|
this.props.onShowChannelClear();
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
const { error, name, longId, shortId } = this.props;
|
const { error, name, longId, shortId } = this.props;
|
||||||
|
|
|
@ -126,7 +126,7 @@ export default function (state = initialState, action) {
|
||||||
[action.data.id]: {
|
[action.data.id]: {
|
||||||
error: action.data.error,
|
error: action.data.error,
|
||||||
name : action.data.name,
|
name : action.data.name,
|
||||||
claimId: action.data.claimId,
|
data : action.data.data,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -143,12 +143,22 @@ export default function (state = initialState, action) {
|
||||||
// channelData: action.data,
|
// channelData: action.data,
|
||||||
// }),
|
// }),
|
||||||
// });
|
// });
|
||||||
// case actions.CHANNEL_CLAIMS_DATA_UPDATE:
|
case actions.SHOW_CHANNEL_CLEAR:
|
||||||
// return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
// showChannel: Object.assign({}, state.showChannel, {
|
showChannel: {
|
||||||
// channelClaimsData: action.data,
|
error : null,
|
||||||
// }),
|
channelData: {
|
||||||
// });
|
name : null,
|
||||||
|
shortId: null,
|
||||||
|
longId : null,
|
||||||
|
},
|
||||||
|
channelClaimsData: {
|
||||||
|
claims : null,
|
||||||
|
currentPage: null,
|
||||||
|
totalPages : null,
|
||||||
|
totalClaims: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
// display an asset
|
// display an asset
|
||||||
case actions.FILE_AVAILABILITY_UPDATE:
|
case actions.FILE_AVAILABILITY_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { addAssetRequest, updateShowAsset, addChannelRequest, updateShowChannel,
|
||||||
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';
|
import { getChannelData, getChannelClaims } from 'api/channelApi';
|
||||||
|
|
||||||
function* newAssetRequest (action) {
|
function* newAssetRequest (action) {
|
||||||
const { id, name, modifier } = action.data;
|
const { id, name, modifier } = action.data;
|
||||||
|
@ -22,14 +22,15 @@ function* newAssetRequest (action) {
|
||||||
|
|
||||||
function* newChannelRequest (action) {
|
function* newChannelRequest (action) {
|
||||||
const { id, name, channelId } = action.data;
|
const { id, name, channelId } = action.data;
|
||||||
let success, message, longChannelId;
|
let success, message, data;
|
||||||
try {
|
try {
|
||||||
({success, message, data: longChannelId} = yield call(getLongChannelClaimId, name, channelId));
|
({success, message, data} = yield call(getChannelData, name, channelId));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
yield put(addChannelRequest(id, error.message, name, null));
|
yield put(addChannelRequest(id, error.message, name, null));
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
return yield put(addChannelRequest(id, null, name, longChannelId));
|
console.log('api/channel/data/ response:', data);
|
||||||
|
return yield put(addChannelRequest(id, null, name, data));
|
||||||
}
|
}
|
||||||
yield put(addChannelRequest(id, message, name, null));
|
yield put(addChannelRequest(id, message, name, null));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue