redirect to channel page if no channels when trying to repost
This commit is contained in:
parent
bf9be7c46d
commit
4f770ec83e
3 changed files with 47 additions and 4 deletions
|
@ -1,6 +1,14 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { makeSelectClaimIsMine, makeSelectFileInfoForUri, makeSelectClaimForUri, doPrepareEdit } from 'lbry-redux';
|
import {
|
||||||
|
makeSelectClaimIsMine,
|
||||||
|
makeSelectFileInfoForUri,
|
||||||
|
makeSelectClaimForUri,
|
||||||
|
doPrepareEdit,
|
||||||
|
selectMyChannelClaims,
|
||||||
|
} from 'lbry-redux';
|
||||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||||
|
import { doSetPlayingUri } from 'redux/actions/content';
|
||||||
|
import { doToast } from 'redux/actions/notifications';
|
||||||
import { doOpenModal } from 'redux/actions/app';
|
import { doOpenModal } from 'redux/actions/app';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import FileActions from './view';
|
import FileActions from './view';
|
||||||
|
@ -12,11 +20,14 @@ const select = (state, props) => ({
|
||||||
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
||||||
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
||||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||||
|
myChannels: selectMyChannelClaims(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||||
prepareEdit: (publishData, uri, fileInfo) => dispatch(doPrepareEdit(publishData, uri, fileInfo, fs)),
|
prepareEdit: (publishData, uri, fileInfo) => dispatch(doPrepareEdit(publishData, uri, fileInfo, fs)),
|
||||||
|
clearPlayingUri: () => dispatch(doSetPlayingUri(null)),
|
||||||
|
doToast: options => dispatch(doToast(options)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(FileActions);
|
export default connect(select, perform)(FileActions);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { SIMPLE_SITE } from 'config';
|
import { SIMPLE_SITE, SITE_NAME } from 'config';
|
||||||
import * as PAGES from 'constants/pages';
|
import * as PAGES from 'constants/pages';
|
||||||
import * as CS from 'constants/claim_search';
|
import * as CS from 'constants/claim_search';
|
||||||
import * as MODALS from 'constants/modal_types';
|
import * as MODALS from 'constants/modal_types';
|
||||||
|
@ -11,6 +11,7 @@ import { buildURI } from 'lbry-redux';
|
||||||
import * as RENDER_MODES from 'constants/file_render_modes';
|
import * as RENDER_MODES from 'constants/file_render_modes';
|
||||||
import { useIsMobile } from 'effects/use-screensize';
|
import { useIsMobile } from 'effects/use-screensize';
|
||||||
import ClaimSupportButton from 'component/claimSupportButton';
|
import ClaimSupportButton from 'component/claimSupportButton';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
|
@ -21,13 +22,33 @@ type Props = {
|
||||||
fileInfo: FileListItem,
|
fileInfo: FileListItem,
|
||||||
costInfo: ?{ cost: number },
|
costInfo: ?{ cost: number },
|
||||||
renderMode: string,
|
renderMode: string,
|
||||||
|
myChannels: ?Array<ChannelClaim>,
|
||||||
|
doToast: ({ message: string }) => void,
|
||||||
|
clearPlayingUri: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileActions(props: Props) {
|
function FileActions(props: Props) {
|
||||||
const { fileInfo, uri, openModal, claimIsMine, claim, costInfo, renderMode, prepareEdit } = props;
|
const {
|
||||||
|
fileInfo,
|
||||||
|
uri,
|
||||||
|
openModal,
|
||||||
|
claimIsMine,
|
||||||
|
claim,
|
||||||
|
costInfo,
|
||||||
|
renderMode,
|
||||||
|
prepareEdit,
|
||||||
|
myChannels,
|
||||||
|
clearPlayingUri,
|
||||||
|
doToast,
|
||||||
|
} = props;
|
||||||
|
const {
|
||||||
|
push,
|
||||||
|
location: { pathname },
|
||||||
|
} = useHistory();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const webShareable = costInfo && costInfo.cost === 0 && RENDER_MODES.WEB_SHAREABLE_MODES.includes(renderMode);
|
const webShareable = costInfo && costInfo.cost === 0 && RENDER_MODES.WEB_SHAREABLE_MODES.includes(renderMode);
|
||||||
const showDelete = claimIsMine || (fileInfo && (fileInfo.written_bytes > 0 || fileInfo.blobs_completed > 0));
|
const showDelete = claimIsMine || (fileInfo && (fileInfo.written_bytes > 0 || fileInfo.blobs_completed > 0));
|
||||||
|
const hasChannels = myChannels && myChannels.length > 0;
|
||||||
const claimId = claim && claim.claim_id;
|
const claimId = claim && claim.claim_id;
|
||||||
const { signing_channel: signingChannel } = claim;
|
const { signing_channel: signingChannel } = claim;
|
||||||
const channelName = signingChannel && signingChannel.name;
|
const channelName = signingChannel && signingChannel.name;
|
||||||
|
@ -47,6 +68,16 @@ function FileActions(props: Props) {
|
||||||
editUri = buildURI(uriObject);
|
editUri = buildURI(uriObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleRepostClick() {
|
||||||
|
if (!hasChannels) {
|
||||||
|
clearPlayingUri();
|
||||||
|
push(`/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`);
|
||||||
|
doToast({ message: __('A channel is required to repost on %SITE_NAME%', { SITE_NAME }) });
|
||||||
|
} else {
|
||||||
|
openModal(MODALS.REPOST, { uri });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const lhsSection = (
|
const lhsSection = (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
|
@ -62,7 +93,7 @@ function FileActions(props: Props) {
|
||||||
icon={ICONS.REPOST}
|
icon={ICONS.REPOST}
|
||||||
label={__('Repost')}
|
label={__('Repost')}
|
||||||
requiresAuth={IS_WEB}
|
requiresAuth={IS_WEB}
|
||||||
onClick={() => openModal(MODALS.REPOST, { uri })}
|
onClick={handleRepostClick}
|
||||||
/>
|
/>
|
||||||
{claim.meta.reposted > 0 && (
|
{claim.meta.reposted > 0 && (
|
||||||
<Button
|
<Button
|
||||||
|
|
|
@ -133,6 +133,7 @@ function ModalRepost(props: Props) {
|
||||||
<SelectChannel
|
<SelectChannel
|
||||||
label={__('Channel to repost on')}
|
label={__('Channel to repost on')}
|
||||||
hideAnon
|
hideAnon
|
||||||
|
hideNew
|
||||||
channel={repostChannel}
|
channel={repostChannel}
|
||||||
onChannelChange={newChannel => setRepostChannel(newChannel)}
|
onChannelChange={newChannel => setRepostChannel(newChannel)}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue