When there isn't a active file it defaults to the default settings

This commit is contained in:
Lost Paul 2025-01-03 22:36:34 +01:00
parent 81d7236a1e
commit b1e03cd36b
2 changed files with 15 additions and 23 deletions

View file

@ -464,8 +464,9 @@ export function getCodeBlockEndLine(text: string, startLine: number, count = 1)
return line;
}
export async function getOverviews(plugin: FolderNotesPlugin, file: TFile) {
export async function getOverviews(plugin: FolderNotesPlugin, file: TFile | null) {
// is an object with unkown keys
if (!file) return [];
const overviews: { [key: string]: string }[] = [];
const content = await plugin.app.vault.read(file);
if (!content) return overviews;

View file

@ -53,7 +53,7 @@ export class FolderOverviewView extends ItemView {
ctx?: MarkdownPostProcessorContext,
file?: TFile | null
) {
this.contentEl = contentEl;
this.yaml = yaml;
this.defaultSettings = defaultSettings;
@ -67,17 +67,6 @@ export class FolderOverviewView extends ItemView {
}
const activeFile = plugin.app.workspace.getActiveFile();
if (!activeFile) {
let msg = contentEl.querySelector('.fn-no-file-msg');
if (!msg) {
msg = contentEl.createEl('p', { cls: 'fn-no-file-msg' });
}
msg.textContent = 'No active file found';
return;
} else {
const msg = contentEl.querySelector('.fn-no-file-msg');
if (msg) msg.remove();
}
const overviews = await getOverviews(plugin, activeFile);
@ -93,16 +82,18 @@ export class FolderOverviewView extends ItemView {
.setName('Select overview')
.setClass('fn-select-overview-setting')
.addDropdown((cb) => {
const options = overviews.reduce((acc, overview) => {
acc[overview.id] = parseOverviewTitle(
overview as any as yamlSettings,
plugin,
activeFile.parent
);
return acc;
}, {} as Record<string, string>);
cb.addOptions(options);
if (activeFile) {
const options = overviews.reduce((acc, overview) => {
acc[overview.id] = parseOverviewTitle(
overview as any as yamlSettings,
plugin,
activeFile.parent
);
return acc;
}, {} as Record<string, string>);
cb.addOptions(options);
}
cb.addOption('default', 'Default');
cb.setValue(yaml?.id ?? 'default');
console.log(yaml);