Skip to content

Commit

Permalink
Lightbox: Added Button to jump to current image within the conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
findus committed Nov 21, 2024
1 parent 5d899d7 commit ac26daf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7691,5 +7691,9 @@
"icu:WhatsNew__v7.35--0": {
"messageformat": "The new filter icon next to the search box makes it easy to quickly find unread chats, but feel free to take your time deciding whether or not to leave them on read after seeing what they had to say.",
"description": "Release notes for version 7.35"
},
"icu:jumpto": {
"messageformat": "Jump to",
"description": "Jumps to the medias position in the conversation"
}
}
9 changes: 9 additions & 0 deletions stylesheets/components/Lightbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@
}
}

&--jump {
&::before {
@include mixins.color-svg(
'../images/icons/v3/chat/chat.svg',
variables.$color-gray-15
);
}
}

&--close {
&::before {
@include mixins.color-svg(
Expand Down
25 changes: 25 additions & 0 deletions ts/components/Lightbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ConversationType,
SaveAttachmentActionCreatorType,
} from '../state/ducks/conversations';
import { useConversationsActions } from '../state/ducks/conversations';
import type { LocalizerType } from '../types/Util';
import type { MediaItemType, MediaItemMessageType } from '../types/MediaItem';
import * as GoogleChrome from '../util/GoogleChrome';
Expand Down Expand Up @@ -94,6 +95,7 @@ export function Lightbox({
hasNextMessage,
hasPrevMessage,
}: PropsType): JSX.Element | null {
const { scrollToMessage } = useConversationsActions();
const hasThumbnails = media.length > 1;
const messageId = media.at(0)?.message.id;
const prevMessageId = usePrevious(messageId, messageId);
Expand Down Expand Up @@ -186,6 +188,21 @@ export function Lightbox({
[isViewOnce, media, saveAttachment, selectedIndex]
);

const handleJumpToConversation = useCallback(
(
event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
) => {
if (isViewOnce) {
return;
}
const mediaItem = media[selectedIndex];
const { message } = mediaItem;
const { conversationId, id } = message;
scrollToMessage(conversationId, id);
},
[isViewOnce, media, selectedIndex, scrollToMessage]
);

const handleForward = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
) => {
Expand Down Expand Up @@ -677,6 +694,14 @@ export function Lightbox({
<div />
)}
<div className="Lightbox__controls">
{!isViewOnce ? (
<button
aria-label={i18n('icu:jumpto')}
className="Lightbox__button Lightbox__button--jump"
onClick={handleJumpToConversation}
type="button"
/>
) : null}
{!isViewOnce ? (
<button
aria-label={i18n('icu:forwardMessage')}
Expand Down

0 comments on commit ac26daf

Please sign in to comment.