-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow sharing photos from the chat log #653
Changes from all commits
c10cb5d
94d057f
6815a01
a717059
6810af7
5e6ba13
34d2c9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import styles from "../assets/stylesheets/presence-log.scss"; | ||
import classNames from "classnames"; | ||
|
||
import { share } from "../utils/share"; | ||
import { getLandingPageForPhoto } from "../utils/phoenix-utils"; | ||
|
||
export default function PhotoMessage({ name, body: { src: url }, className, maySpawn, hubId }) { | ||
const landingPageUrl = getLandingPageForPhoto(url); | ||
const onShareClicked = share.bind(null, { | ||
url: landingPageUrl, | ||
title: `Taken in #hubs, join me at https://hub.link/${hubId}` | ||
}); | ||
return ( | ||
<div className={className}> | ||
{maySpawn && <button className={classNames(styles.iconButton, styles.share)} onClick={onShareClicked} />} | ||
<div className={styles.mediaBody}> | ||
<span> | ||
<b>{name}</b> | ||
</span> | ||
<span> | ||
{"took a "} | ||
<b> | ||
<a href={landingPageUrl} target="_blank" rel="noopener noreferrer"> | ||
photo | ||
</a> | ||
</b>. | ||
</span> | ||
</div> | ||
<a href={landingPageUrl} target="_blank" rel="noopener noreferrer"> | ||
<img src={url} /> | ||
</a> | ||
</div> | ||
); | ||
} | ||
PhotoMessage.propTypes = { | ||
name: PropTypes.string, | ||
maySpawn: PropTypes.bool, | ||
body: PropTypes.object, | ||
className: PropTypes.string, | ||
hubId: PropTypes.string | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Wraps navigator.share with a fallback to twitter for unsupported browsers | ||
*/ | ||
export function share(opts) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh I figured there might be other share utils at some point |
||
if (navigator.share) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a comment |
||
return navigator.share(opts); | ||
} else { | ||
const { title, url } = opts; | ||
const width = 550; | ||
const height = 420; | ||
const left = (screen.width - width) / 2; | ||
const top = (screen.height - height) / 2; | ||
const params = `scrollbars=no,menubar=no,toolbar=no,status=no,width=${width},height=${height},top=${top},left=${left}`; | ||
const tweetLink = `https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent( | ||
title | ||
)}`; | ||
window.open(tweetLink, "_blank", params); | ||
return Promise.resolve(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have written this to be
onClick=() => this.shareClicked(shortLink)
but this is probably OK -- i find i don't usebind
anymore due to the property syntax. (currying the second arg is interesting tho, very FP :))