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 {
|
||||
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) {
|
||||
// return {
|
||||
// type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
|
||||
// data: { claims, currentPage, totalPages, totalClaims },
|
||||
// };
|
||||
// };
|
||||
export function clearShowChannel () {
|
||||
return {
|
||||
type: actions.SHOW_CHANNEL_CLEAR,
|
||||
};
|
||||
};
|
||||
|
||||
// display a file
|
||||
|
||||
|
|
|
@ -1,36 +1,14 @@
|
|||
import Request from 'utils/request';
|
||||
import request from '../utils/request';
|
||||
|
||||
export function getLongChannelClaimId (name, modifier) {
|
||||
let body = {};
|
||||
// create request params
|
||||
if (modifier) {
|
||||
if (modifier.id) {
|
||||
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 getChannelData (name, id) {
|
||||
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)
|
||||
};
|
||||
|
||||
export function getShortChannelId (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}`;
|
||||
export function getChannelClaims (name, claimId) {
|
||||
|
||||
return Request(url);
|
||||
};
|
||||
|
|
|
@ -16,9 +16,12 @@ export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
|
|||
// new
|
||||
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';
|
||||
|
||||
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 (assetRequests[requestId]) { // case: the assetRequest exists
|
||||
const request = assetRequests[requestId];
|
||||
this.onRepeatRequest(requestId, request);
|
||||
this.onRepeatRequest(request);
|
||||
} else { // case: the asset request does not exist
|
||||
this.onNewRequest(requestId, requestName, requestModifier);
|
||||
}
|
||||
|
@ -34,19 +34,18 @@ class ShowAsset extends React.Component {
|
|||
console.log('new request');
|
||||
this.props.onNewRequest(id, requestName, requestModifier);
|
||||
}
|
||||
onRepeatRequest (requestId, request) {
|
||||
onRepeatRequest ({ error, name, claimId }) {
|
||||
console.log('repeat request');
|
||||
const { assets } = this.props;
|
||||
const { error: requestError, name, claimId } = request;
|
||||
// if error, return and update state with error
|
||||
if (requestError) {
|
||||
return this.props.onRequestError(requestError);
|
||||
if (error) {
|
||||
return this.props.onRequestError(error);
|
||||
}
|
||||
// update the showAsset data in the store
|
||||
const { assets } = this.props;
|
||||
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);
|
||||
let { error: assetError, name, claimId, shortId, claimData } = assets[assetId];
|
||||
this.props.onShowExistingAsset(assetId, assetError, name, claimId, shortId, claimData);
|
||||
} else { // case: the asset data does not exist yet
|
||||
this.props.onShowNewAsset(assetId, name, claimId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { connect } from 'react-redux';
|
||||
import {newChannelRequest, updateRequestError} from 'actions/show';
|
||||
import {newChannelRequest, updateRequestError, clearShowChannel} from 'actions/show';
|
||||
import View from './view';
|
||||
|
||||
const mapStateToProps = ({ show }) => {
|
||||
|
@ -19,6 +19,15 @@ const mapStateToProps = ({ show }) => {
|
|||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
onNewChannelRequest (id, name, channelId) {
|
||||
dispatch(newChannelRequest(id, name, channelId));
|
||||
},
|
||||
onRequestError: (error) => {
|
||||
dispatch(updateRequestError(error, null, null));
|
||||
},
|
||||
onShowChannelClear: () => {
|
||||
dispatch(clearShowChannel());
|
||||
},
|
||||
// onShowChannelError: (error) => {
|
||||
// dispatch(updateShowChannelError(error));
|
||||
// },
|
||||
|
@ -26,16 +35,6 @@ const mapDispatchToProps = dispatch => {
|
|||
// 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));
|
||||
},
|
||||
onRequestError: (error) => {
|
||||
dispatch(updateRequestError(error, null, null));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
|||
import ErrorPage from 'components/ErrorPage';
|
||||
import NavBar from 'containers/NavBar';
|
||||
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||
import request from 'utils/request';
|
||||
|
||||
import { CHANNEL } from 'constants/show_request_types';
|
||||
|
||||
|
@ -25,7 +24,7 @@ class ShowChannel extends React.Component {
|
|||
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');
|
||||
console.log('we got a repeat channel request on an unmounted ShowChannel component');
|
||||
} else {
|
||||
this.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ class ShowChannel extends React.Component {
|
|||
const request = requestList[requestId];
|
||||
this.onRepeatChannelRequest(request);
|
||||
} 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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
});
|
||||
// if error, return and update state with error
|
||||
if (error) {
|
||||
return this.props.onRequestError(error);
|
||||
}
|
||||
// if no error, get the channel's claims data
|
||||
}
|
||||
componentWillUnmount () {
|
||||
this.props.onChannelDataClear();
|
||||
this.props.onShowChannelClear();
|
||||
}
|
||||
render () {
|
||||
const { error, name, longId, shortId } = this.props;
|
||||
|
|
|
@ -124,9 +124,9 @@ export default function (state = initialState, action) {
|
|||
return Object.assign({}, state, {
|
||||
channelRequests: Object.assign({}, state.assetRequests, {
|
||||
[action.data.id]: {
|
||||
error : action.data.error,
|
||||
name : action.data.name,
|
||||
claimId: action.data.claimId,
|
||||
error: action.data.error,
|
||||
name : action.data.name,
|
||||
data : action.data.data,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
@ -143,12 +143,22 @@ export default function (state = initialState, action) {
|
|||
// 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_CLEAR:
|
||||
return Object.assign({}, state, {
|
||||
showChannel: {
|
||||
error : null,
|
||||
channelData: {
|
||||
name : null,
|
||||
shortId: null,
|
||||
longId : null,
|
||||
},
|
||||
channelClaimsData: {
|
||||
claims : null,
|
||||
currentPage: null,
|
||||
totalPages : null,
|
||||
totalClaims: null,
|
||||
},
|
||||
});
|
||||
// display an asset
|
||||
case actions.FILE_AVAILABILITY_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { addAssetRequest, updateShowAsset, addChannelRequest, updateShowChannel,
|
|||
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';
|
||||
import { getChannelData, getChannelClaims } from 'api/channelApi';
|
||||
|
||||
function* newAssetRequest (action) {
|
||||
const { id, name, modifier } = action.data;
|
||||
|
@ -22,14 +22,15 @@ function* newAssetRequest (action) {
|
|||
|
||||
function* newChannelRequest (action) {
|
||||
const { id, name, channelId } = action.data;
|
||||
let success, message, longChannelId;
|
||||
let success, message, data;
|
||||
try {
|
||||
({success, message, data: longChannelId} = yield call(getLongChannelClaimId, name, channelId));
|
||||
({success, message, data} = yield call(getChannelData, name, channelId));
|
||||
} catch (error) {
|
||||
yield put(addChannelRequest(id, error.message, name, null));
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue