Skip to content

Commit e81739a

Browse files
authored
fix: incorrect history api called when using regular functions (#110)
1 parent 45b2b24 commit e81739a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/webapp/src/components/history.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class HistoryComponent extends LitElement {
7070
async onChatClicked(sessionId: string) {
7171
try {
7272
this.isLoading = true;
73-
const response = await fetch(`${this.options.apiUrl}/api/chats/${sessionId}/?userId=${this.userId}`);
73+
const response = await fetch(`${this.getApiUrl()}/api/chats/${sessionId}/?userId=${this.userId}`);
7474
const messages = await response.json();
7575
const loadSessionEvent = new CustomEvent('loadSession', {
7676
detail: { id: sessionId, messages },
@@ -92,7 +92,7 @@ export class HistoryComponent extends LitElement {
9292
try {
9393
this.chats = this.chats.filter((chat) => chat.id !== sessionId);
9494

95-
await fetch(`${this.options.apiUrl}/api/chats/${sessionId}?userId=${this.userId}`, {
95+
await fetch(`${this.getApiUrl()}/api/chats/${sessionId}?userId=${this.userId}`, {
9696
method: 'DELETE',
9797
});
9898
} catch (error) {
@@ -144,7 +144,7 @@ export class HistoryComponent extends LitElement {
144144
this.isLoading = true;
145145
this.hasError = false;
146146
try {
147-
const response = await fetch(`${this.options.apiUrl}/api/chats?userId=${this.userId}`);
147+
const response = await fetch(`${this.getApiUrl()}/api/chats?userId=${this.userId}`);
148148
const chats = await response.json();
149149
this.chats = chats;
150150
this.isLoading = false;
@@ -155,6 +155,8 @@ export class HistoryComponent extends LitElement {
155155
}
156156
}
157157

158+
protected getApiUrl = () => this.options.apiUrl || import.meta.env.VITE_API_URL || '';
159+
158160
protected renderLoader = () =>
159161
this.isLoading ? html`<slot name="loader"><div class="loader-animation"></div></slot>` : nothing;
160162

0 commit comments

Comments
 (0)