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

Show composer on public rooms after signing in #42497

Merged
merged 11 commits into from
Jun 5, 2024
24 changes: 24 additions & 0 deletions src/hooks/useDeepCompareRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useRef } from 'react';
import isEqual from 'lodash/isEqual';

/**
* This hook returns a reference to the provided value,
* but only updates that reference if a deep comparison indicates that the value has changed.
*
* This is useful when working with objects or arrays as dependencies to other hooks like `useEffect` or `useMemo`,
* where you want the hook to trigger not just on reference changes, but also when the contents of the object or array change.
*
* @example
* const myArray = // some array
* const deepComparedArray = useDeepCompareRef(myArray);
* useEffect(() => {
* // This will run not just when myArray is a new array, but also when its contents change.
* }, [deepComparedArray]);
*/
export default function useDeepCompareRef<T>(value: T): T | undefined {
const ref = useRef<T>();
if (!isEqual(value, ref.current)) {
ref.current = value;
}
return ref.current;
}
7 changes: 5 additions & 2 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import ReportFooter from './report/ReportFooter';
import type {ActionListContextType, ReactionListRef, ScrollPosition} from './ReportScreenContext';
import {ActionListContext, ReactionListContext} from './ReportScreenContext';
import useDeepCompareRef from '@hooks/useDeepCompareRef';

Check failure on line 55 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

`@hooks/useDeepCompareRef` import should occur before import of `./HeaderView`
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved

type ReportScreenOnyxPropsWithoutParentReportAction = {
/** Get modal status */
Expand Down Expand Up @@ -168,6 +169,8 @@
const isReportOpenInRHP = useIsReportOpenInRHP();
const {isSmallScreenWidth} = useWindowDimensions();
const shouldUseNarrowLayout = isSmallScreenWidth || isReportOpenInRHP;
const permissions = useDeepCompareRef(reportProp?.permissions);

/**
* Create a lightweight Report so as to keep the re-rendering as light as possible by
* passing in only the required props.
Expand Down Expand Up @@ -215,7 +218,7 @@
isOptimisticReport: reportProp?.isOptimisticReport,
lastMentionedTime: reportProp?.lastMentionedTime,
avatarUrl: reportProp?.avatarUrl,
permissions: reportProp?.permissions,
permissions,
invoiceReceiver: reportProp?.invoiceReceiver,
}),
[
Expand Down Expand Up @@ -256,7 +259,7 @@
reportProp?.isOptimisticReport,
reportProp?.lastMentionedTime,
reportProp?.avatarUrl,
reportProp?.permissions,
permissions,
reportProp?.invoiceReceiver,
],
);
Expand Down
Loading