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

Allow sharing photos from the chat log #653

Merged
merged 7 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
Binary file added src/assets/share_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/spawn_message-hover.png
Binary file not shown.
23 changes: 17 additions & 6 deletions src/assets/stylesheets/presence-log.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,38 @@
max-width: 75%;
}

:local(.spawn-message) {
:local(.icon-button) {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
outline-style: none;
width: 24px;
height: 24px;
background-size: 100%;
background-size: 20px;
background-position: center;
background-repeat: no-repeat;
border: 0;
display: flex;
justify-content: center;
align-items: center;
align-self: flex-start;
cursor: pointer;
background-image: url(../spawn_message.png);
margin-right: 6px;
border-radius: 12px;
background-color: transparent;

&:hover {
background-color: $action-color;
}
}

:local(.spawn-message) {
background-image: url(../spawn_message.png);
}

:local(.spawn-message):hover {
background-image: url(../spawn_message-hover.png);
// TODO replace these icons with share button
:local(.share) {
background-image: url(../share_message.png);
}

&:local(.media) {
Expand All @@ -99,7 +110,7 @@

img {
height: 35px;
margin-right: 8px;
margin-left: 8px;
border: 2px solid rgba(255,255,255,0.15);
display: block;
border-radius: 5px;
Expand Down
18 changes: 7 additions & 11 deletions src/react-components/invite-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from "prop-types";
import copy from "copy-to-clipboard";
import classNames from "classnames";
import { FormattedMessage } from "react-intl";
import { share } from "../utils/share";

import styles from "../assets/stylesheets/invite-dialog.scss";

Expand All @@ -25,11 +26,11 @@ export default class InviteDialog extends Component {
shareButtonActive: false
};

shareClicked = link => {
shareClicked = url => {
this.setState({ shareButtonActive: true });
setTimeout(() => this.setState({ shareButtonActive: false }), 5000);

navigator.share({ title: "Join me now in #hubs!", url: link });
share({ url, title: "Join me now in #hubs!" }).then(() => {
this.setState({ shareButtonActive: false });
});
};

copyClicked = link => {
Expand All @@ -46,11 +47,6 @@ export default class InviteDialog extends Component {
const shortLinkText = `hub.link/${this.props.hubId}`;
const shortLink = "https://" + shortLinkText;

const tweetText = `Join me now in #hubs!`;
const tweetLink = `https://twitter.com/share?url=${encodeURIComponent(shortLink)}&text=${encodeURIComponent(
tweetText
)}`;

return (
<div className={styles.dialog}>
<div className={styles.attachPoint} />
Expand Down Expand Up @@ -89,9 +85,9 @@ export default class InviteDialog extends Component {
)}
{this.props.allowShare &&
!navigator.share && (
<a href={tweetLink} className={styles.linkButton} target="_blank" rel="noopener noreferrer">
<button className={styles.linkButton} onClick={this.shareClicked.bind(this, shortLink)}>
Copy link
Contributor

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 use bind anymore due to the property syntax. (currying the second arg is interesting tho, very FP :))

<FormattedMessage id="invite.tweet" />
</a>
</button>
)}
</div>
</div>
Expand Down
74 changes: 54 additions & 20 deletions src/react-components/presence-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,56 @@ import styles from "../assets/stylesheets/presence-log.scss";
import classNames from "classnames";
import { FormattedMessage } from "react-intl";
import ChatMessage from "./chat-message";
import { share } from "../utils/share";

function SpawnPhotoMessage({ name, body: { src: url }, className, maySpawn, hubId }) {
let landingPageUrl = new URL(url);
const [hostname, port] = process.env.RETICULUM_SERVER.split(":");
console.log(hostname, port, landingPageUrl.port);
Copy link
Contributor

Choose a reason for hiding this comment

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

console log

Copy link
Contributor

Choose a reason for hiding this comment

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

I might consider rolling this routine into phoenix-utils.js, its where I've tried to centralize references to RETICULUM_SERVER

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason getReticulumFetchUrl(landingPageUrl.pathname.replace(".png", ".html")) wouldn't work? also might be worth future proofing this for other file extensions by just dropping the file extension instead of assumign .png

landingPageUrl.hostname = hostname;
if (port) landingPageUrl.port = port;
landingPageUrl.pathname = landingPageUrl.pathname.replace(".png", ".html");
landingPageUrl = landingPageUrl.toString();

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>
);
}
SpawnPhotoMessage.propTypes = {
name: PropTypes.string,
maySpawn: PropTypes.bool,
body: PropTypes.object,
className: PropTypes.string,
hubId: PropTypes.string
};
Copy link
Contributor

Choose a reason for hiding this comment

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

chat-message.js is a thing so maybe photo-message.js should be too


export default class PresenceLog extends Component {
static propTypes = {
entries: PropTypes.array,
inRoom: PropTypes.bool
inRoom: PropTypes.bool,
hubId: PropTypes.string
};

constructor(props) {
Expand Down Expand Up @@ -54,26 +99,15 @@ export default class PresenceLog extends Component {
/>
);
case "spawn": {
const { src } = e.body;
return (
<div key={e.key} className={classNames(entryClasses, styles.media)}>
<a href={src} target="_blank" rel="noopener noreferrer">
<img src={src} />
</a>
<div className={styles.mediaBody}>
<span>
<b>{e.name}</b>
</span>
<span>
{"took a "}
<b>
<a href={src} target="_blank" rel="noopener noreferrer">
photo
</a>
</b>.
</span>
</div>
</div>
<SpawnPhotoMessage
key={e.key}
name={e.name}
className={classNames(entryClasses, styles.media)}
body={e.body}
maySpawn={e.maySpawn}
hubId={this.props.hubId}
/>
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/react-components/ui-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,14 @@ class UIRoot extends Component {

{(!entryFinished || this.isWaitingForAutoExit()) && (
<div className={styles.uiDialog}>
<PresenceLog entries={this.props.presenceLogEntries || []} />
<PresenceLog entries={this.props.presenceLogEntries || []} hubId={this.props.hubId} />
<div className={dialogBoxContentsClassNames}>{dialogContents}</div>
</div>
)}

{entryFinished && <PresenceLog inRoom={true} entries={this.props.presenceLogEntries || []} />}
{entryFinished && (
<PresenceLog inRoom={true} entries={this.props.presenceLogEntries || []} hubId={this.props.hubId} />
)}
{entryFinished && (
<form onSubmit={this.sendMessage}>
<div className={styles.messageEntryInRoom} style={{ height: pendingMessageFieldHeight }}>
Expand Down
17 changes: 17 additions & 0 deletions src/utils/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function share(opts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

export default perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a comment
// Use navigator.share otherwise just post to Twitter

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();
}
}