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

Add Faithlife social share to share links to faithlife, email, facebook and twitter #50

Merged
merged 7 commits into from
Sep 27, 2018

Conversation

AuresaNyctea
Copy link
Contributor

Not complete: iframing and tabs. Mobile ui and copy button is larger than input.


// Radium automatically prefixes radiumConfig with _
// eslint-disable-next-line no-underscore-dangle
const config = this.context._radiumConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styled-ui doesn't use Radium, so the user agent will have to be obtained through navigator.userAgent. Note that navigator is not defined when SSR so special care will need to be taken if accessing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. i'm unfamiliar with Radium so I tried to remove the usages but missed this one

this.setState({ showFeedback: true });

if (!this.feedbackTimer) {
this.feedbackTimer = setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use a debounced method instead of maintaining a timer in these situations. I find it easier to read and reason about. Something like:

componentWillUnmount() {
	this.hideFeedbackSoon.cancel();
}

hideFeedbackSoon = debounce(() => {
	this.setState({ showFeedback: false });
}, 2000);

copyToClipboard = () => {
	...
	this.hideFeedbackSoon();
	...
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good fit for lodash.debounce

import { Button } from '../button/component.jsx';
// import { isIOSDevice } from '../../helpers/user-agent-helper';

export class CopyToClipboardButton extends React.Component {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should use a more rounded copy library instead of user agent sniffing to try to determine browser support for copying. Maybe clipboard.js? Also, it would be awesome to export this component from styled-ui as well as the ShareDialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shall investigate this :)

import { forwardClassRef } from '../utils/forwardref-wrapper.jsx';
import * as Styled from './styled.jsx';

export const Input = forwardClassRef(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dustinsoftware I added an input, it's pretty simple and I haven't tested it fully yet because I still can't get a ref pointing at it. Could you take a look at this in the am?

@AuresaNyctea
Copy link
Contributor Author

@ianfisk can you take another look at this pr?

const encodedMessage = message ? encodeURIComponent(message) : '';

return (
<Modal renderFooter={() => null} isOpen={isOpen} onClose={onClose} title="Share this page">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new function for every render here may result in unnecessary updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper solution is probably to add a hideFooter to Modal instead of just passing in a null function? I didn't do that because I wasn't sure so maybe @dustinsoftware can chime in here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A withoutFooter prop was added for this purpose very recently.
https://faithlife.github.io/styled-ui/#/modal/documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey I somehow missed that... thanks @awesomebob


export class CopyToClipboard extends React.Component {
static propTypes = {
clipboard: PropTypes.func.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting clipboard as a prop feels unnecessary. I think the fact we are using Clipboard.js is an implementation detail of this component that we don't need to expose like this.

const input = this.input.current;

const Clipboard = this.props.clipboard;
this.clipboard = new Clipboard(button);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instance needs to be cleaned up in componentWillUnmount:

componentWillUnmount() {
  this.clipboard.destroy();
}


constructor(props) {
super(props);
this.input = React.createRef();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a NIT, but I prefer using class fields instead of defining instance variables in a constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Remove the need for the constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly because class fields are new and shiny and it requires less typing. It would also be more consistent with almost all components in styled-ui.

…ok and twitter.

Not complete: iframing and tabs. Mobile ui and copy button is larger than input.
Included: Copy works

Not included: Currently copy doesn't select the text, need to add a check for error and a check for if clipboard isn't supported, I think this will require adding a `ref` to the input which I haven't figured out how to do yet.
@RobertBolender
Copy link
Contributor

Build is passing. @dustinsoftware without objection, I will merge and publish this PR today.

Copy link
Contributor

@dustinsoftware dustinsoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, go ahead and merge and we can do some more improvements soon after :)

@RobertBolender RobertBolender merged commit f5e744e into Faithlife:master Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants