Pinned Messages: Fix broken order after switching chats

This commit is contained in:
Alexander Zinchuk 2021-05-15 00:53:25 +03:00
parent 8faf3a84f5
commit 84f8b64040

View File

@ -134,15 +134,16 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
}
}, [chatId, loadPinnedMessages, lastSyncTime, threadId]);
useEffect(() => {
setPinnedMessageIndex(0);
}, [chatId]);
// Modify index after unpinning
// Modify pinned index after unpinning
useEffect(() => {
setPinnedMessageIndex(pinnedMessagesCount ? cycleRestrict(pinnedMessagesCount, pinnedMessageIndex) : -1);
}, [pinnedMessagesCount, pinnedMessageIndex]);
// Reset pinned index when switching chats
useEffect(() => {
setPinnedMessageIndex(0);
}, [chatId]);
useEnsureMessage(chatId, pinnedMessageId, pinnedMessage);
const { width: windowWidth } = useWindowSize();