No need to use then or finally in async functions after an await

This commit is contained in:
Debanjum Singh Solanky 2023-01-26 17:05:53 -03:00
parent 4070be637c
commit 4456cf5c8f
2 changed files with 12 additions and 12 deletions

View file

@ -78,12 +78,12 @@ export class KhojModal extends SuggestModal<SearchResult> {
async getSuggestions(query: string): Promise<SearchResult[]> {
// Query Khoj backend for search results
let encodedQuery = encodeURIComponent(query);
let searchUrl = `${this.setting.khojUrl}/api/search?q=${encodedQuery}&n=${this.setting.resultsCount}&r=${this.rerank}&t=markdown`
let results = await request(searchUrl)
.then(response => JSON.parse(response))
.then(data => data
.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; }));
let searchUrl = `${this.setting.khojUrl}/api/search?q=${encodedQuery}&n=${this.setting.resultsCount}&r=${this.rerank}&t=markdown`;
let response = await request(searchUrl);
let data = JSON.parse(response);
let results = data
.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; });
return results;
}

View file

@ -36,8 +36,8 @@ export class KhojSettingTab extends PluginSettingTab {
.setValue(`${this.plugin.settings.khojUrl}`)
.onChange(async (value) => {
this.plugin.settings.khojUrl = value.trim();
await this.plugin.saveSettings()
.finally(() => containerEl.firstElementChild?.setText(this.getBackendStatusMessage()));
await this.plugin.saveSettings();
containerEl.firstElementChild?.setText(this.getBackendStatusMessage());
}));
new Setting(containerEl)
.setName('Results Count')
@ -60,15 +60,15 @@ export class KhojSettingTab extends PluginSettingTab {
.onClick(async () => {
// Disable button while updating index
button.setButtonText('Updating...');
button.removeCta()
button.removeCta();
indexVaultSetting = indexVaultSetting.setDisabled(true);
await request(`${this.plugin.settings.khojUrl}/api/update?t=markdown&force=true`)
.then(() => new Notice('✅ Updated Khoj index.'));
await request(`${this.plugin.settings.khojUrl}/api/update?t=markdown&force=true`);
new Notice('✅ Updated Khoj index.');
// Re-enable button once index is updated
button.setButtonText('Update');
button.setCta()
button.setCta();
indexVaultSetting = indexVaultSetting.setDisabled(false);
})
);