Web Bot: Add "Open chat with bot" button (#1847)
This commit is contained in:
parent
c1c2c24726
commit
5a9baa530b
@ -58,7 +58,7 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
theme,
|
theme,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
closeWebApp, sendWebViewData, prolongWebView, toggleBotInAttachMenu, openTelegramLink,
|
closeWebApp, sendWebViewData, prolongWebView, toggleBotInAttachMenu, openTelegramLink, openChat,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
const [mainButton, setMainButton] = useState<WebAppButton | undefined>();
|
const [mainButton, setMainButton] = useState<WebAppButton | undefined>();
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
@ -164,6 +164,13 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
});
|
});
|
||||||
}, [bot, isInstalled, toggleBotInAttachMenu]);
|
}, [bot, isInstalled, toggleBotInAttachMenu]);
|
||||||
|
|
||||||
|
const openBotChat = useCallback(() => {
|
||||||
|
openChat({
|
||||||
|
id: bot!.id,
|
||||||
|
});
|
||||||
|
closeWebApp();
|
||||||
|
}, [bot, closeWebApp, openChat]);
|
||||||
|
|
||||||
const MoreMenuButton: FC<{ onTrigger: () => void; isOpen?: boolean }> = useMemo(() => {
|
const MoreMenuButton: FC<{ onTrigger: () => void; isOpen?: boolean }> = useMemo(() => {
|
||||||
return ({ onTrigger, isOpen: isMenuOpen }) => (
|
return ({ onTrigger, isOpen: isMenuOpen }) => (
|
||||||
<Button
|
<Button
|
||||||
@ -198,6 +205,9 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
trigger={MoreMenuButton}
|
trigger={MoreMenuButton}
|
||||||
positionX="right"
|
positionX="right"
|
||||||
>
|
>
|
||||||
|
{chat && bot && chat.id !== bot.id && (
|
||||||
|
<MenuItem icon="bots" onClick={openBotChat}>{lang('BotWebViewOpenBot')}</MenuItem>
|
||||||
|
)}
|
||||||
<MenuItem icon="reload" onClick={handleRefreshClick}>{lang('WebApp.ReloadPage')}</MenuItem>
|
<MenuItem icon="reload" onClick={handleRefreshClick}>{lang('WebApp.ReloadPage')}</MenuItem>
|
||||||
{bot?.isAttachMenuBot && (
|
{bot?.isAttachMenuBot && (
|
||||||
<MenuItem icon={isInstalled ? 'stop' : 'install'} onClick={handleToggleClick} destructive={isInstalled}>
|
<MenuItem icon={isInstalled ? 'stop' : 'install'} onClick={handleToggleClick} destructive={isInstalled}>
|
||||||
@ -207,9 +217,7 @@ const WebAppModal: FC<OwnProps & StateProps> = ({
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [
|
}, [lang, closeWebApp, bot, MoreMenuButton, handleRefreshClick, isInstalled, handleToggleClick, chat, openBotChat]);
|
||||||
MoreMenuButton, bot, closeWebApp, handleRefreshClick, handleToggleClick, lang, isInstalled,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const prevMainButtonColor = usePrevious(mainButton?.color, true);
|
const prevMainButtonColor = usePrevious(mainButton?.color, true);
|
||||||
const prevMainButtonTextColor = usePrevious(mainButton?.textColor, true);
|
const prevMainButtonTextColor = usePrevious(mainButton?.textColor, true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user