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[]> { 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;
} }

View File

@@ -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);
}) })
); );