2018-02-15 02:40:11 +01:00
|
|
|
import { call, put, takeLatest } from 'redux-saga/effects';
|
2018-02-15 02:26:11 +01:00
|
|
|
import * as actions from 'constants/show_action_types';
|
|
|
|
import { onRequestError, onNewChannelRequest, onNewAssetRequest } from 'actions/show';
|
2018-02-23 00:43:26 +01:00
|
|
|
import { newAssetRequest } from 'sagas/show_asset';
|
|
|
|
import { newChannelRequest } from 'sagas/show_channel';
|
2018-02-15 02:26:11 +01:00
|
|
|
import lbryUri from 'utils/lbryUri';
|
|
|
|
|
2018-02-22 02:02:57 +01:00
|
|
|
function * parseAndUpdateIdentifierAndClaim (modifier, claim) {
|
2018-02-15 02:40:11 +01:00
|
|
|
console.log('parseAndUpdateIdentifierAndClaim');
|
2018-02-15 02:26:11 +01:00
|
|
|
// this is a request for an asset
|
|
|
|
// claim will be an asset claim
|
|
|
|
// the identifier could be a channel or a claim id
|
|
|
|
let isChannel, channelName, channelClaimId, claimId, claimName, extension;
|
|
|
|
try {
|
|
|
|
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(modifier));
|
|
|
|
({ claimName, extension } = lbryUri.parseClaim(claim));
|
|
|
|
} catch (error) {
|
2018-02-15 02:40:11 +01:00
|
|
|
return yield put(onRequestError(error.message));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
|
|
|
// trigger an new action to update the store
|
|
|
|
if (isChannel) {
|
2018-02-23 00:43:26 +01:00
|
|
|
return yield call(newAssetRequest, onNewAssetRequest(claimName, null, channelName, channelClaimId, extension));
|
2018-02-15 02:40:11 +01:00
|
|
|
};
|
2018-02-23 00:43:26 +01:00
|
|
|
yield call(newAssetRequest, onNewAssetRequest(claimName, claimId, null, null, extension));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
2018-02-22 02:02:57 +01:00
|
|
|
function * parseAndUpdateClaimOnly (claim) {
|
2018-02-15 02:40:11 +01:00
|
|
|
console.log('parseAndUpdateIdentifierAndClaim');
|
2018-02-15 02:26:11 +01:00
|
|
|
// this could be a request for an asset or a channel page
|
|
|
|
// claim could be an asset claim or a channel claim
|
|
|
|
let isChannel, channelName, channelClaimId;
|
|
|
|
try {
|
|
|
|
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(claim));
|
|
|
|
} catch (error) {
|
2018-02-15 02:40:11 +01:00
|
|
|
return yield put(onRequestError(error.message));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
|
|
|
// trigger an new action to update the store
|
|
|
|
// return early if this request is for a channel
|
|
|
|
if (isChannel) {
|
2018-02-23 00:43:26 +01:00
|
|
|
return yield call(newChannelRequest, onNewChannelRequest(channelName, channelClaimId));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
|
|
|
// if not for a channel, parse the claim request
|
|
|
|
let claimName, extension;
|
|
|
|
try {
|
|
|
|
({claimName, extension} = lbryUri.parseClaim(claim));
|
|
|
|
} catch (error) {
|
2018-02-15 02:40:11 +01:00
|
|
|
return yield put(onRequestError(error.message));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
2018-02-23 00:43:26 +01:00
|
|
|
yield call(newAssetRequest, onNewAssetRequest(claimName, null, null, null, extension));
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
|
|
|
|
2018-02-23 00:43:26 +01:00
|
|
|
export function * handleShowPageUri (action) {
|
2018-02-15 02:40:11 +01:00
|
|
|
console.log('handleShowPageUri');
|
2018-02-23 00:43:26 +01:00
|
|
|
console.log('action:', action);
|
2018-02-15 02:40:11 +01:00
|
|
|
const { identifier, claim } = action.data;
|
2018-02-15 02:26:11 +01:00
|
|
|
if (identifier) {
|
2018-02-15 02:40:11 +01:00
|
|
|
return yield call(parseAndUpdateIdentifierAndClaim, identifier, claim);
|
2018-02-15 02:26:11 +01:00
|
|
|
}
|
2018-02-15 02:40:11 +01:00
|
|
|
yield call(parseAndUpdateClaimOnly, claim);
|
2018-02-15 02:26:11 +01:00
|
|
|
};
|
|
|
|
|
2018-02-22 02:02:57 +01:00
|
|
|
export function * watchHandleShowPageUri () {
|
2018-02-15 02:26:11 +01:00
|
|
|
yield takeLatest(actions.HANDLE_SHOW_URI, handleShowPageUri);
|
|
|
|
};
|