Inline Bot Tooltip: Fix closing animation (#1313)

This commit is contained in:
Alexander Zinchuk 2021-07-23 17:01:52 +03:00
parent 5ba055400b
commit 4e0d706384
5 changed files with 39 additions and 16 deletions

View File

@ -91,7 +91,7 @@ export async function fetchInlineBotResults({
return { return {
isGallery: Boolean(result.gallery), isGallery: Boolean(result.gallery),
help: bot.botPlaceholder, help: bot.botPlaceholder,
nextOffset: result.nextOffset, nextOffset: getInlineBotResultsNextOffset(bot.username, result.nextOffset),
switchPm: buildSwitchPm(result.switchPm), switchPm: buildSwitchPm(result.switchPm),
users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any), users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any),
results: processInlineBotResult(String(result.queryId), result.results), results: processInlineBotResult(String(result.queryId), result.results),
@ -144,6 +144,10 @@ function processInlineBotResult(queryId: string, results: GramJs.TypeBotInlineRe
}); });
} }
function getInlineBotResultsNextOffset(username: string, nextOffset?: string) {
return username === 'gif' && nextOffset === '0' ? '' : nextOffset;
}
function addUserToLocalDb(user: GramJs.User) { function addUserToLocalDb(user: GramJs.User) {
localDb.users[user.id] = user; localDb.users[user.id] = user;
} }

View File

@ -800,6 +800,17 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
filteredUsers={mentionFilteredUsers} filteredUsers={mentionFilteredUsers}
usersById={usersById} usersById={usersById}
/> />
<InlineBotTooltip
isOpen={isInlineBotTooltipOpen}
botId={inlineBotId}
allowedAttachmentOptions={allowedAttachmentOptions}
isGallery={isInlineBotTooltipGallery}
inlineBotResults={inlineBotResults}
switchPm={inlineBotSwitchPm}
onSelectResult={handleInlineBotSelect}
loadMore={loadMoreForInlineBot}
onClose={closeInlineBotTooltip}
/>
<div id="message-compose"> <div id="message-compose">
<div className="svg-appendix" ref={appendixRef} /> <div className="svg-appendix" ref={appendixRef} />
<ComposerEmbeddedMessage /> <ComposerEmbeddedMessage />
@ -917,17 +928,6 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
onClose={closeBotKeyboard} onClose={closeBotKeyboard}
/> />
)} )}
<InlineBotTooltip
isOpen={isInlineBotTooltipOpen}
botId={inlineBotId}
allowedAttachmentOptions={allowedAttachmentOptions}
isGallery={isInlineBotTooltipGallery}
inlineBotResults={inlineBotResults}
switchPm={inlineBotSwitchPm}
onSelectResult={handleInlineBotSelect}
loadMore={loadMoreForInlineBot}
onClose={closeInlineBotTooltip}
/>
<SymbolMenu <SymbolMenu
isOpen={isSymbolMenuOpen} isOpen={isSymbolMenuOpen}
allowedAttachmentOptions={allowedAttachmentOptions} allowedAttachmentOptions={allowedAttachmentOptions}

View File

@ -17,6 +17,7 @@ import useShowTransition from '../../../hooks/useShowTransition';
import { throttle } from '../../../util/schedulers'; import { throttle } from '../../../util/schedulers';
import { pick } from '../../../util/iteratees'; import { pick } from '../../../util/iteratees';
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';
import usePrevious from '../../../hooks/usePrevious';
import MediaResult from './inlineResults/MediaResult'; import MediaResult from './inlineResults/MediaResult';
import ArticleResult from './inlineResults/ArticleResult'; import ArticleResult from './inlineResults/ArticleResult';
@ -122,7 +123,18 @@ const InlineBotTooltip: FC<OwnProps & DispatchProps> = ({
sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` }); sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` });
}, [botId, openChat, sendBotCommand, switchPm]); }, [botId, openChat, sendBotCommand, switchPm]);
if (!shouldRender || !inlineBotResults || (!inlineBotResults.length && !switchPm)) {
const prevInlineBotResults = usePrevious(
inlineBotResults && inlineBotResults.length
? inlineBotResults
: undefined,
shouldRender,
);
const renderedInlineBotResults = inlineBotResults && !inlineBotResults.length
? prevInlineBotResults
: inlineBotResults;
if (!shouldRender || !renderedInlineBotResults || (!renderedInlineBotResults.length && !switchPm)) {
return undefined; return undefined;
} }
@ -142,7 +154,7 @@ const InlineBotTooltip: FC<OwnProps & DispatchProps> = ({
} }
function renderContent() { function renderContent() {
return inlineBotResults!.map((inlineBotResult, index) => { return renderedInlineBotResults!.map((inlineBotResult, index) => {
switch (inlineBotResult.type) { switch (inlineBotResult.type) {
case 'gif': case 'gif':
return ( return (
@ -205,7 +217,7 @@ const InlineBotTooltip: FC<OwnProps & DispatchProps> = ({
<InfiniteScroll <InfiniteScroll
ref={containerRef} ref={containerRef}
className={className} className={className}
items={inlineBotResults} items={renderedInlineBotResults}
itemSelector=".chat-item-clickable" itemSelector=".chat-item-clickable"
noFastList noFastList
onLoadMore={handleLoadMore} onLoadMore={handleLoadMore}

View File

@ -19,6 +19,7 @@ export default function useInlineBotTooltip(
const { queryInlineBot, resetInlineBot } = getDispatch(); const { queryInlineBot, resetInlineBot } = getDispatch();
const { username, query, canShowHelp } = parseStartWithUsernameString(text); const { username, query, canShowHelp } = parseStartWithUsernameString(text);
const usernameLowered = username.toLowerCase(); const usernameLowered = username.toLowerCase();
const prevQuery = usePrevious(query);
const prevUsername = usePrevious(username); const prevUsername = usePrevious(username);
const inlineBotData = inlineBots && inlineBots[usernameLowered]; const inlineBotData = inlineBots && inlineBots[usernameLowered];
const { const {
@ -30,6 +31,12 @@ export default function useInlineBotTooltip(
help, help,
} = inlineBotData || {}; } = inlineBotData || {};
useEffect(() => {
if (prevQuery !== query) {
unmarkIsOpen();
}
}, [prevQuery, query, unmarkIsOpen]);
useEffect(() => { useEffect(() => {
if (isAllowed && usernameLowered && chatId) { if (isAllowed && usernameLowered && chatId) {
queryInlineBot({ chatId, username: usernameLowered, query }); queryInlineBot({ chatId, username: usernameLowered, query });

View File

@ -249,7 +249,7 @@ async function searchInlineBot({
global = replaceInlineBotSettings(global, username, { global = replaceInlineBotSettings(global, username, {
...newInlineBotData, ...newInlineBotData,
help: result.help, help: result.help,
isGallery: result.isGallery, ...(newResults.length && { isGallery: result.isGallery }),
...(result.switchPm && { switchPm: result.switchPm }), ...(result.switchPm && { switchPm: result.switchPm }),
canLoadMore: result.results.length > 0 && Boolean(result.nextOffset), canLoadMore: result.results.length > 0 && Boolean(result.nextOffset),
results: newInlineBotData.offset === '' || newInlineBotData.offset === result.nextOffset results: newInlineBotData.offset === '' || newInlineBotData.offset === result.nextOffset