Header Pinned Message: Inverse navigation when holding <Shift>

This commit is contained in:
Alexander Zinchuk 2023-04-15 13:51:44 +02:00
parent 2aa693eece
commit e21a9ffaf3
2 changed files with 10 additions and 7 deletions

View File

@ -39,7 +39,7 @@ type OwnProps = {
customTitle?: string; customTitle?: string;
className?: string; className?: string;
onUnpinMessage?: (id: number) => void; onUnpinMessage?: (id: number) => void;
onClick?: () => void; onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
onAllPinnedClick?: () => void; onAllPinnedClick?: () => void;
isLoading?: boolean; isLoading?: boolean;
isFullWidth?: boolean; isFullWidth?: boolean;

View File

@ -42,6 +42,7 @@ import {
selectThreadParam, selectThreadParam,
selectThreadTopMessageId, selectThreadTopMessageId,
} from '../../global/selectors'; } from '../../global/selectors';
import cycleRestrict from '../../util/cycleRestrict';
import useEnsureMessage from '../../hooks/useEnsureMessage'; import useEnsureMessage from '../../hooks/useEnsureMessage';
import useWindowSize from '../../hooks/useWindowSize'; import useWindowSize from '../../hooks/useWindowSize';
import useShowTransition from '../../hooks/useShowTransition'; import useShowTransition from '../../hooks/useShowTransition';
@ -184,15 +185,17 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
pinMessage({ messageId, isUnpin: true }); pinMessage({ messageId, isUnpin: true });
}, [pinMessage]); }, [pinMessage]);
const handlePinnedMessageClick = useCallback((): void => { const handlePinnedMessageClick = useCallback((e: React.MouseEvent<HTMLElement, MouseEvent>): void => {
if (!pinnedMessage) return; const messageId = e.shiftKey && Array.isArray(pinnedMessageIds)
? pinnedMessageIds[cycleRestrict(pinnedMessageIds.length, pinnedMessageIds.indexOf(pinnedMessageId!) - 2)]
: pinnedMessageId!;
if (onFocusPinnedMessage(pinnedMessage.id)) { if (onFocusPinnedMessage(messageId)) {
focusMessage({ focusMessage({
chatId: pinnedMessage.chatId, threadId, messageId: pinnedMessage.id, noForumTopicPanel: true, chatId, threadId, messageId, noForumTopicPanel: true,
}); });
} }
}, [pinnedMessage, threadId, onFocusPinnedMessage]); }, [pinnedMessageIds, pinnedMessageId, onFocusPinnedMessage, chatId, threadId]);
const handleAllPinnedClick = useCallback(() => { const handleAllPinnedClick = useCallback(() => {
openChat({ id: chatId, threadId, type: 'pinned' }); openChat({ id: chatId, threadId, type: 'pinned' });
@ -415,7 +418,7 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
<GroupCallTopPane <GroupCallTopPane
hasPinnedOffset={ hasPinnedOffset={
(shouldRenderPinnedMessage && Boolean(renderingPinnedMessage)) (shouldRenderPinnedMessage && Boolean(renderingPinnedMessage))
|| (shouldRenderAudioPlayer && Boolean(renderingAudioMessage)) || (shouldRenderAudioPlayer && Boolean(renderingAudioMessage))
} }
chatId={chatId} chatId={chatId}
/> />