Fix: hook being used inside useEffect (#21534)

This commit is contained in:
Tainan Felipe 2024-10-28 13:14:43 -03:00 committed by GitHub
parent bf3cd7a5d5
commit 988ae28d42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 35 deletions

View File

@ -93,22 +93,10 @@ const ActionsBarContainer = (props) => {
const amIPresenter = currentUserData?.presenter; const amIPresenter = currentUserData?.presenter;
const amIModerator = currentUserData?.isModerator; const amIModerator = currentUserData?.isModerator;
const [pinnedPadDataState, setPinnedPadDataState] = useState(null); const [pinnedPadDataState, setPinnedPadDataState] = useState(null);
const { data: pinnedPadData } = useDeduplicatedSubscription(
PINNED_PAD_SUBSCRIPTION,
);
useEffect(() => {
const fetchData = async () => {
const { data: pinnedPadData } = await useDeduplicatedSubscription(
PINNED_PAD_SUBSCRIPTION,
);
setPinnedPadDataState(pinnedPadData || []);
};
fetchData();
}, []);
const isSharedNotesPinnedFromGraphql = !!pinnedPadDataState
&& pinnedPadDataState.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
const isSharedNotesPinned = isSharedNotesPinnedFromGraphql;
const allowExternalVideo = useIsExternalVideoEnabled(); const allowExternalVideo = useIsExternalVideoEnabled();
const connected = useReactiveVar(connectionStatus.getConnectedStatusVar()); const connected = useReactiveVar(connectionStatus.getConnectedStatusVar());
const intl = useIntl(); const intl = useIntl();
@ -131,7 +119,12 @@ const ActionsBarContainer = (props) => {
&& (deviceInfo.isPhone || isLayeredView.matches); && (deviceInfo.isPhone || isLayeredView.matches);
if (actionsBarStyle.display === false) return null; if (actionsBarStyle.display === false) return null;
if (!currentMeeting) return null; if (!currentMeeting) return null;
if (!pinnedPadData) return null;
const isSharedNotesPinnedFromGraphql = !!pinnedPadData
&& pinnedPadData.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
const isSharedNotesPinned = isSharedNotesPinnedFromGraphql;
return ( return (
<ActionsBar { <ActionsBar {
...{ ...{

View File

@ -191,30 +191,13 @@ const UserNotesGraphql: React.FC<UserNotesGraphqlProps> = (props) => {
}; };
const UserNotesContainerGraphql: React.FC<UserNotesContainerGraphqlProps> = (props) => { const UserNotesContainerGraphql: React.FC<UserNotesContainerGraphqlProps> = (props) => {
type PinnedPadData = {
sharedNotes: Array<{
sharedNotesExtId: string;
}>;
};
const { userLocks } = props; const { userLocks } = props;
const disableNotes = userLocks.userNotes; const disableNotes = userLocks.userNotes;
const [pinnedPadDataState, setPinnedPadDataState] = useState<PinnedPadData | null>(null); const { data: pinnedPadData } = useDeduplicatedSubscription(
PINNED_PAD_SUBSCRIPTION,
useEffect(() => { );
const fetchData = async () => {
const { data: pinnedPadData } = await useDeduplicatedSubscription(
PINNED_PAD_SUBSCRIPTION,
);
setPinnedPadDataState(pinnedPadData || []);
};
fetchData();
}, []);
const NOTES_CONFIG = window.meetingClientSettings.public.notes; const NOTES_CONFIG = window.meetingClientSettings.public.notes;
const isPinned = !!pinnedPadDataState && pinnedPadDataState.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const sidebarContent = layoutSelectInput((i: any) => i.sidebarContent); const sidebarContent = layoutSelectInput((i: any) => i.sidebarContent);
const { sidebarContentPanel } = sidebarContent; const { sidebarContentPanel } = sidebarContent;
@ -226,7 +209,9 @@ const UserNotesContainerGraphql: React.FC<UserNotesContainerGraphqlProps> = (pro
const hasUnreadNotes = useHasUnreadNotes(); const hasUnreadNotes = useHasUnreadNotes();
const markNotesAsRead = () => setNotesLastRev(rev); const markNotesAsRead = () => setNotesLastRev(rev);
const isEnabled = NotesService.useIsEnabled(); const isEnabled = NotesService.useIsEnabled();
if (!pinnedPadData) return null;
const isPinned = !!pinnedPadData && pinnedPadData?.sharedNotes[0]?.sharedNotesExtId === NOTES_CONFIG.id;
return ( return (
<UserNotesGraphql <UserNotesGraphql
disableNotes={disableNotes} disableNotes={disableNotes}