Refactor claimSupportButton

- Tooltip
- only interested in repost value from claim
This commit is contained in:
Rafael 2022-02-01 17:08:27 -03:00 committed by Thomas Zarebczan
parent 21a5e27cd2
commit c9fbf197f9
2 changed files with 34 additions and 26 deletions

View file

@ -1,14 +1,24 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { makeSelectTagInClaimOrChannelForUri, makeSelectClaimForUri } from 'redux/selectors/claims'; import { makeSelectTagInClaimOrChannelForUri, selectClaimForUri } from 'redux/selectors/claims';
import ClaimSupportButton from './view'; import ClaimSupportButton from './view';
const DISABLE_SUPPORT_TAG = 'disable-support'; const DISABLE_SUPPORT_TAG = 'disable-support';
const select = (state, props) => ({
disableSupport: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state),
claim: makeSelectClaimForUri(props.uri)(state),
});
export default connect(select, { const select = (state, props) => {
const { uri } = props;
const claim = selectClaimForUri(state, uri);
const isRepost = claim && claim.repost_url;
return {
disableSupport: makeSelectTagInClaimOrChannelForUri(uri, DISABLE_SUPPORT_TAG)(state),
isRepost,
};
};
const perform = {
doOpenModal, doOpenModal,
})(ClaimSupportButton); };
export default connect(select, perform)(ClaimSupportButton);

View file

@ -4,33 +4,31 @@ import * as ICONS from 'constants/icons';
import React from 'react'; import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import Button from 'component/button'; import Button from 'component/button';
import Tooltip from 'component/common/tooltip';
type Props = { type Props = {
uri: string, uri: string,
doOpenModal: (string, {}) => void,
fileAction?: boolean, fileAction?: boolean,
// redux
disableSupport: boolean, disableSupport: boolean,
claim: GenericClaim, isRepost?: boolean,
doOpenModal: (id: string, {}) => void,
}; };
export default function ClaimSupportButton(props: Props) { export default function ClaimSupportButton(props: Props) {
const { doOpenModal, uri, fileAction, disableSupport, claim } = props; const { uri, fileAction, isRepost, disableSupport, doOpenModal } = props;
const isRepost = claim && claim.repost_url;
if (disableSupport) { return disableSupport ? null : (
return null; <Tooltip title={__('Support this claim')} arrow={false}>
}
return (
<Button <Button
button={fileAction ? undefined : 'alt'} button={!fileAction && 'alt'}
className={classnames({ 'button--file-action': fileAction })} className={classnames({ 'button--file-action': fileAction })}
icon={ICONS.LBC} icon={ICONS.LBC}
iconSize={fileAction ? 22 : undefined} iconSize={fileAction && 22}
label={isRepost ? __('Support Repost') : __('Support --[button to support a claim]--')} label={isRepost ? __('Support Repost') : __('Support --[button to support a claim]--')}
requiresAuth={IS_WEB} requiresAuth
title={__('Support this claim')}
onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })} onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })}
/> />
</Tooltip>
); );
} }