Sticker Tooltip: Clean input; Emoji Tooltip: Save to recent (#1305)

This commit is contained in:
Alexander Zinchuk 2021-07-21 17:44:44 +03:00
parent bedd7727cd
commit bf6c6ef035
3 changed files with 14 additions and 5 deletions

View File

@ -538,7 +538,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
resetComposer, stopRecordingVoice, showDialog, slowMode, isAdmin, sendMessage, forwardMessages, lang,
]);
const handleStickerSelect = useCallback((sticker: ApiSticker) => {
const handleStickerSelect = useCallback((sticker: ApiSticker, shouldPreserveInput = false) => {
sticker = {
...sticker,
isPreloadedGlobally: true,
@ -549,7 +549,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
openCalendar();
} else {
sendMessage({ sticker });
requestAnimationFrame(() => { resetComposer(true); });
requestAnimationFrame(() => { resetComposer(shouldPreserveInput); });
}
}, [shouldSchedule, openCalendar, sendMessage, resetComposer]);

View File

@ -105,6 +105,11 @@ const EmojiTooltip: FC<OwnProps> = ({
}
}, [addRecentEmoji, emojis, onEmojiSelect, selectedIndex]);
const handleClick = useCallback((native: string, id: string) => {
onEmojiSelect(native);
addRecentEmoji({ emoji: id });
}, [addRecentEmoji, onEmojiSelect]);
useEffect(() => (isOpen ? captureKeyboardListeners({
onEsc: onClose,
onLeft: (e: KeyboardEvent) => handleArrowKey(-1, e),
@ -138,7 +143,7 @@ const EmojiTooltip: FC<OwnProps> = ({
key={emoji.id}
emoji={emoji}
focus={selectedIndex === index}
onClick={onEmojiSelect}
onClick={handleClick}
/>
))
) : shouldRender ? (

View File

@ -32,7 +32,7 @@ export type OwnProps = {
onLoad: () => void;
onClose: () => void;
onEmojiSelect: (emoji: string) => void;
onStickerSelect: (sticker: ApiSticker) => void;
onStickerSelect: (sticker: ApiSticker, shouldPreserveInput?: boolean) => void;
onGifSelect: (gif: ApiVideo) => void;
onRemoveSymbol: () => void;
onSearchOpen: (type: 'stickers' | 'gifs') => void;
@ -114,6 +114,10 @@ const SymbolMenu: FC<OwnProps & StateProps> = ({
onSearchOpen(type);
}, [onClose, onSearchOpen]);
const handleStickerSelect = useCallback((sticker: ApiSticker) => {
onStickerSelect(sticker, true);
}, [onStickerSelect]);
const lang = useLang();
const { canSendStickers, canSendGifs } = allowedAttachmentOptions;
@ -133,7 +137,7 @@ const SymbolMenu: FC<OwnProps & StateProps> = ({
className="picker-tab"
loadAndPlay={canSendStickers ? isOpen && (isActive || isFrom) : false}
canSendStickers={canSendStickers}
onStickerSelect={onStickerSelect}
onStickerSelect={handleStickerSelect}
/>
);
case SymbolMenuTabs.GIFs: