mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
No need to use then or finally in async functions after an await
This commit is contained in:
@@ -78,12 +78,12 @@ export class KhojModal extends SuggestModal<SearchResult> {
|
|||||||
async getSuggestions(query: string): Promise<SearchResult[]> {
|
async getSuggestions(query: string): Promise<SearchResult[]> {
|
||||||
// Query Khoj backend for search results
|
// Query Khoj backend for search results
|
||||||
let encodedQuery = encodeURIComponent(query);
|
let encodedQuery = encodeURIComponent(query);
|
||||||
let searchUrl = `${this.setting.khojUrl}/api/search?q=${encodedQuery}&n=${this.setting.resultsCount}&r=${this.rerank}&t=markdown`
|
let searchUrl = `${this.setting.khojUrl}/api/search?q=${encodedQuery}&n=${this.setting.resultsCount}&r=${this.rerank}&t=markdown`;
|
||||||
let results = await request(searchUrl)
|
let response = await request(searchUrl);
|
||||||
.then(response => JSON.parse(response))
|
let data = JSON.parse(response);
|
||||||
.then(data => data
|
let results = data
|
||||||
.filter((result: any) => !this.find_similar_notes || !result.additional.file.endsWith(this.app.workspace.getActiveFile()?.path))
|
.filter((result: any) => !this.find_similar_notes || !result.additional.file.endsWith(this.app.workspace.getActiveFile()?.path))
|
||||||
.map((result: any) => { return { entry: result.entry, file: result.additional.file } as SearchResult; }));
|
.map((result: any) => { return { entry: result.entry, file: result.additional.file } as SearchResult; });
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ export class KhojSettingTab extends PluginSettingTab {
|
|||||||
.setValue(`${this.plugin.settings.khojUrl}`)
|
.setValue(`${this.plugin.settings.khojUrl}`)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.khojUrl = value.trim();
|
this.plugin.settings.khojUrl = value.trim();
|
||||||
await this.plugin.saveSettings()
|
await this.plugin.saveSettings();
|
||||||
.finally(() => containerEl.firstElementChild?.setText(this.getBackendStatusMessage()));
|
containerEl.firstElementChild?.setText(this.getBackendStatusMessage());
|
||||||
}));
|
}));
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Results Count')
|
.setName('Results Count')
|
||||||
@@ -60,15 +60,15 @@ export class KhojSettingTab extends PluginSettingTab {
|
|||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
// Disable button while updating index
|
// Disable button while updating index
|
||||||
button.setButtonText('Updating...');
|
button.setButtonText('Updating...');
|
||||||
button.removeCta()
|
button.removeCta();
|
||||||
indexVaultSetting = indexVaultSetting.setDisabled(true);
|
indexVaultSetting = indexVaultSetting.setDisabled(true);
|
||||||
|
|
||||||
await request(`${this.plugin.settings.khojUrl}/api/update?t=markdown&force=true`)
|
await request(`${this.plugin.settings.khojUrl}/api/update?t=markdown&force=true`);
|
||||||
.then(() => new Notice('✅ Updated Khoj index.'));
|
new Notice('✅ Updated Khoj index.');
|
||||||
|
|
||||||
// Re-enable button once index is updated
|
// Re-enable button once index is updated
|
||||||
button.setButtonText('Update');
|
button.setButtonText('Update');
|
||||||
button.setCta()
|
button.setCta();
|
||||||
indexVaultSetting = indexVaultSetting.setDisabled(false);
|
indexVaultSetting = indexVaultSetting.setDisabled(false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user