Skip to content

Commit

Permalink
chore: rename events / fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rjborba committed Nov 21, 2024
1 parent bd907e1 commit 46ea174
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 29 deletions.
7 changes: 6 additions & 1 deletion apps/demo-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ function App() {
api_key: 'LerNlbp6379jVKaPs4wt2nZT4MJZbU1J',
endpoint: 'https://cloud.orama.run/v1/indexes/docs-orama-b3f5xd',
}}
onSearchCompletedCallback={(e) => console.log(e)}
onSearchCompleted={(e) => console.log(e)}
onSearchResultClick={(e) => {
console.log(e)
e.preventDefault()

console.log('Prevented')
}}
onAnswerGenerated={(e) => console.log(e)}
onAnswerSourceClick={(e) => {
console.log(e)
e.preventDefault()
}}
/>
</div>
</section>
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-stencil-vue/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const OramaChatButton = /*@__PURE__*/ defineContainer<JSX.OramaChatButton

export const OramaChatMessagesContainer = /*@__PURE__*/ defineContainer<JSX.OramaChatMessagesContainer>('orama-chat-messages-container', undefined, [
'interactions',
'answerGeneratedCallback'
'answerGenerated'
]);


Expand Down Expand Up @@ -142,8 +142,8 @@ export const OramaSearch = /*@__PURE__*/ defineContainer<JSX.OramaSearch>('orama
'disableChat',
'highlightTitle',
'highlightDescription',
'searchCompletedCallback',
'answerGeneratedCallback'
'searchCompleted',
'answerGenerated'
]);


