Refs: #68 less waiting for files to be rendered during import

This commit is contained in:
Roland Broekema 2026-01-05 10:57:49 +01:00
parent a634acc5e9
commit 6284e2ec0c
2 changed files with 11 additions and 9 deletions

View file

@ -1,7 +1,5 @@
import {App, normalizePath, Notice, Platform, TFile, TFolder, Vault, Workspace} from "obsidian";
import {getSettings} from "src/context/sharedSettingsContext";
import {RunType} from "src/insights/insight.d";
import {insightService} from "src/insights/insightService";
import {FileExistsModal} from "src/ui/modals/fileExistsModal";
import {createNameSlug} from "src/util/nameUtils";
@ -47,10 +45,7 @@ async function handleFileCreation(app: App, filePath: string, content: string) {
}
}).open();
} else {
const createdFile = await app.vault.create(filePath, content);
await new Promise(r => setTimeout(r, 50));
await insightService.process(RunType.IMMEDIATELY);
await openFile(createdFile, app.workspace);
await app.vault.adapter.write(filePath, content);
}
}
@ -59,7 +54,7 @@ export async function createContactFile(
folderPath: string,
content: string,
filename: string
) {
): Promise<string | undefined> {
const folder = app.vault.getAbstractFileByPath(folderPath !== '' ? folderPath : '/');
if (!folder) {
new Notice(`Can not find path: '${folderPath}'. Please update "Contacts" plugin settings`);
@ -71,9 +66,11 @@ export async function createContactFile(
if (parentFolder?.path?.contains(folderPath)) {
const filePath = normalizePath(fileJoin(parentFolder.path, filename));
await handleFileCreation(app, filePath, content);
return filePath;
} else {
const filePath = normalizePath(fileJoin(folderPath, filename));
await handleFileCreation(app, filePath, content);
return filePath;
}
}

View file

@ -7,10 +7,11 @@ import { getSettings } from "src/context/sharedSettingsContext";
import {
createContactFile,
createFileName,
findContactFiles, isFileInFolder,
findContactFiles, isFileInFolder, openFile,
openFilePicker,
saveVcardFilePicker
} from "src/file/file";
import { RunType } from "src/insights/insight.d";
import { insightService } from "src/insights/insightService";
import { ContactsPluginSettings } from "src/settings/settings";
import { useSettings } from "src/ui/hooks/settingsHook";
@ -48,6 +49,7 @@ const importVCFContacts = async (fileContent: string, app: App, settings: Contac
if (skipped > 0) new Notice(`Skipped ${skipped} contact(s) without name information`);
if (imported > 0) new Notice(`Imported ${imported} contact(s)`);
await insightService.process(RunType.IMMEDIATELY);
};
export const SidebarRootView = (props: SidebarRootViewProps) => {
@ -131,7 +133,10 @@ export const SidebarRootView = (props: SidebarRootViewProps) => {
async function createNewContact() {
const records = await vcard.createEmpty();
const mdContent = mdRender(records, mySettings.defaultHashtag);
await createContactFile(app, mySettings.contactsFolder, mdContent, createFileName(records));
const filePath = await createContactFile(app, mySettings.contactsFolder, mdContent, createFileName(records));
if(filePath) {
openFile(app.vault.getAbstractFileByPath(filePath) as TFile, workspace)
}
}
return (