Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: ModalSocialShare #1943

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/renderer/component/address/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { clipboard } from 'electron';
import { FormRow } from 'component/common/form';
import Button from 'component/button';
import * as icons from 'constants/icons';

/*
noSnackbar added due to issue 1945
https://github.com/lbryio/lbry-desktop/issues/1945
"Snackbars and modals can't be displayed at the same time"
*/
type Props = {
address: string,
noSnackbar: boolean,
doNotify: ({ message: string, displayType: Array<string> }) => void,
};

Expand All @@ -20,7 +25,7 @@ export default class Address extends React.PureComponent<Props> {
input: ?HTMLInputElement;

render() {
const { address, doNotify } = this.props;
const { address, doNotify, noSnackbar } = this.props;

return (
<FormRow verticallyCentered padded stretch>
Expand All @@ -43,10 +48,12 @@ export default class Address extends React.PureComponent<Props> {
icon={icons.CLIPBOARD}
onClick={() => {
clipboard.writeText(address);
doNotify({
message: __('Address copied'),
displayType: ['snackbar'],
});
if (!noSnackbar) {
doNotify({
message: __('Address copied'),
displayType: ['snackbar'],
});
}
}}
/>
</FormRow>
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/component/common/icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Tooltip from 'component/common/tooltip';
// These are copied from `scss/vars`, can they both come from the same source?
const RED_COLOR = '#e2495e';
const GREEN_COLOR = '#44b098';
const BLUE_COLOR = '#49b2e2';

type Props = {
icon: string,
Expand All @@ -33,6 +34,8 @@ class IconComponent extends React.PureComponent<Props> {
return RED_COLOR;
case 'green':
return GREEN_COLOR;
case 'blue':
return BLUE_COLOR;
default:
return undefined;
}
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/component/socialShare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'lbry-redux';
import SocialShare from './view';

const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
});

export default connect(select)(SocialShare);
77 changes: 77 additions & 0 deletions src/renderer/component/socialShare/view.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @flow
import React from 'react';
import type { Claim } from 'types/claim';
import Button from 'component/button';
import * as icons from 'constants/icons';
import Tooltip from 'component/common/tooltip';
import Address from 'component/address';

type Props = {
claim: Claim,
onDone: () => void,
};

class SocialShare extends React.PureComponent<Props> {
constructor(props: Props) {
super(props);

this.input = undefined;
}

input: ?HTMLInputElement;

render() {
const { claim_id: claimId, name: claimName, channel_name: channelName } = this.props.claim;
const { onDone } = this.props;
const speechPrefix = 'http://spee.ch/';
const speechURL = channelName
? `${speechPrefix}${channelName}/${claimName}`
: `${speechPrefix}${claimName}#${claimId}`;

return (
<div>
<div className="card__title">
<h2>{__('Share This Content')}</h2>

<div className="card__content">
<Address address={speechURL} noSnackbar />
</div>
<div className="card__actions card__actions--center">
<Tooltip onComponent body={__('Facebook')}>
<Button
iconColor="blue"
icon={icons.FACEBOOK}
button="alt"
label={__('')}
href={`https://facebook.com/sharer/sharer.php?u=${speechURL}`}
/>
</Tooltip>
<Tooltip onComponent body={__('Twitter')}>
<Button
iconColor="blue"
icon={icons.TWITTER}
button="alt"
label={__('')}
href={`https://twitter.com/home?status=${speechURL}`}
/>
</Tooltip>
<Tooltip onComponent body={__('View on Spee.ch')}>
<Button
icon={icons.GLOBE}
iconColor="blue"
button="alt"
label={__('')}
href={`${speechURL}`}
/>
</Tooltip>
</div>
<div className="card__actions">
<Button button="link" label={__('Done')} onClick={onDone} />
</div>
</div>
</div>
);
}
}

export default SocialShare;
2 changes: 2 additions & 0 deletions src/renderer/constants/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export const EXTERNAL_LINK = 'ExternalLink';
export const GIFT = 'Gift';
export const EYE = 'Eye';
export const PLAY = 'Play';
export const FACEBOOK = 'Facebook';
export const TWITTER = 'Twitter';
9 changes: 6 additions & 3 deletions src/renderer/modal/modalRouter/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import ModalEmailCollection from 'modal/modalEmailCollection';
import ModalPhoneCollection from 'modal/modalPhoneCollection';
import ModalFirstSubscription from 'modal/modalFirstSubscription';
import ModalConfirmTransaction from 'modal/modalConfirmTransaction';
import ModalSendTip from '../modalSendTip';
import ModalPublish from '../modalPublish';
import ModalOpenExternalLink from '../modalOpenExternalLink';
import ModalSocialShare from 'modal/modalSocialShare';
import ModalSendTip from 'modal/modalSendTip';
import ModalPublish from 'modal/modalPublish';
import ModalOpenExternalLink from 'modal/modalOpenExternalLink';
import ModalConfirmThumbnailUpload from 'modal/modalConfirmThumbnailUpload';
import ModalWalletEncrypt from 'modal/modalWalletEncrypt';
import ModalWalletDecrypt from 'modal/modalWalletDecrypt';
Expand Down Expand Up @@ -160,6 +161,8 @@ class ModalRouter extends React.PureComponent<Props> {
return <ModalFirstSubscription {...notificationProps} />;
case MODALS.SEND_TIP:
return <ModalSendTip {...notificationProps} />;
case MODALS.SOCIAL_SHARE:
return <ModalSocialShare {...notificationProps} />;
case MODALS.PUBLISH:
return <ModalPublish {...notificationProps} />;
case MODALS.CONFIRM_EXTERNAL_LINK:
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/modal/modalSocialShare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { connect } from 'react-redux';
import { doHideNotification } from 'lbry-redux';
import ModalSocialShare from './view';

const perform = dispatch => ({
closeModal: () => dispatch(doHideNotification()),
});

export default connect(
null,
perform
)(ModalSocialShare);
22 changes: 22 additions & 0 deletions src/renderer/modal/modalSocialShare/view.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @flow
import React from 'react';
import { Modal } from 'modal/modal';
import SocialShare from 'component/socialShare';

type Props = {
closeModal: () => void,
uri: string,
};

class ModalSocialShare extends React.PureComponent<Props> {
render() {
const { closeModal, uri } = this.props;
return (
<Modal isOpen onAborted={closeModal} type="custom">
<SocialShare uri={uri} onDone={closeModal} />
</Modal>
);
}
}

export default ModalSocialShare;
8 changes: 6 additions & 2 deletions src/renderer/page/file/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import DateTime from 'component/dateTime';
import * as icons from 'constants/icons';
import Button from 'component/button';
import SubscribeButton from 'component/subscribeButton';
import ViewOnWebButton from 'component/viewOnWebButton';
import Page from 'component/page';
import type { Claim } from 'types/claim';
import type { Subscription } from 'types/subscription';
Expand Down Expand Up @@ -224,7 +223,12 @@ class FilePage extends React.Component<Props> {
/>
)}
{speechSharable && (
<ViewOnWebButton claimId={claim.claim_id} claimName={claim.name} />
<Button
button="alt"
icon={icons.GLOBE}
label={__('Share')}
onClick={() => openModal({ id: MODALS.SOCIAL_SHARE }, { uri })}
/>
)}
</div>

Expand Down