From 681cbbd03b29ffba4abc776b8402b5f51c29810a Mon Sep 17 00:00:00 2001 From: Alexandre Shafii <46509400+aexshafii@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:24:32 +0100 Subject: [PATCH] feat: ability-to-set-custom-fabric-path (#262) --- plugin/fileUtils.ts | 1 + plugin/index.ts | 2 +- plugin/settings.ts | 2 +- .../organizer/fabric-classification-box.tsx | 4 ++-- .../views/settings/fabric-prompt-manager.tsx | 8 +++----- plugin/views/settings/file-config-tab.tsx | 18 ++++++++++++++---- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/plugin/fileUtils.ts b/plugin/fileUtils.ts index 70215a68..33e27a06 100644 --- a/plugin/fileUtils.ts +++ b/plugin/fileUtils.ts @@ -16,6 +16,7 @@ export async function checkAndCreateFolders( await ensureFolderExists(app, settings.attachmentsPath); await ensureFolderExists(app, settings.logFolderPath); await ensureFolderExists(app, settings.templatePaths); + await ensureFolderExists(app, settings.fabricPaths); await ensureFolderExists(app, settings.stagingFolder); await ensureFolderExists(app, settings.backupFolderPath); } diff --git a/plugin/index.ts b/plugin/index.ts index a6de2279..50f473aa 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -864,7 +864,7 @@ export default class FileOrganizer extends Plugin { getClassificationsForFabric(): string[] { const patternFolder = this.app.vault.getAbstractFileByPath( - "_FileOrganizer2000/patterns" + this.settings.fabricPaths ); if (!patternFolder || !(patternFolder instanceof TFolder)) { console.error("Pattern folder not found or is not a valid folder."); diff --git a/plugin/settings.ts b/plugin/settings.ts index ef2a3fa2..73695b2b 100644 --- a/plugin/settings.ts +++ b/plugin/settings.ts @@ -8,6 +8,7 @@ export class FileOrganizerSettings { logFolderPath = "_FileOrganizer2000/Logs"; backupFolderPath = "_FileOrganizer2000/Backups"; templatePaths = "_FileOrganizer2000/Templates"; + fabricPaths = "_FileOrganizer2000/Fabric"; useSimilarTags = true; renameInstructions = "Create a concise, descriptive name for the document based on its key content. Prioritize clarity and searchability, using specific terms that will make the document easy to find later. Avoid generic words and focus on unique, identifying elements."; usePro = true; @@ -24,7 +25,6 @@ export class FileOrganizerSettings { selfHostingURL = "http://localhost:3000"; enableScreenpipe = false; enableFabric = false; - fabricPatternPath = "_FileOrganizer2000/Fabric"; useFolderEmbeddings = false; useVaultTitles = true; enableFileRenaming = true; diff --git a/plugin/views/organizer/fabric-classification-box.tsx b/plugin/views/organizer/fabric-classification-box.tsx index 9c2adc3b..87af3fa7 100644 --- a/plugin/views/organizer/fabric-classification-box.tsx +++ b/plugin/views/organizer/fabric-classification-box.tsx @@ -35,8 +35,8 @@ export const FabricClassificationBox: React.FC< const fabricDropdownRef = React.useRef(null); const patternsPath = React.useMemo( - () => `${plugin.settings.fabricPatternPath.replace(/\/$/, "")}/patterns`, - [plugin.settings.fabricPatternPath] + () => `${plugin.settings.fabricPaths}/patterns`, + [plugin.settings.fabricPaths] ); /** diff --git a/plugin/views/settings/fabric-prompt-manager.tsx b/plugin/views/settings/fabric-prompt-manager.tsx index 731f2718..7a2ded66 100644 --- a/plugin/views/settings/fabric-prompt-manager.tsx +++ b/plugin/views/settings/fabric-prompt-manager.tsx @@ -14,12 +14,10 @@ export const FabricPromptManager: React.FC = ({ plugin useEffect(() => { checkExistingPrompts(); - plugin.settings.fabricPatternPath = "_FileOrganizer2000/Fabric/"; - plugin.saveSettings(); }, []); const checkExistingPrompts = async () => { - const patternsPath = plugin.settings.fabricPatternPath; + const patternsPath = plugin.settings.fabricPaths; await plugin.ensureFolderExists(patternsPath); const patternFolder = plugin.app.vault.getAbstractFileByPath(patternsPath); @@ -46,7 +44,7 @@ export const FabricPromptManager: React.FC = ({ plugin try { const latestSha = await getLatestCommitSha(); - const localShaPath = `${plugin.settings.fabricPatternPath}/.last_commit_sha`; + const localShaPath = `${plugin.settings.fabricPaths}/.last_commit_sha`; let localSha = ''; if (await plugin.app.vault.adapter.exists(localShaPath)) { @@ -54,7 +52,7 @@ export const FabricPromptManager: React.FC = ({ plugin } if (localSha !== latestSha) { - const patternsPath = plugin.settings.fabricPatternPath; + const patternsPath = plugin.settings.fabricPaths; await plugin.app.vault.adapter.rmdir(patternsPath, true); await plugin.ensureFolderExists(patternsPath); diff --git a/plugin/views/settings/file-config-tab.tsx b/plugin/views/settings/file-config-tab.tsx index 25f53afd..9c18292f 100644 --- a/plugin/views/settings/file-config-tab.tsx +++ b/plugin/views/settings/file-config-tab.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import FileOrganizer from '../../index'; import { cleanPath } from '../../../utils'; -import { normalizePath, Vault } from 'obsidian'; +import { normalizePath } from 'obsidian'; interface FileConfigTabProps { plugin: FileOrganizer; @@ -15,6 +15,7 @@ export const FileConfigTab: React.FC = ({ plugin }) => { const [ignoreFolders, setIgnoreFolders] = useState(plugin.settings.ignoreFolders.join(',')); const [backupFolderPath, setBackupFolderPath] = useState(plugin.settings.backupFolderPath); const [templatePaths, setTemplatePaths] = useState(plugin.settings.templatePaths); + const [fabricPaths, setFabricPaths] = useState(plugin.settings.fabricPaths); const [warnings, setWarnings] = useState>({}); const [pathExistence, setPathExistence] = useState>({}); @@ -70,7 +71,8 @@ export const FileConfigTab: React.FC = ({ plugin }) => { logFolderPath, defaultDestinationPath, backupFolderPath, - templatePaths + templatePaths, + fabricPaths ]; const existenceResults = await Promise.all( @@ -81,7 +83,7 @@ export const FileConfigTab: React.FC = ({ plugin }) => { }; checkPaths(); - }, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, backupFolderPath, templatePaths]); + }, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, backupFolderPath, templatePaths, fabricPaths]); useEffect(() => { const newWarnings: Record = {}; @@ -98,6 +100,7 @@ export const FileConfigTab: React.FC = ({ plugin }) => { checkPath(defaultDestinationPath, 'defaultDestinationPath'); checkPath(backupFolderPath, 'backupFolderPath'); checkPath(templatePaths, 'templatePaths'); + checkPath(fabricPaths, 'fabricPaths'); // Special check for ignoreFolders if (ignoreFolders !== "*") { @@ -108,7 +111,7 @@ export const FileConfigTab: React.FC = ({ plugin }) => { } setWarnings(newWarnings); - }, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, ignoreFolders, backupFolderPath, templatePaths]); + }, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, ignoreFolders, backupFolderPath, templatePaths, fabricPaths]); const renderSettingItem = ( name: string, @@ -204,6 +207,13 @@ export const FileConfigTab: React.FC = ({ plugin }) => { (e) => handleSettingChange(e.target.value, setTemplatePaths, 'templatePaths'), 'templatePaths' )} + {renderSettingItem( + "Fabric patterns folder", + "Choose a folder for fabric patterns.", + fabricPaths, + (e) => handleSettingChange(e.target.value, setFabricPaths, 'fabricPaths'), + 'fabricPaths' + )} ); };