Global Search / Media: Add Focus Message context action
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2c82b5eed2
commit
b8fda6bade
@ -4,6 +4,8 @@ import {
|
|||||||
} from '../../../lib/teact/teact';
|
} from '../../../lib/teact/teact';
|
||||||
import { getActions, withGlobal } from '../../../global';
|
import { getActions, withGlobal } from '../../../global';
|
||||||
|
|
||||||
|
import type { ApiMessage } from '../../../api/types';
|
||||||
|
import type { MenuItemContextAction } from '../../ui/ListItem';
|
||||||
import type { StateProps } from './helpers/createMapStateToProps';
|
import type { StateProps } from './helpers/createMapStateToProps';
|
||||||
import { LoadMoreDirection, MediaViewerOrigin } from '../../../types';
|
import { LoadMoreDirection, MediaViewerOrigin } from '../../../types';
|
||||||
|
|
||||||
@ -15,6 +17,8 @@ import { throttle } from '../../../util/schedulers';
|
|||||||
import { createMapStateToProps } from './helpers/createMapStateToProps';
|
import { createMapStateToProps } from './helpers/createMapStateToProps';
|
||||||
|
|
||||||
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';
|
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';
|
||||||
|
import useLang from '../../../hooks/useLang';
|
||||||
|
import useLastCallback from '../../../hooks/useLastCallback';
|
||||||
import useOldLang from '../../../hooks/useOldLang';
|
import useOldLang from '../../../hooks/useOldLang';
|
||||||
import useAsyncRendering from '../../right/hooks/useAsyncRendering';
|
import useAsyncRendering from '../../right/hooks/useAsyncRendering';
|
||||||
|
|
||||||
@ -44,11 +48,13 @@ const MediaResults: FC<OwnProps & StateProps> = ({
|
|||||||
const {
|
const {
|
||||||
searchMessagesGlobal,
|
searchMessagesGlobal,
|
||||||
openMediaViewer,
|
openMediaViewer,
|
||||||
|
focusMessage,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>();
|
const containerRef = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
const lang = useOldLang();
|
const oldLang = useOldLang();
|
||||||
|
const lang = useLang();
|
||||||
|
|
||||||
const { observe: observeIntersectionForMedia } = useIntersectionObserver({
|
const { observe: observeIntersectionForMedia } = useIntersectionObserver({
|
||||||
rootRef: containerRef,
|
rootRef: containerRef,
|
||||||
@ -86,9 +92,19 @@ const MediaResults: FC<OwnProps & StateProps> = ({
|
|||||||
});
|
});
|
||||||
}, [openMediaViewer]);
|
}, [openMediaViewer]);
|
||||||
|
|
||||||
|
const getMessageContextActions = useLastCallback((message: ApiMessage): MenuItemContextAction[] => {
|
||||||
|
return [{
|
||||||
|
title: lang('FocusMessage'),
|
||||||
|
icon: 'show-message',
|
||||||
|
handler: () => {
|
||||||
|
focusMessage({ chatId: message.chatId, messageId: message.id });
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
function renderGallery() {
|
function renderGallery() {
|
||||||
return (
|
return (
|
||||||
<div className="media-list" dir={lang.isRtl ? 'rtl' : undefined}>
|
<div className="media-list" dir={oldLang.isRtl ? 'rtl' : undefined}>
|
||||||
{foundMessages.map((message) => (
|
{foundMessages.map((message) => (
|
||||||
<Media
|
<Media
|
||||||
key={`${message.chatId}-${message.id}`}
|
key={`${message.chatId}-${message.id}`}
|
||||||
@ -97,6 +113,7 @@ const MediaResults: FC<OwnProps & StateProps> = ({
|
|||||||
isProtected={isChatProtected || message.isProtected}
|
isProtected={isChatProtected || message.isProtected}
|
||||||
observeIntersection={observeIntersectionForMedia}
|
observeIntersection={observeIntersectionForMedia}
|
||||||
onClick={handleSelectMedia}
|
onClick={handleSelectMedia}
|
||||||
|
contextActions={getMessageContextActions(message)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -141,8 +158,8 @@ const MediaResults: FC<OwnProps & StateProps> = ({
|
|||||||
{canRenderContents && (!foundIds || foundIds.length === 0) && (
|
{canRenderContents && (!foundIds || foundIds.length === 0) && (
|
||||||
<NothingFound
|
<NothingFound
|
||||||
withSticker
|
withSticker
|
||||||
text={lang('ChatList.Search.NoResults')}
|
text={oldLang('ChatList.Search.NoResults')}
|
||||||
description={lang('ChatList.Search.NoResultsDescription')}
|
description={oldLang('ChatList.Search.NoResultsDescription')}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isMediaGrid && renderGallery()}
|
{isMediaGrid && renderGallery()}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user