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