Skip to content

Commit

Permalink
open in full-page button action
Browse files Browse the repository at this point in the history
  • Loading branch information
petemill committed Oct 22, 2024
1 parent d3306da commit 9c1eae2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
18 changes: 18 additions & 0 deletions browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include "brave/browser/ui/side_panel/ai_chat/ai_chat_side_panel_utils.h"
#include "brave/components/ai_chat/core/browser/ai_chat_service.h"
#include "brave/components/ai_chat/core/browser/constants.h"
#include "brave/components/ai_chat/core/common/features.h"
#include "brave/components/ai_chat/core/common/mojom/ai_chat.mojom-shared.h"
#include "brave/components/ai_chat/core/common/mojom/ai_chat.mojom.h"
#include "brave/components/constants/webui_url_constants.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
Expand All @@ -24,6 +26,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/url_constants.h"
#include "ui/base/page_transition_types.h"

#if BUILDFLAG(IS_ANDROID)
#include "brave/browser/ui/android/ai_chat/brave_leo_settings_launcher_helper.h"
Expand Down Expand Up @@ -105,6 +108,21 @@ void AIChatUIPageHandler::OpenAIChatSettings() {
#endif
}

void AIChatUIPageHandler::OpenConversationFullPage(
const std::string& conversation_uuid) {
CHECK(ai_chat::features::IsAIChatHistoryEnabled());
CHECK(active_chat_tab_helper_);
active_chat_tab_helper_->web_contents()->OpenURL(
{
GURL(kChatUIURL).Resolve(conversation_uuid),
content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_TYPED,
false,
},
{});
}

void AIChatUIPageHandler::OpenURL(const GURL& url) {
if (!url.SchemeIs(content::kChromeUIScheme) &&
!url.SchemeIs(url::kHttpsScheme)) {
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class AIChatUIPageHandler : public mojom::AIChatUIHandler,
~AIChatUIPageHandler() override;

// mojom::AIChatUIHandler

void OpenAIChatSettings() override;
void OpenConversationFullPage(const std::string& conversation_uuid) override;
void OpenURL(const GURL& url) override;
void OpenLearnMoreAboutBraveSearchWithLeo() override;
void OpenModelSupportUrl() override;
Expand Down
1 change: 1 addition & 0 deletions components/ai_chat/core/browser/constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ base::span<const webui::LocalizedString> GetLocalizedStrings() {
IDS_CHAT_UI_MODEL_PREMIUM_LABEL_NON_PREMIUM},
{"modelCategory-chat", IDS_CHAT_UI_MODEL_CATEGORY_CHAT},
{"menuNewChat", IDS_CHAT_UI_MENU_NEW_CHAT},
{"openFullPageLabel", IDS_CHAT_UI_LABEL_OPEN_FULL_PAGE},
{"menuGoPremium", IDS_CHAT_UI_MENU_GO_PREMIUM},
{"menuManageSubscription", IDS_CHAT_UI_MENU_MANAGE_SUBSCRIPTION},
{"menuSettings", IDS_CHAT_UI_MENU_SETTINGS},
Expand Down
7 changes: 7 additions & 0 deletions components/ai_chat/core/common/mojom/ai_chat.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ interface ServiceObserver {
interface AIChatUIHandler {
// Open various external links or dialogs depending on the platform
OpenAIChatSettings();

// From a sidebar or popup conversation, open the conversation in the
// full-page UI.
// TODO(petemill): WebUI Compile-timesupport for build flags
// so that we can use [EnableIfNot=is_android] here.
OpenConversationFullPage(string conversation_uuid);

OpenURL(url.mojom.Url url);
OpenLearnMoreAboutBraveSearchWithLeo();
OpenModelSupportUrl();
Expand Down
12 changes: 6 additions & 6 deletions components/ai_chat/resources/page/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const getTitle = (activeConversation?: Conversation) => activeConversation?.titl


const newChatButtonLabel = getLocale('newChatButtonLabel')
const openFullPageButtonLabel = getLocale('openFullPageLabel')

export const PageTitleHeader = React.forwardRef(function (props: FeatureButtonMenuProps, ref: React.Ref<HTMLDivElement>) {
const aiChatContext = useAIChat()
Expand All @@ -43,6 +44,7 @@ export const PageTitleHeader = React.forwardRef(function (props: FeatureButtonMe
const activeConversation = aiChatContext.visibleConversations.find(c => c.uuid === conversationContext.conversationUuid)
const showTitle = (!aiChatContext.isDefaultConversation || aiChatContext.isStandalone)
const isVisible = useIsConversationVisible(conversationContext.conversationUuid)
const canShowFullScreenButton = aiChatContext.isHistoryEnabled && !aiChatContext.isMobile && !aiChatContext.isStandalone && conversationContext.conversationUuid

return (
<div className={styles.header} ref={ref}>
Expand Down Expand Up @@ -73,15 +75,13 @@ export const PageTitleHeader = React.forwardRef(function (props: FeatureButtonMe
<Icon name={aiChatContext.isHistoryEnabled ? 'edit-box' : 'erase'} />
</Button>
)}
{!aiChatContext.isStandalone &&
{canShowFullScreenButton &&
<Button
fab
kind='plain-faint'
aria-label="Open full page"
title="Open full page"
onClick={() => {
// TODO(fallaciousreasoning): Wire this up to a new mojom interface.
}}
aria-label={openFullPageButtonLabel}
title={openFullPageButtonLabel}
onClick={() => getAPI().UIHandler.openConversationFullPage(conversationContext.conversationUuid!)}
>
<Icon name='expand' />
</Button>}
Expand Down
3 changes: 3 additions & 0 deletions components/resources/ai_chat_ui_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<message name="IDS_CHAT_UI_MODEL_CATEGORY_CHAT" desc="Category name for Chat">
Chat
</message>
<message name="IDS_CHAT_UI_LABEL_OPEN_FULL_PAGE" desc="Menu item to expand a sidebar conversation to a the full page experience">
Open full page
</message>
<message name="IDS_CHAT_UI_MENU_NEW_CHAT" desc="Menu item for new chat">
New chat
</message>
Expand Down

0 comments on commit 9c1eae2

Please sign in to comment.