updated how new channel requests are stored
This commit is contained in:
parent
61d5feee82
commit
e1f07e27ee
8 changed files with 53 additions and 31 deletions
|
@ -82,10 +82,10 @@ export function newChannelRequest (id, name, channelId) {
|
|||
};
|
||||
};
|
||||
|
||||
export function addChannelRequest (id, error, data) {
|
||||
export function addChannelRequest (id, error, name, longId, shortId) {
|
||||
return {
|
||||
type: actions.CHANNEL_REQUEST_ADD,
|
||||
data: { id, error, data },
|
||||
data: { id, error, name, longId, shortId },
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@ const mapStateToProps = ({ show }) => {
|
|||
error : show.showAsset.error,
|
||||
name : show.showAsset.name,
|
||||
claimData : show.showAsset.claimData,
|
||||
// test
|
||||
showAsset : show.assets[show.request.id],
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class ShowAsset extends React.Component {
|
|||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
// case where componentDidMount triggered new props
|
||||
if (requestIsAnAssetRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
|
||||
if (requestIsNewRequest(nextProps, this.props)) {
|
||||
const { requestId, requestName, requestModifier, assetRequests } = nextProps;
|
||||
const existingRequest = assetRequests[requestId];
|
||||
if (existingRequest) { // case: the assetRequest exists
|
||||
|
@ -34,7 +34,7 @@ class ShowAsset extends React.Component {
|
|||
this.onNewRequest(requestId, requestName, requestModifier);
|
||||
}
|
||||
} else {
|
||||
console.log('show.assetRequests did not update');
|
||||
console.log('show.assetRequestId did not update');
|
||||
}
|
||||
}
|
||||
onNewRequest (id, requestName, requestModifier) {
|
||||
|
@ -52,13 +52,18 @@ class ShowAsset extends React.Component {
|
|||
const assetId = `a#${name}#${claimId}`;
|
||||
const existingAssetRecord = assets[assetId];
|
||||
if (existingAssetRecord) { // case: the asset data already exists
|
||||
let { error: assetError, name, claimId, shortId, claimData } = existingAssetRecord;
|
||||
this.props.onShowExistingAsset(assetId, assetError, name, claimId, shortId, claimData);
|
||||
this.showExistingAsset(assetId, existingAssetRecord);
|
||||
} else { // case: the asset data does not exist yet
|
||||
console.log('error: there should be an existing record');
|
||||
// this.props.onShowNewAsset(assetId, name, claimId);
|
||||
this.showNewAsset(assetId, name, claimId);
|
||||
}
|
||||
}
|
||||
showNewAsset (assetId, name, claimId) {
|
||||
this.props.onShowNewAsset(assetId, name, claimId);
|
||||
}
|
||||
showExistingAsset (assetId, existingAssetRecord) {
|
||||
let { error, name, claimId, shortId, claimData } = existingAssetRecord;
|
||||
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
||||
}
|
||||
componentWillUnmount () {
|
||||
this.props.onLeaveShowAsset();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ const mapStateToProps = ({ show }) => {
|
|||
requestChannelName: show.request.data.name,
|
||||
requestChannelId : show.request.data.id,
|
||||
requestList : show.channelRequests,
|
||||
channels : show.channels,
|
||||
channelList : show.channels,
|
||||
// show channel
|
||||
error : show.showChannel.error,
|
||||
name : show.showChannel.channelData.name,
|
||||
|
|
|
@ -15,20 +15,20 @@ function requestIsNewRequest (nextProps, props) {
|
|||
|
||||
class ShowChannel extends React.Component {
|
||||
componentDidMount () {
|
||||
const {requestId, requestChannelName, requestChannelId, requestList} = this.props;
|
||||
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = this.props;
|
||||
const existingRequest = requestList[requestId];
|
||||
if (existingRequest) {
|
||||
this.onRepeatChannelRequest(existingRequest);
|
||||
this.onRepeatChannelRequest(existingRequest, channelList);
|
||||
} else {
|
||||
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
|
||||
const {requestId, requestChannelName, requestChannelId, requestList} = nextProps;
|
||||
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = nextProps;
|
||||
const existingRequest = requestList[requestId];
|
||||
if (existingRequest) {
|
||||
this.onRepeatChannelRequest(existingRequest);
|
||||
this.onRepeatChannelRequest(existingRequest, channelList);
|
||||
} else {
|
||||
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
|
@ -38,13 +38,25 @@ class ShowChannel extends React.Component {
|
|||
console.log('new request');
|
||||
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||
}
|
||||
onRepeatChannelRequest ({ id, error, data: { channelName, longChannelClaimId} }) {
|
||||
onRepeatChannelRequest ({ id, error, channelData: { channelName, longChannelClaimId} }, channelList) {
|
||||
// if error, return and update state with error
|
||||
if (error) {
|
||||
return this.props.onRequestError(error);
|
||||
}
|
||||
// if no error, get the channel's claims data
|
||||
// check if the channel data is present or not
|
||||
const existingChannel = channelList[id];
|
||||
if (existingChannel) {
|
||||
showExistingChannel();
|
||||
} else {
|
||||
showNewChannel();
|
||||
}
|
||||
}
|
||||
showNewChannel () {
|
||||
|
||||
};
|
||||
showExistingChannel () {
|
||||
|
||||
};
|
||||
componentWillUnmount () {
|
||||
this.props.onShowChannelClear();
|
||||
}
|
||||
|
|
|
@ -124,8 +124,12 @@ export default function (state = initialState, action) {
|
|||
return Object.assign({}, state, {
|
||||
channelRequests: Object.assign({}, state.channelRequests, {
|
||||
[action.data.id]: {
|
||||
error: action.data.error,
|
||||
data : action.data.data,
|
||||
error : action.data.error,
|
||||
channelData: {
|
||||
name : action.data.name,
|
||||
longId : action.data.longId,
|
||||
shortId: action.data.shortId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
|
|
@ -16,7 +16,8 @@ function* newAssetRequest (action) {
|
|||
}
|
||||
if (success) {
|
||||
yield put(addAssetRequest(id, null, name, longId));
|
||||
return yield put(showNewAsset(id, name, longId));
|
||||
const newAssetId = `a#${name}#${longId}`; // note move to action
|
||||
return yield put(showNewAsset(newAssetId, name, longId));
|
||||
}
|
||||
yield put(addAssetRequest(id, message, name, null));
|
||||
};
|
||||
|
@ -48,7 +49,7 @@ function* getAssetDataAndShowAsset (action) {
|
|||
yield put(updateShowAsset(id, null, name, claimId, shortId, claimData));
|
||||
}
|
||||
|
||||
function* retriveFile (action) {
|
||||
function* retrieveFile (action) {
|
||||
const name = action.data.name;
|
||||
const claimId = action.data.claimId;
|
||||
// see if the file is available
|
||||
|
@ -86,15 +87,17 @@ function* newChannelRequest (action) {
|
|||
try {
|
||||
({success, message, data} = yield call(getChannelData, name, channelId));
|
||||
} catch (error) {
|
||||
yield put(addChannelRequest(id, error.message, null));
|
||||
yield put(addChannelRequest(id, error.message, null, null, null));
|
||||
}
|
||||
if (success) {
|
||||
console.log('api/channel/data/ response:', data);
|
||||
return yield put(addChannelRequest(id, null, data));
|
||||
const { channelName, longChannelClaimId, shortChannelClaimId } = data;
|
||||
return yield put(addChannelRequest(id, null, channelName, longChannelClaimId, shortChannelClaimId));
|
||||
}
|
||||
yield put(addChannelRequest(id, message, null));
|
||||
yield put(addChannelRequest(id, message, null, null, null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function* watchNewAssetRequest () {
|
||||
yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest);
|
||||
};
|
||||
|
@ -107,6 +110,10 @@ export function* watchShowNewAsset () {
|
|||
yield takeLatest(actions.SHOW_ASSET_NEW, getAssetDataAndShowAsset);
|
||||
};
|
||||
|
||||
export function* watchFileIsRequested () {
|
||||
yield takeLatest(actions.FILE_REQUESTED, retriveFile);
|
||||
export function* watchShowNewChannel () {
|
||||
yield takeLatest(actions.SHOW_ASSET_NEW, getAssetDataAndShowAsset);
|
||||
};
|
||||
|
||||
export function* watchFileIsRequested () {
|
||||
yield takeLatest(actions.FILE_REQUESTED, retrieveFile);
|
||||
};
|
||||
|
|
|
@ -4,7 +4,6 @@ module.exports = {
|
|||
REGEXP_ADDRESS : /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/,
|
||||
CHANNEL_CHAR : '@',
|
||||
parseIdentifier : function (identifier) {
|
||||
console.log('parsing identifier:', identifier);
|
||||
const componentsRegex = new RegExp(
|
||||
'([^:$#/]*)' + // value (stops at the first separator or end)
|
||||
'([:$#]?)([^/]*)' // modifier separator, modifier (stops at the first path separator or end)
|
||||
|
@ -12,7 +11,6 @@ module.exports = {
|
|||
const [proto, value, modifierSeperator, modifier] = componentsRegex
|
||||
.exec(identifier)
|
||||
.map(match => match || null);
|
||||
console.log(`${proto}, ${value}, ${modifierSeperator}, ${modifier}`);
|
||||
|
||||
// Validate and process name
|
||||
if (!value) {
|
||||
|
@ -54,7 +52,6 @@ module.exports = {
|
|||
};
|
||||
},
|
||||
parseClaim: function (name) {
|
||||
console.log('parsing name:', name);
|
||||
const componentsRegex = new RegExp(
|
||||
'([^:$#/.]*)' + // name (stops at the first extension)
|
||||
'([:$#.]?)([^/]*)' // extension separator, extension (stops at the first path separator or end)
|
||||
|
@ -62,7 +59,6 @@ module.exports = {
|
|||
const [proto, claimName, extensionSeperator, extension] = componentsRegex
|
||||
.exec(name)
|
||||
.map(match => match || null);
|
||||
console.log(`${proto}, ${claimName}, ${extensionSeperator}, ${extension}`);
|
||||
|
||||
// Validate and process name
|
||||
if (!claimName) {
|
||||
|
|
Loading…
Reference in a new issue