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

[GH-49599] - scroll chat to the bottom when a whisper for the current user is received in the chat #49699

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 21 additions & 3 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import FloatingMessageCounter from './FloatingMessageCounter';

Check failure on line 35 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `{OnyxInputOrEntry}·from·'@src/types/onyx';⏎import·ReportAction·from·'../../../types/onyx/ReportAction';⏎import·`

Check failure on line 35 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `{OnyxInputOrEntry}·from·'@src/types/onyx';⏎import·ReportAction·from·'../../../types/onyx/ReportAction';⏎import·`
import getInitialNumToRender from './getInitialNumReportActionsToRender';
import ListBoundaryLoader from './ListBoundaryLoader';
import ReportActionsListItemRenderer from './ReportActionsListItemRenderer';

Check failure on line 38 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Delete `;⏎import·{OnyxInputOrEntry}·from·"@src/types/onyx";⏎import·ReportAction·from·"../../../types/onyx/ReportAction"`

Check failure on line 38 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Delete `;⏎import·{OnyxInputOrEntry}·from·"@src/types/onyx";⏎import·ReportAction·from·"../../../types/onyx/ReportAction"`
import {OnyxInputOrEntry} from "@src/types/onyx";

Check failure on line 39 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 39 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`@src/types/onyx` import should occur before import of `./FloatingMessageCounter`

Check failure on line 39 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 39 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

`@src/types/onyx` import should occur before import of `./FloatingMessageCounter`
import ReportAction from "../../../types/onyx/ReportAction";

Check warning on line 40 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../../../types/onyx/ReportAction'. Use '@src/types/onyx/ReportAction' instead

Check failure on line 40 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

All imports in the declaration are only used as types. Use `import type`

Check warning on line 40 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unexpected parent import '../../../types/onyx/ReportAction'. Use '@src/types/onyx/ReportAction' instead

Check failure on line 40 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

All imports in the declaration are only used as types. Use `import type`

type LoadNewerChats = DebouncedFunc<(params: {distanceFromStart: number}) => void>;

Expand Down Expand Up @@ -279,7 +281,7 @@

const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID;
const reportActionSize = useRef(sortedVisibleReportActions.length);
const hasNewestReportAction = sortedVisibleReportActions[0]?.created === report.lastVisibleActionCreated;
const hasNewestReportAction = sortedVisibleReportActions[0]?.created >= report.lastVisibleActionCreated;

Check failure on line 284 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'report.lastVisibleActionCreated' is possibly 'undefined'.
const hasNewestReportActionRef = useRef(hasNewestReportAction);
hasNewestReportActionRef.current = hasNewestReportAction;
const previousLastIndex = useRef(lastActionIndex);
Expand All @@ -289,11 +291,14 @@
const [isFloatingMessageCounterVisible, setIsFloatingMessageCounterVisible] = useState(false);

useEffect(() => {
const isWhisperForUser = isWhisperVisibleOnlyToUser(sortedVisibleReportActions[0])

Check failure on line 294 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'isWhisperVisibleOnlyToUser' was used before it was defined

Check failure on line 294 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `;`

Check failure on line 294 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

'isWhisperVisibleOnlyToUser' was used before it was defined

Check failure on line 294 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `;`
const shouldScrollForWhisper = isWhisperForUser && hasNewestReportAction;

if (
scrollingVerticalOffset.current < AUTOSCROLL_TO_TOP_THRESHOLD &&
(scrollingVerticalOffset.current < AUTOSCROLL_TO_TOP_THRESHOLD &&
previousLastIndex.current !== lastActionIndex &&

Check failure on line 299 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `····`

Check failure on line 299 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `····`
reportActionSize.current > sortedVisibleReportActions.length &&

Check failure on line 300 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `····`

Check failure on line 300 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `····`
hasNewestReportAction
hasNewestReportAction) || shouldScrollForWhisper

Check failure on line 301 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `············hasNewestReportAction)·||` with `················hasNewestReportAction)·||⏎···········`

Check failure on line 301 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Replace `············hasNewestReportAction)·||` with `················hasNewestReportAction)·||⏎···········`
) {
reportScrollManager.scrollToBottom();
}
Expand Down Expand Up @@ -338,6 +343,19 @@
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

const isWhisperVisibleOnlyToUser =
(reportAction: OnyxInputOrEntry<ReportAction>) => {
const whisperedTo = ReportActionsUtils.getWhisperedTo(reportAction);

const iouReportID =
ReportActionsUtils.isMoneyRequestAction(reportAction) && ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID
? (ReportActionsUtils.getOriginalMessage(reportAction)?.IOUReportID ?? '').toString()
: '-1';
const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID);
const isWhisper = whisperedTo.length > 0 && transactionsWithReceipts.length === 0;
return isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo);
}

const scrollToBottomForCurrentUserAction = useCallback(
(isFromCurrentUser: boolean) => {
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
Expand Down
Loading