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

Adds Share button to picture and video items in Chat #6511

Merged
merged 1 commit into from
Oct 31, 2024
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
33 changes: 32 additions & 1 deletion src/react-components/room/ChatSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ReactComponent as WandIcon } from "../icons/Wand.svg";
import { ReactComponent as AttachIcon } from "../icons/Attach.svg";
import { ReactComponent as SendIcon } from "../icons/Send.svg";
import { ReactComponent as ReactionIcon } from "../icons/Reaction.svg";
import { ReactComponent as ShareIcon } from "../icons/Share.svg";
import { IconButton } from "../input/IconButton";
import { TextAreaInput } from "../input/TextAreaInput";
import { Popover } from "../popover/Popover";
Expand All @@ -15,6 +16,8 @@ import styles from "./ChatSidebar.scss";
import { formatMessageBody } from "../../utils/chat-message";
import { FormattedMessage, useIntl, defineMessages, FormattedRelativeTime } from "react-intl";
import { permissionMessage } from "./PermissionNotifications";
import { share } from "../../utils/share";
import configs from "../../utils/configs";

export function SpawnMessageButton(props) {
return (
Expand Down Expand Up @@ -377,7 +380,21 @@ MessageBubble.propTypes = {
permission: PropTypes.bool
};

function getMessageComponent(message) {
function getMessageComponent(message, intl) {
const onShareClick = async () => {
try {
await share({
url: message.body?.src,
title: intl.formatMessage(
{ id: "photo-message.default-tweet", defaultMessage: "Taken in {shareHashtag}" },
{ shareHashtag: configs.translation("share-hashtag") }
)
});
} catch (error) {
console.error(`while sharing (from chat sidebar):`, error);
}
};

switch (message.type) {
case "chat": {
const { formattedBody, monospace, emoji } = formatMessageBody(message.body);
Expand All @@ -391,13 +408,27 @@ function getMessageComponent(message) {
return (
<MessageBubble key={message.id} media>
<video controls src={message.body.src} />
<IconButton
className={styles.iconButton}
onClick={onShareClick}
title={intl.formatMessage({ id: "share-popover.title", defaultMessage: "Share" })}
>
<ShareIcon />
</IconButton>
</MessageBubble>
);
case "image":
case "photo":
return (
<MessageBubble key={message.id} media>
<img src={message.body.src} />
<IconButton
className={styles.iconButton}
onClick={onShareClick}
title={intl.formatMessage({ id: "share-popover.title", defaultMessage: "Share" })}
>
<ShareIcon />
</IconButton>
</MessageBubble>
);
case "permission":
Expand Down
23 changes: 23 additions & 0 deletions src/react-components/room/ChatSidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
padding: 10px 16px;
max-width: 80%;
width: max-content;
display: flex;
flex-direction: row;
justify-content: start;
font-size: theme.$font-size-md;
overflow-wrap: break-word;
line-height: 1.25;
Expand All @@ -71,6 +74,8 @@
background-color: theme.$chat-bubble-bg-color-sent;
color: theme.$chat-bubble-text-color-sent;
align-self: flex-end;
flex-direction: row-reverse;
justify-content: end;

a {
color: theme.$chat-bubble-text-color-sent;
Expand Down Expand Up @@ -134,6 +139,24 @@
}
}

:local(.icon-button) {
width: 48px;
height: 48px;
display: flex;
flex-shrink: 0;
justify-content: center;
align-items: center;
cursor: pointer;
border-radius: 18px;
background-color: transparent;

&:hover {
@media (pointer: fine) {
color: theme.$primary-color-hover;
}
}
}

:local(.chat-input-warning) {
padding-top: theme.$spacing-2xs;
}
Expand Down