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

feat: Scroll the conversation to top #31874

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
Copy link

@thesynthax thesynthax Mar 5, 2024

Choose a reason for hiding this comment

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

Change title: 'Start_of_converstation', to title: 'Go_to_first_message',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMemo } from 'react';

import type { RoomToolboxActionConfig } from '../../views/room/contexts/RoomToolboxContext';

export const useGetTopMessageRoomAction = () => {
return useMemo((): RoomToolboxActionConfig | undefined => {
return {
id: 'go-to-start-of-the-conversation',
title: 'Go_to_first_message',
icon: 'arrow-up',
order: 21,
type: 'organization',
groups: ['channel', 'group', 'direct', 'direct_multiple', 'team'],
};
}, []);
};
2 changes: 2 additions & 0 deletions apps/meteor/client/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useContactProfileRoomAction } from './hooks/roomActions/useContactProfi
import { useDiscussionsRoomAction } from './hooks/roomActions/useDiscussionsRoomAction';
import { useE2EERoomAction } from './hooks/roomActions/useE2EERoomAction';
import { useExportMessagesRoomAction } from './hooks/roomActions/useExportMessagesRoomAction';
import { useGetTopMessageRoomAction } from './hooks/roomActions/useGetTopMessageRoomAction';
import { useKeyboardShortcutListRoomAction } from './hooks/roomActions/useKeyboardShortcutListRoomAction';
import { useMembersListRoomAction } from './hooks/roomActions/useMembersListRoomAction';
import { useMentionsRoomAction } from './hooks/roomActions/useMentionsRoomAction';
Expand Down Expand Up @@ -69,6 +70,7 @@ export const roomActionHooks = [
useUploadedFilesListRoomAction,
useVoIPRoomInfoRoomAction,
useWebRTCVideoRoomAction,
useGetTopMessageRoomAction,
] satisfies (() => RoomToolboxActionConfig | undefined)[];

export const quickActionHooks = [
Expand Down
15 changes: 15 additions & 0 deletions apps/meteor/client/views/room/body/RoomBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useTranslation,
useUser,
useUserPreference,
useRouteParameter,
} from '@rocket.chat/ui-contexts';
import type { MouseEventHandler, ReactElement, UIEvent } from 'react';
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
Expand Down Expand Up @@ -59,6 +60,7 @@ import { useRetentionPolicy } from './hooks/useRetentionPolicy';
import { useUnreadMessages } from './hooks/useUnreadMessages';

const RoomBody = (): ReactElement => {
const tabActionId = useRouteParameter('tab');
const formatDate = useFormatDate();
const t = useTranslation();
const isLayoutEmbedded = useEmbeddedLayout();
Expand Down Expand Up @@ -117,6 +119,12 @@ const RoomBody = (): ReactElement => {
setHasNewMessages(false);
}, [scrollMessageList]);

const sendToTop = useCallback(() => {
scrollMessageList(() => {
return { left: 30, top: 0 };
});
}, [scrollMessageList]);

const sendToBottomIfNecessary = useCallback(() => {
if (atBottomRef.current === true) {
sendToBottom();
Expand Down Expand Up @@ -271,6 +279,13 @@ const RoomBody = (): ReactElement => {
};
}, [sendToBottomIfNecessary]);

useEffect(() => {
if (tabActionId === 'go-to-start-of-the-conversation') {
sendToTop();
toolbox.closeTab();
}
}, [tabActionId, sendToTop, toolbox]);

const router = useRouter();

const debouncedReadMessageRead = useMemo(
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json

Choose a reason for hiding this comment

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

Change "Start_of_converstation" : "Start_of_converstation", to "Go_to_first_message" : "Go to first message",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Original file line number Diff line number Diff line change
Expand Up @@ -4914,6 +4914,7 @@
"spy-voip-calls": "Spy Voip Calls",
"spy-voip-calls_description": "Permission to spy voip calls",
"SSL": "SSL",
"Go_to_first_message" : "Go_to_first_message",
"Star": "Star",
"Star_Message": "Star Message",
"Starred_Messages": "Starred Messages",
Expand Down
Loading