From f2352005518fb450d08d753f5ff6406b2b99d36c Mon Sep 17 00:00:00 2001 From: Lost Paul <70213368+LostPaul@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:19:38 +0200 Subject: [PATCH] Included file types bug & sort after bug --- manifest.json | 2 +- src/folderOverview/FolderOverview.ts | 31 ++++++++++++++++------------ src/folderOverview/ModalSettings.ts | 2 +- src/functions/ListComponent.ts | 1 + 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/manifest.json b/manifest.json index 6c269ec..1ffbc0a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "folder-notes", "name": "Folder notes", - "version": "1.5.9", + "version": "1.5.10", "minAppVersion": "0.15.0", "description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.", "author": "Lost Paul", diff --git a/src/folderOverview/FolderOverview.ts b/src/folderOverview/FolderOverview.ts index 73c3c04..a2ae940 100644 --- a/src/folderOverview/FolderOverview.ts +++ b/src/folderOverview/FolderOverview.ts @@ -64,7 +64,7 @@ export class FolderOverview { const root = el.createEl('div', { cls: 'folder-overview' }); const titleEl = root.createEl('h1', { cls: 'folder-overview-title' }); const ul = root.createEl('ul', { cls: 'folder-overview-list' }); - if (this.yaml.includeTypes.length === 0) { return; } + if (this.yaml.includeTypes.length === 0) { return this.addEditButton(root); } let files: TAbstractFile[] = []; const sourceFile = plugin.app.vault.getAbstractFileByPath(ctx.sourcePath); if (!sourceFile) return; @@ -106,14 +106,7 @@ export class FolderOverview { files = this.getAllFiles(files, sourceFolderPath, this.yaml.depth); } if (files.length === 0) { - const editButton = root.createEl('button', { cls: 'folder-overview-edit-button' }); - editButton.innerText = 'Edit overview'; - editButton.addEventListener('click', (e) => { - e.stopImmediatePropagation(); - e.preventDefault(); - e.stopPropagation(); - new FolderOverviewSettings(plugin.app, plugin, this.yaml, ctx, el).open(); - }, { capture: true }); + this.addEditButton(root) } files = this.sortFiles(files, this.yaml, plugin); @@ -124,7 +117,6 @@ export class FolderOverview { const gridArticle = gridItem.createEl('article', { cls: 'folder-overview-grid-item-article' }); if (file instanceof TFile) { const fileContent = await plugin.app.vault.read(file); - // skip --- yaml const descriptionEl = gridArticle.createEl('p', { cls: 'folder-overview-grid-item-description' }); let description = fileContent.split('\n')[0]; if (description.length > 64) { @@ -160,11 +152,24 @@ export class FolderOverview { }); } } - if (this.yaml.style !== 'list') { return; } - if (this.yaml.includeTypes.length > 1 && (!this.yaml.showEmptyFolders || this.yaml.onlyIncludeSubfolders)) { + const overviewListEl = el.childNodes[0].childNodes[1]; + if (overviewListEl && overviewListEl.childNodes.length === 0) { + this.addEditButton(root); + } + if (this.yaml.includeTypes.length > 1 && (!this.yaml.showEmptyFolders || this.yaml.onlyIncludeSubfolders) && this.yaml.style === 'list') { this.removeEmptyFolders(ul, 1, this.yaml); } } + addEditButton(root: HTMLElement) { + const editButton = root.createEl('button', { cls: 'folder-overview-edit-button' }); + editButton.innerText = 'Edit overview'; + editButton.addEventListener('click', (e) => { + e.stopImmediatePropagation(); + e.preventDefault(); + e.stopPropagation(); + new FolderOverviewSettings(this.plugin.app, this.plugin, this.yaml, this.ctx, this.el).open(); + }, { capture: true }); + } cloneFileExplorerView(plugin: FolderNotesPlugin, ctx: MarkdownPostProcessorContext, root: HTMLElement, yaml: yamlSettings, pathBlacklist: string[]) { const folder = plugin.getEL(this.yaml.folderPath) let folderElement = folder?.parentElement; @@ -511,7 +516,7 @@ export function getCodeBlockEndLine(text: string, startLine: number, count = 1) let line = startLine + 1; const lines = text.split('\n'); while (line < lines.length) { - if (count > 20) { return -1; } + if (count > 50) { return -1; } if (lines[line].startsWith('```')) { return line; } diff --git a/src/folderOverview/ModalSettings.ts b/src/folderOverview/ModalSettings.ts index 4ae1d1e..d559d83 100644 --- a/src/folderOverview/ModalSettings.ts +++ b/src/folderOverview/ModalSettings.ts @@ -29,7 +29,7 @@ export class FolderOverviewSettings extends Modal { includeTypes: includeTypes.map((type) => type.toLowerCase()) as includeTypes[], disableFileTag: yaml?.disableFileTag === undefined || yaml?.disableFileTag === null ? plugin.settings.defaultOverview.disableFileTag : yaml?.disableFileTag, sortBy: yaml?.sortBy || plugin.settings.defaultOverview.sortBy, - sortByAsc: yaml?.sortByAsc || plugin.settings.defaultOverview.sortByAsc, + sortByAsc: yaml?.sortByAsc === undefined || yaml?.sortByAsc === null ? plugin.settings.defaultOverview.sortByAsc : yaml?.sortByAsc, showEmptyFolders: yaml?.showEmptyFolders === undefined || yaml?.showEmptyFolders === null ? plugin.settings.defaultOverview.showEmptyFolders : yaml?.showEmptyFolders, onlyIncludeSubfolders: yaml?.onlyIncludeSubfolders === undefined || yaml?.onlyIncludeSubfolders === null ? plugin.settings.defaultOverview.onlyIncludeSubfolders : yaml?.onlyIncludeSubfolders, storeFolderCondition: yaml?.storeFolderCondition === undefined || yaml?.storeFolderCondition === null ? plugin.settings.defaultOverview.storeFolderCondition : yaml?.storeFolderCondition, diff --git a/src/functions/ListComponent.ts b/src/functions/ListComponent.ts index cbf5d52..3b726c5 100644 --- a/src/functions/ListComponent.ts +++ b/src/functions/ListComponent.ts @@ -52,6 +52,7 @@ export default class ListComponent { async addValue(value: string) { this.values.push(value); this.addElement(value); + console.log(this.values); this.modal.yaml.includeTypes = this.values as includeTypes[]; return this; }