Expand Down
12 changes: 6 additions & 6 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ declare global {
new (): HTMLOramaChatButtonElement;
};
interface HTMLOramaChatMessagesContainerElementEventMap {
"answerGeneratedCallback": OnSearchCompletedCallbackProps;
"answerGenerated": OnSearchCompletedCallbackProps;
}
interface HTMLOramaChatMessagesContainerElement extends Components.OramaChatMessagesContainer, HTMLStencilElement {
addEventListener<K extends keyof HTMLOramaChatMessagesContainerElementEventMap>(type: K, listener: (this: HTMLOramaChatMessagesContainerElement, ev: OramaChatMessagesContainerCustomEvent<HTMLOramaChatMessagesContainerElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -415,8 +415,8 @@ declare global {
new (): HTMLOramaNavigationBarElement;
};
interface HTMLOramaSearchElementEventMap {
"searchCompletedCallback": OnSearchCompletedCallbackProps;
"answerGeneratedCallback": OnSearchCompletedCallbackProps;
"searchCompleted": OnSearchCompletedCallbackProps;
"answerGenerated": OnSearchCompletedCallbackProps;
}
interface HTMLOramaSearchElement extends Components.OramaSearch, HTMLStencilElement {
addEventListener<K extends keyof HTMLOramaSearchElementEventMap>(type: K, listener: (this: HTMLOramaSearchElement, ev: OramaSearchCustomEvent<HTMLOramaSearchElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -605,7 +605,7 @@ declare namespace LocalJSX {
}
interface OramaChatMessagesContainer {
"interactions"?: TChatInteraction[];
"onAnswerGeneratedCallback"?: (event: OramaChatMessagesContainerCustomEvent<OnSearchCompletedCallbackProps>) => void;
"onAnswerGenerated"?: (event: OramaChatMessagesContainerCustomEvent<OnSearchCompletedCallbackProps>) => void;
}
interface OramaChatUserMessage {
"interaction"?: TChatInteraction;
Expand Down Expand Up @@ -659,8 +659,8 @@ declare namespace LocalJSX {
"highlightTitle"?: HighlightOptions | false;
"linksRel"?: string;
"linksTarget"?: string;
"onAnswerGeneratedCallback"?: (event: OramaSearchCustomEvent<OnSearchCompletedCallbackProps>) => void;
"onSearchCompletedCallback"?: (event: OramaSearchCustomEvent<OnSearchCompletedCallbackProps>) => void;
"onAnswerGenerated"?: (event: OramaSearchCustomEvent<OnSearchCompletedCallbackProps>) => void;
"onSearchCompleted"?: (event: OramaSearchCustomEvent<OnSearchCompletedCallbackProps>) => void;
"placeholder"?: string;
"sourceBaseUrl"?: string;
"suggestions"?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ export class OramaSources {
componentDidLoad() {
this.carouselSourceRef?.addEventListener('scroll', this.handleCarouselScroll)
this.computeCarouselArrowsVisibility()
this.resizeObserver.observe(this.carouselSourceRef)

if (this.carouselSourceRef) {
this.resizeObserver.observe(this.carouselSourceRef)
}
}

disconnectedCallback() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Host, Prop, h, Element, State, type EventEmitter, Event } from '@stencil/core'
import { chatContext, type TChatInteraction } from '@/context/chatContext'
import { OnSearchCompletedCallbackProps } from '@/types'
import type { OnSearchCompletedCallbackProps } from '@/types'

@Component({
tag: 'orama-chat-messages-container',
Expand All @@ -10,7 +10,7 @@ import { OnSearchCompletedCallbackProps } from '@/types'
export class OramaChatMessagesContainer {
@Prop() interactions: TChatInteraction[]

@Event({ bubbles: true, composed: true }) answerGeneratedCallback: EventEmitter<OnSearchCompletedCallbackProps>
@Event({ bubbles: true, composed: true }) answerGenerated: EventEmitter<OnSearchCompletedCallbackProps>

@Element() el: HTMLElement

Expand All @@ -20,7 +20,7 @@ export class OramaChatMessagesContainer {
onSuggestionClick = (suggestion: string) => {
chatContext.chatService?.sendQuestion(suggestion, undefined, {
onAnswerGeneratedCallback(onAnswerGeneratedCallbackProps) {
this.answerGeneratedCallback.emit(onAnswerGeneratedCallbackProps)
this.answerGenerated.emit(onAnswerGeneratedCallbackProps)
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

## Events

| Event | Description | Type |
| ------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `answerGeneratedCallback` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |
| Event | Description | Type |
| ----------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `answerGenerated` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Fragment, Listen, Host, Prop, State, Watch, h, type EventEmitter, Event } from '@stencil/core'
import { chatContext, chatStore, TAnswerStatus } from '@/context/chatContext'
import type { OnAnswerGeneratedCallbackProps, OnSearchCompletedCallbackProps, SearchResult, SourcesMap } from '@/types'
import type { OnAnswerGeneratedCallbackProps, SearchResult, SourcesMap } from '@/types'
import '@phosphor-icons/webcomponents/dist/icons/PhPaperPlaneTilt.mjs'
import '@phosphor-icons/webcomponents/dist/icons/PhStopCircle.mjs'
import '@phosphor-icons/webcomponents/dist/icons/PhArrowDown.mjs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| `placeholder` | `placeholder` | | `string` | `'Ask me anything'` |
| `showClearChat` | `show-clear-chat` | | `boolean` | `true` |
| `sourceBaseUrl` | `source-base-url` | | `string` | `''` |
| `sourcesMap` | -- | | `{ title?: string; description?: string; path?: string; }` | `undefined` |
| `sourcesMap` | -- | | `{ title?: string; path?: string; description?: string; }` | `undefined` |
| `suggestions` | -- | | `string[]` | `undefined` |
| `systemPrompts` | -- | | `string[]` | `undefined` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class OramaSearch {
@State() searchValue = ''
@State() selectedFacet = ''

@Event({ bubbles: true, composed: true }) searchCompletedCallback: EventEmitter<OnSearchCompletedCallbackProps>
@Event({ bubbles: true, composed: true }) answerGeneratedCallback: EventEmitter<OnSearchCompletedCallbackProps>
@Event({ bubbles: true, composed: true }) searchCompleted: EventEmitter<OnSearchCompletedCallbackProps>
@Event({ bubbles: true, composed: true }) answerGenerated: EventEmitter<OnSearchCompletedCallbackProps>

inputRef!: HTMLOramaInputElement

Expand All @@ -36,7 +36,7 @@ export class OramaSearch {
handleSearchValueChange() {
searchState.searchService.search(this.searchValue, this.selectedFacet, {
onSearchCompletedCallback: (onSearchCompletedCallbackProps) => {
this.searchCompletedCallback.emit(onSearchCompletedCallbackProps)
this.searchCompleted.emit(onSearchCompletedCallbackProps)
},
})
globalContext.currentTerm = this.searchValue
Expand All @@ -63,7 +63,7 @@ export class OramaSearch {
}

const chatButton = this.el.querySelector('orama-chat-button') as HTMLElement
chatButton.click()
chatButton?.click()
}

render() {
Expand Down Expand Up @@ -96,7 +96,7 @@ export class OramaSearch {
globalContext.currentTask = 'chat'
chatContext.chatService?.sendQuestion(term, undefined, {
onAnswerGeneratedCallback(onAnswerGeneratedCallbackProps) {
this.answerGeneratedCallback.emit(onAnswerGeneratedCallbackProps)
this.answerGenerated.emit(onAnswerGeneratedCallbackProps)
},
})
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

## Events

| Event | Description | Type |
| ------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `answerGeneratedCallback` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |
| `searchCompletedCallback` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |
| Event | Description | Type |
| ----------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `answerGenerated` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |
| `searchCompleted` | | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| `linksTarget` | `links-target` | | `string` | `undefined` |
| `placeholder` | `placeholder` | | `string` | `undefined` |
| `sourceBaseUrl` | `source-base-url` | | `string` | `undefined` |
| `sourcesMap` | -- | | `{ title?: string; description?: string; path?: string; }` | `undefined` |
| `sourcesMap` | -- | | `{ title?: string; path?: string; description?: string; }` | `undefined` |
| `suggestions` | -- | | `string[]` | `undefined` |
| `systemPrompts` | -- | | `string[]` | `undefined` |

Expand Down

0 comments on commit 46ea174

Please sign in to comment.