Skip to content

Commit 2f6ea5b

Browse files
authored
Merge branch 'main' into zeno/rnd-7450-mobile-toc-chat-layout
2 parents dcd0355 + fc98a4a commit 2f6ea5b

File tree

8 files changed

+46
-27
lines changed

8 files changed

+46
-27
lines changed

.changeset/funny-dodos-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Fix search results cursor

.changeset/social-moles-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Support `greeting` and fix suggested questions if there are no custom ones defined

packages/gitbook/src/components/AI/useAI.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export type AIConfig = {
1717
aiMode: CustomizationAIMode;
1818
suggestions?: string[];
1919
trademark: boolean;
20+
greeting?: {
21+
title: string;
22+
subtitle: string;
23+
};
2024
};
2125

2226
export type Assistant = Omit<GitBookAssistant, 'icon'> & {
@@ -50,10 +54,10 @@ export type Assistant = Omit<GitBookAssistant, 'icon'> & {
5054
const AIContext = React.createContext<AIConfig | null>(null);
5155

5256
export function AIContextProvider(props: React.PropsWithChildren<AIConfig>): React.ReactElement {
53-
const { aiMode, trademark, suggestions, children } = props;
57+
const { aiMode, trademark, suggestions, greeting, children } = props;
5458
const value = React.useMemo(
55-
() => ({ aiMode, trademark, suggestions }),
56-
[aiMode, trademark, suggestions]
59+
() => ({ aiMode, trademark, suggestions, greeting }),
60+
[aiMode, trademark, suggestions, greeting]
5761
);
5862
return <AIContext.Provider value={value}>{children}</AIContext.Provider>;
5963
}

packages/gitbook/src/components/AIChat/AIChat.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ export function AIChatBody(props: {
201201
chat: AIChatState;
202202
welcomeMessage?: string;
203203
suggestions?: string[];
204+
greeting?: {
205+
title: string;
206+
subtitle: string;
207+
};
204208
}) {
205-
const { chatController, chat, suggestions } = props;
209+
const { chatController, chat, suggestions, greeting } = props;
206210
const { trademark } = useAI().config;
207211

208212
const [input, setInput] = React.useState('');
@@ -241,19 +245,20 @@ export function AIChatBody(props: {
241245
className="size-8 text-primary [@container(min-height:400px)]:size-16"
242246
/>
243247
</div>
244-
<div className="flex flex-col items-start [@container(min-height:400px)]:items-center">
248+
<div className="flex flex-col items-start gap-1 [@container(min-height:400px)]:items-center">
245249
<h5
246-
className="animate-blur-in-slow font-bold text-lg text-tint-strong [@container(min-height:400px)]:text-center"
250+
className="animate-blur-in-slow font-bold text-lg text-tint-strong leading-tight [@container(min-height:400px)]:text-center"
247251
style={{ animationDelay: '.5s' }}
248252
data-testid="ai-chat-time-greeting"
249253
>
250-
{timeGreeting}
254+
{greeting?.title || timeGreeting}
251255
</h5>
252256
<p
253-
className="animate-blur-in-slow text-tint [@container(min-height:400px)]:text-center"
257+
className="animate-blur-in-slow text-tint leading-tight [@container(min-height:400px)]:text-center"
254258
style={{ animationDelay: '.6s' }}
255259
>
256-
{t(language, 'ai_chat_assistant_description')}
260+
{greeting?.subtitle ||
261+
t(language, 'ai_chat_assistant_description')}
257262
</p>
258263
</div>
259264
</div>

packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ export default function AIChatSuggestedQuestions(props: {
77
suggestions?: string[];
88
}) {
99
const language = useLanguage();
10-
const {
11-
chatController,
12-
suggestions = [
13-
tString(language, 'ai_chat_suggested_questions_about_this_page'),
14-
tString(language, 'ai_chat_suggested_questions_read_next'),
15-
tString(language, 'ai_chat_suggested_questions_example'),
16-
],
17-
} = props;
10+
const { chatController, suggestions: _suggestions } = props;
11+
12+
const suggestions =
13+
_suggestions && _suggestions.length > 0
14+
? _suggestions
15+
: [
16+
tString(language, 'ai_chat_suggested_questions_about_this_page'),
17+
tString(language, 'ai_chat_suggested_questions_read_next'),
18+
tString(language, 'ai_chat_suggested_questions_example'),
19+
];
1820

1921
return (
2022
<div className="flex flex-col items-start gap-2 self-start">

packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function EmbeddableAIChat(props: EmbeddableAIChatProps) {
9898
chatController={chatController}
9999
chat={chat}
100100
suggestions={configuration.suggestions}
101+
greeting={configuration.greeting}
101102
/>
102103
</EmbeddableFrameBody>
103104
</EmbeddableFrameMain>

packages/gitbook/src/components/Search/useSearchResults.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ export function useSearchResults(props: {
173173
return;
174174
}
175175

176-
setResultsState({ results, fetching: false, error: false });
176+
const aiEnrichedResults = withAI
177+
? withAskTriggers(results, query, assistants)
178+
: results;
179+
180+
setResultsState({ results: aiEnrichedResults, fetching: false, error: false });
177181

178182
trackEvent({
179183
type: 'search_type_query',
@@ -194,14 +198,7 @@ export function useSearchResults(props: {
194198
};
195199
}, [query, scope, trackEvent, withAI, siteSpaceId, siteSpaceIds, disabled, suggestions]);
196200

197-
const aiEnrichedResults: ResultType[] = React.useMemo(() => {
198-
if (!withAI) {
199-
return resultsState.results;
200-
}
201-
return withAskTriggers(resultsState.results, query, assistants);
202-
}, [resultsState.results, query, withAI, assistants]);
203-
204-
return { ...resultsState, results: aiEnrichedResults };
201+
return resultsState;
205202
}
206203

207204
/**

packages/gitbook/src/components/TableOfContents/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ToggleableLinkItemStyles = [
2525
'text-balance font-normal text-sm text-tint-strong/7 hover:bg-tint-hover hover:text-tint-strong contrast-more:text-tint-strong',
2626
'contrast-more:hover:text-tint-strong contrast-more:hover:ring-1 contrast-more:hover:ring-tint-12',
2727
'before:contents[] before:-left-px before:absolute before:inset-y-0',
28-
'sidebar-list-line:rounded-l-none sidebar-list-line:before:w-px [&+div_a]:sidebar-list-default:rounded-l-none [&+div_a]:pl-5 [&+div_a]:sidebar-list-default:before:w-px',
28+
'sidebar-list-line:rounded-l-none! sidebar-list-line:before:w-px [&+div_a]:sidebar-list-default:rounded-l-none [&+div_a]:pl-5 [&+div_a]:sidebar-list-default:before:w-px',
2929
];
3030

3131
export const ToggleableLinkItemActiveStyles = [

0 commit comments

Comments
 (0)