From 92c04c4c6cfe1be00058ee8bfcf53ce764ec9d43 Mon Sep 17 00:00:00 2001 From: Jacob Clarke Date: Sun, 15 Jan 2023 22:15:20 -0600 Subject: [PATCH 1/2] add settings to filter by default --- .gitignore | 1 + .../FolderContextViewComponent.tsx | 5 +- src/i18n.ts | 4 + src/settings.ts | 90 +++++++++++-------- 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 837f7f8..36629f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .env .DS_Store +undefined \ No newline at end of file diff --git a/src/components/ContextView/FolderContextViewComponent.tsx b/src/components/ContextView/FolderContextViewComponent.tsx index 5c394da..56cffab 100644 --- a/src/components/ContextView/FolderContextViewComponent.tsx +++ b/src/components/ContextView/FolderContextViewComponent.tsx @@ -22,7 +22,10 @@ export const FolderContextViewComponent = ( const folder = props.folder?.path; const path = folderContextFromFolder(props.plugin, folder); const ref = useRef(null); - const [flowOpen, setFlowOpen] = useState(false); + const [flowOpen, setFlowOpen] = useState( + props.plugin.settings.enableFolderNote && + props.plugin.settings.folderNoteOpenDefault + ); const folderNotePath = props.plugin.settings.folderNoteInsideFolder ? `${props.folder.path}/${props.folder.name}.md` : props.folder && props.folder.parent.path == "/" diff --git a/src/i18n.ts b/src/i18n.ts index 964378a..b9e4301 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -290,6 +290,10 @@ class T { name:"Enable Folder Note", desc:"Access the folder note in the folder page and hide the folder note from spaces" }, + folderNoteOpenDefault: { + name: 'Open Folder Note by Default', + desc: 'When accessing a folder, open the folder note by default.', + }, activeFile: { name: "Reveal Active File", desc: "Automatically reveal the active file in Spaces" diff --git a/src/settings.ts b/src/settings.ts index 85a55cd..e19e1a1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -27,6 +27,7 @@ export interface MakeMDPluginSettings { deleteFileOption: DeleteFileOption; autoOpenFileContext: boolean; expandedFolders: Record; + folderNoteOpenDefault: boolean; expandedSpaces: string[]; saveAllContextToFrontmatter: boolean; folderRank: StringTree; @@ -61,7 +62,7 @@ export const DEFAULT_SETTINGS: MakeMDPluginSettings = { editorFlow: true, internalLinkClickFlow: true, saveAllContextToFrontmatter: false, - editorFlowStyle: "seamless", + editorFlowStyle: 'seamless', autoOpenFileContext: false, spacesCompactMode: false, spacesEnabled: true, @@ -71,13 +72,14 @@ export const DEFAULT_SETTINGS: MakeMDPluginSettings = { spacesStickers: true, spacesDisablePatch: false, folderNoteInsideFolder: true, + folderNoteOpenDefault: false, sidebarTabs: true, showRibbon: true, - deleteFileOption: "trash", + deleteFileOption: 'trash', expandedFolders: {}, - expandedSpaces: ["/"], + expandedSpaces: ['/'], folderRank: { - node: "root", + node: 'root', children: [], isFolder: true, }, @@ -85,15 +87,15 @@ export const DEFAULT_SETTINGS: MakeMDPluginSettings = { fileIcons: [], spaces: [], pinnedSpaces: [], - menuTriggerChar: "/", - emojiTriggerChar: ":", - folderContextFile: "context", - tagContextFolder: "Context", - hiddenFiles: ["Context"], - hiddenExtensions: ["mdb"], - vaultSort: ["rank", true], - newFileLocation: "root", - newFileFolderPath: "", + menuTriggerChar: '/', + emojiTriggerChar: ':', + folderContextFile: 'context', + tagContextFolder: 'Context', + hiddenFiles: ['Context'], + hiddenExtensions: ['mdb'], + vaultSort: ['rank', true], + newFileLocation: 'root', + newFileFolderPath: '', }; export class MakeMDPluginSettingsTab extends PluginSettingTab { @@ -113,7 +115,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { let { containerEl } = this; containerEl.empty(); - containerEl.createEl("h2", { text: t.settings.sectionAppearance }); + containerEl.createEl('h2', { text: t.settings.sectionAppearance }); new Setting(containerEl) .setName(t.settings.sidebarTabs.name) .setDesc(t.settings.sidebarTabs.desc) @@ -121,7 +123,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { toggle.setValue(this.plugin.settings.sidebarTabs).onChange((value) => { this.plugin.settings.sidebarTabs = value; this.plugin.saveSettings(); - document.body.classList.toggle("mk-hide-tabs", !value); + document.body.classList.toggle('mk-hide-tabs', !value); }) ); new Setting(containerEl) @@ -131,7 +133,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { toggle.setValue(this.plugin.settings.showRibbon).onChange((value) => { this.plugin.settings.showRibbon = value; this.plugin.saveSettings(); - document.body.classList.toggle("mk-hide-ribbon", !value); + document.body.classList.toggle('mk-hide-ribbon', !value); }) ); @@ -149,7 +151,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { }) ); - containerEl.createEl("h2", { text: t.settings.sectionSidebar }); + containerEl.createEl('h2', { text: t.settings.sectionSidebar }); new Setting(containerEl) .setName(t.settings.spaces.name) .setDesc(t.settings.spaces.desc) @@ -191,6 +193,18 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { this.plugin.saveSettings(); }) ); + + new Setting(containerEl) + .setName(t.settings.folderNoteOpenDefault.name) + .setDesc(t.settings.folderNoteOpenDefault.desc) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.folderNoteOpenDefault) + .onChange((value) => { + this.plugin.settings.folderNoteOpenDefault = value; + this.plugin.saveSettings(); + }) + ); new Setting(containerEl) .setName(t.settings.activeFile.name) .setDesc(t.settings.activeFile.desc) @@ -202,7 +216,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { this.plugin.saveSettings(); }) ); - containerEl.createEl("h2", { text: "Context" }); + containerEl.createEl('h2', { text: 'Context' }); new Setting(containerEl) .setName(t.settings.openFileContext.name) @@ -228,7 +242,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { }) ); - containerEl.createEl("h2", { text: t.settings.sectionFlow }); + containerEl.createEl('h2', { text: t.settings.sectionFlow }); new Setting(containerEl) .setName(t.settings.internalLinkFlowEditor.name) .setDesc(t.settings.internalLinkFlowEditor.desc) @@ -255,26 +269,26 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { .setName(t.settings.editorFlowStyle.name) .setDesc(t.settings.editorFlowStyle.desc) .addDropdown((dropdown: DropdownComponent) => { - dropdown.addOption("classic", t.settings.editorFlowStyle.classic); - dropdown.addOption("seamless", t.settings.editorFlowStyle.seamless); - dropdown.addOption("minimal", t.settings.editorFlowStyle.minimal); + dropdown.addOption('classic', t.settings.editorFlowStyle.classic); + dropdown.addOption('seamless', t.settings.editorFlowStyle.seamless); + dropdown.addOption('minimal', t.settings.editorFlowStyle.minimal); dropdown .setValue(this.plugin.settings.editorFlowStyle) .onChange(async (value) => { this.plugin.settings.editorFlowStyle = value; - document.body.classList.toggle("mk-flow-classic", false); - document.body.classList.toggle("mk-flow-seamless", false); - document.body.classList.toggle("mk-flow-minimal", false); - if (value == "seamless") - document.body.classList.toggle("mk-flow-seamless", true); - if (value == "classic") - document.body.classList.toggle("mk-flow-classic", true); - if (value == "minimal") - document.body.classList.toggle("mk-flow-minimal", true); + document.body.classList.toggle('mk-flow-classic', false); + document.body.classList.toggle('mk-flow-seamless', false); + document.body.classList.toggle('mk-flow-minimal', false); + if (value == 'seamless') + document.body.classList.toggle('mk-flow-seamless', true); + if (value == 'classic') + document.body.classList.toggle('mk-flow-classic', true); + if (value == 'minimal') + document.body.classList.toggle('mk-flow-minimal', true); }); }); - containerEl.createEl("h2", { text: t.settings.sectionEditor }); + containerEl.createEl('h2', { text: t.settings.sectionEditor }); new Setting(containerEl) .setName(t.settings.makeChar.name) @@ -291,7 +305,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { let char = value[0]; if (value.trim().length === 2) { - char = value.replace(this.plugin.settings.menuTriggerChar, ""); + char = value.replace(this.plugin.settings.menuTriggerChar, ''); } text.setValue(char); @@ -339,7 +353,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { }) ); - containerEl.createEl("h2", { text: t.settings.sectionAdvanced }); + containerEl.createEl('h2', { text: t.settings.sectionAdvanced }); new Setting(containerEl) .setName(t.settings.spacesFileExplorerDual.name) @@ -380,13 +394,13 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { .setDesc(t.settings.spacesDeleteOption.desc) .addDropdown((dropdown) => { dropdown.addOption( - "permanent", + 'permanent', t.settings.spacesDeleteOptions.permanant ); - dropdown.addOption("trash", t.settings.spacesDeleteOptions.trash); + dropdown.addOption('trash', t.settings.spacesDeleteOptions.trash); dropdown.addOption( - "system-trash", - t.settings.spacesDeleteOptions["system-trash"] + 'system-trash', + t.settings.spacesDeleteOptions['system-trash'] ); dropdown.setValue(this.plugin.settings.deleteFileOption); dropdown.onChange((option: DeleteFileOption) => { From ee6f0e43c17c7488a9e722093f4aaa69d5347dd0 Mon Sep 17 00:00:00 2001 From: Jacob Clarke Date: Sun, 15 Jan 2023 22:28:02 -0600 Subject: [PATCH 2/2] updated to only open folder note by default if it already exists --- .gitignore | 3 ++- .../ContextView/FolderContextViewComponent.tsx | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 36629f3..ece2d46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .env .DS_Store -undefined \ No newline at end of file +undefined +.vscode \ No newline at end of file diff --git a/src/components/ContextView/FolderContextViewComponent.tsx b/src/components/ContextView/FolderContextViewComponent.tsx index 56cffab..6bd624d 100644 --- a/src/components/ContextView/FolderContextViewComponent.tsx +++ b/src/components/ContextView/FolderContextViewComponent.tsx @@ -22,15 +22,22 @@ export const FolderContextViewComponent = ( const folder = props.folder?.path; const path = folderContextFromFolder(props.plugin, folder); const ref = useRef(null); - const [flowOpen, setFlowOpen] = useState( - props.plugin.settings.enableFolderNote && - props.plugin.settings.folderNoteOpenDefault - ); + + const folderNotePath = props.plugin.settings.folderNoteInsideFolder ? `${props.folder.path}/${props.folder.name}.md` : props.folder && props.folder.parent.path == "/" ? `${props.folder.name}.md` : `${props.folder.parent.path}/${props.folder.name}.md`; + + const folderNote = getAbstractFileAtPath(app, folderNotePath); + + const [flowOpen, setFlowOpen] = useState( + props.plugin.settings.enableFolderNote && + props.plugin.settings.folderNoteOpenDefault && + folderNote + ); + const loadFile = async () => { const folderNote = getAbstractFileAtPath(app, folderNotePath); if (folderNote) {