Skip to content

Commit

Permalink
fix: incorrect history api called when using regular functions (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied authored Feb 25, 2025
1 parent 45b2b24 commit e81739a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/webapp/src/components/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class HistoryComponent extends LitElement {
async onChatClicked(sessionId: string) {
try {
this.isLoading = true;
const response = await fetch(`${this.options.apiUrl}/api/chats/${sessionId}/?userId=${this.userId}`);
const response = await fetch(`${this.getApiUrl()}/api/chats/${sessionId}/?userId=${this.userId}`);
const messages = await response.json();
const loadSessionEvent = new CustomEvent('loadSession', {
detail: { id: sessionId, messages },
Expand All @@ -92,7 +92,7 @@ export class HistoryComponent extends LitElement {
try {
this.chats = this.chats.filter((chat) => chat.id !== sessionId);

await fetch(`${this.options.apiUrl}/api/chats/${sessionId}?userId=${this.userId}`, {
await fetch(`${this.getApiUrl()}/api/chats/${sessionId}?userId=${this.userId}`, {
method: 'DELETE',
});
} catch (error) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export class HistoryComponent extends LitElement {
this.isLoading = true;
this.hasError = false;
try {
const response = await fetch(`${this.options.apiUrl}/api/chats?userId=${this.userId}`);
const response = await fetch(`${this.getApiUrl()}/api/chats?userId=${this.userId}`);
const chats = await response.json();
this.chats = chats;
this.isLoading = false;
Expand All @@ -155,6 +155,8 @@ export class HistoryComponent extends LitElement {
}
}

protected getApiUrl = () => this.options.apiUrl || import.meta.env.VITE_API_URL || '';

protected renderLoader = () =>
this.isLoading ? html`<slot name="loader"><div class="loader-animation"></div></slot>` : nothing;

Expand Down

0 comments on commit e81739a

Please sign in to comment.