Skip to content

Commit 4c3da6b

Browse files
committed
chore: make default footer to be a composable component as well
1 parent 0d6f03a commit 4c3da6b

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

packages/chat-component/src/components/chat-component.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import iconUp from '../../public/svg/chevron-up-icon.svg?raw';
2121
import { type TabContent } from './tab-component.js';
2222
import { ChatController } from './chat-controller.js';
2323
import { ChatHistoryController } from './chat-history-controller.js';
24-
import { container, type ChatInputComponent, ComponentType } from './composable.js';
24+
import { container, type ChatInputComponent, ComponentType, type ChatInputFooterComponent } from './composable.js';
2525
import getDecorators from 'inversify-inject-decorators';
2626
const { lazyMultiInject } = getDecorators(container);
2727

@@ -88,9 +88,6 @@ export class ChatComponent extends LitElement {
8888
@state()
8989
isShowingThoughtProcess = false;
9090

91-
@state()
92-
isDefaultPromptsEnabled: boolean = globalConfig.IS_DEFAULT_PROMPTS_ENABLED && !this.isChatStarted;
93-
9491
@state()
9592
selectedCitation: Citation | undefined = undefined;
9693

@@ -107,6 +104,9 @@ export class ChatComponent extends LitElement {
107104
@lazyMultiInject(ComponentType.ChatInputComponent)
108105
chatInputComponents: ChatInputComponent[];
109106

107+
@lazyMultiInject(ComponentType.ChatInputFooterComponent)
108+
chatInputFooterComponets: ChatInputFooterComponent[];
109+
110110
override updated(changedProperties: Map<string | number | symbol, unknown>) {
111111
super.updated(changedProperties);
112112
// The following block is only necessary when you want to override the component from settings in the outside.
@@ -177,7 +177,6 @@ export class ChatComponent extends LitElement {
177177
this.collapseAside(event);
178178
const question = DOMPurify.sanitize(this.questionInput.value);
179179
this.isChatStarted = true;
180-
this.isDefaultPromptsEnabled = false;
181180

182181
await this.chatController.generateAnswer(
183182
{
@@ -221,7 +220,6 @@ export class ChatComponent extends LitElement {
221220
this.isChatStarted = false;
222221
this.chatThread = [];
223222
this.isDisabled = false;
224-
this.isDefaultPromptsEnabled = true;
225223
this.selectedCitation = undefined;
226224
this.chatController.reset();
227225
// clean up the current session content from the history too
@@ -230,13 +228,6 @@ export class ChatComponent extends LitElement {
230228
this.handleUserChatCancel(event);
231229
}
232230

233-
// Show the default prompts when enabled
234-
showDefaultPrompts(event: Event): void {
235-
if (!this.isDefaultPromptsEnabled) {
236-
this.resetCurrentChat(event);
237-
}
238-
}
239-
240231
// Handle the change event on the input field
241232
handleOnInputChange(): void {
242233
this.isResetInput = !!this.questionInput.value;
@@ -477,13 +468,9 @@ export class ChatComponent extends LitElement {
477468
</button>
478469
</div>
479470
480-
${this.isDefaultPromptsEnabled
481-
? ''
482-
: html`<div class="chat__containerFooter">
483-
<button type="button" @click="${this.showDefaultPrompts}" class="defaults__span button">
484-
${globalConfig.DISPLAY_DEFAULT_PROMPTS_BUTTON}
485-
</button>
486-
</div>`}
471+
${this.chatInputFooterComponets.map((component) =>
472+
component.render(this.resetCurrentChat, this.isChatStarted),
473+
)}
487474
</form>
488475
</section>
489476
${this.isShowingThoughtProcess

packages/chat-component/src/components/composable.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const container = new Container();
55

66
export const ComponentType = {
77
ChatInputComponent: Symbol.for('ChatInputComponent'),
8+
ChatInputFooterComponent: Symbol.for('ChatInputFooterComponent'),
89
};
910

1011
export interface ChatInputComponent {
@@ -16,15 +17,26 @@ export interface ChatInputComponent {
1617
) => TemplateResult;
1718
}
1819

20+
export interface ChatInputFooterComponent {
21+
render: (handleClick: (event: Event) => void, isChatStarted: boolean) => TemplateResult;
22+
}
23+
1924
// Add a default component since inversify currently doesn't seem to support optional bindings
2025
// and bindings fail if no component is provided
2126
@injectable()
22-
export class DefaultInputComponent implements ChatInputComponent {
23-
position = 'right';
24-
27+
export class DefaultEmptyComponent {
2528
render() {
2629
return html``;
2730
}
2831
}
2932

33+
@injectable()
34+
export class DefaultInputComponent extends DefaultEmptyComponent implements ChatInputComponent {
35+
position = 'right';
36+
}
37+
38+
@injectable()
39+
export class DefaultFooterComponent extends DefaultEmptyComponent implements ChatInputFooterComponent {}
40+
3041
container.bind<ChatInputComponent>(ComponentType.ChatInputComponent).to(DefaultInputComponent);
42+
container.bind<ChatInputFooter>(ComponentType.ChatInputFooterComponent).to(DefaultFooterComponent);

packages/chat-component/src/components/default-questions.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { injectable } from 'inversify';
2-
import { container, type ChatInputComponent, ComponentType } from './composable.js';
2+
import { container, type ChatInputComponent, ComponentType, type ChatInputFooterComponent } from './composable.js';
33
import { globalConfig, teaserListTexts } from '../config/global-config.js';
44
import { html } from 'lit';
55

@@ -27,4 +27,20 @@ export class DefaultQuestionsInputComponent implements ChatInputComponent {
2727
}
2828
}
2929

30+
@injectable()
31+
export class DefaultQuestionFooterComponent implements ChatInputFooterComponent {
32+
render(handleClick: (event: Event) => void, isChatStarted: boolean) {
33+
const footer = html`
34+
<div class="chat__containerFooter">
35+
<button type="button" @click="${handleClick}" class="defaults__span button">
36+
${globalConfig.DISPLAY_DEFAULT_PROMPTS_BUTTON}
37+
</button>
38+
</div>
39+
`;
40+
41+
return globalConfig.IS_DEFAULT_PROMPTS_ENABLED && !isChatStarted ? '' : footer;
42+
}
43+
}
44+
3045
container.bind<ChatInputComponent>(ComponentType.ChatInputComponent).to(DefaultQuestionsInputComponent);
46+
container.bind<ChatInputFooter>(ComponentType.ChatInputFooterComponent).to(DefaultQuestionFooterComponent);

0 commit comments

Comments
 (0)