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 ability to resolve share URL using a function #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 14 additions & 5 deletions src/utils/createShareButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class ShareButton extends PureComponent {
onClick: PropTypes.func,
opts: PropTypes.object,
openWindow: PropTypes.bool,
url: PropTypes.string.isRequired,
url: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]).isRequired,
role: PropTypes.string,
style: PropTypes.object,
windowWidth: PropTypes.number,
Expand All @@ -94,7 +97,7 @@ class ShareButton extends PureComponent {
tabIndex: '0',
}

onClick = (e) => {
onClick = async (e) => {
const {
disabled,
onClick,
Expand All @@ -108,7 +111,7 @@ class ShareButton extends PureComponent {

e.preventDefault();

const link = this.link();
const link = await this.link();

const clickHandler = openWindow ? () => this.openWindow(link) : () => onClick(link);

Expand Down Expand Up @@ -151,8 +154,14 @@ class ShareButton extends PureComponent {
windowOpen(link, windowConfig, onShareWindowClose);
}

link() {
const { url, opts, networkLink } = this.props;
async link() {
let { url } = this.props;
const { opts, networkLink } = this.props;

if (typeof url === 'function') {
url = await Promise.resolve(url());
}

return networkLink(url, opts);
}

Expand Down