Skip to content

Commit

Permalink
feat: ability-to-set-custom-fabric-path (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
aexshafii authored Nov 1, 2024
1 parent 591d752 commit 681cbbd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions plugin/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion plugin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,6 @@ export class FileOrganizerSettings {
selfHostingURL = "http://localhost:3000";
enableScreenpipe = false;
enableFabric = false;
fabricPatternPath = "_FileOrganizer2000/Fabric";
useFolderEmbeddings = false;
useVaultTitles = true;
enableFileRenaming = true;
Expand Down
4 changes: 2 additions & 2 deletions plugin/views/organizer/fabric-classification-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const FabricClassificationBox: React.FC<

const fabricDropdownRef = React.useRef<HTMLDivElement>(null);
const patternsPath = React.useMemo(
() => `${plugin.settings.fabricPatternPath.replace(/\/$/, "")}/patterns`,
[plugin.settings.fabricPatternPath]
() => `${plugin.settings.fabricPaths}/patterns`,
[plugin.settings.fabricPaths]
);

/**
Expand Down
8 changes: 3 additions & 5 deletions plugin/views/settings/fabric-prompt-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ export const FabricPromptManager: React.FC<FabricPromptManagerProps> = ({ 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);

Expand All @@ -46,15 +44,15 @@ export const FabricPromptManager: React.FC<FabricPromptManagerProps> = ({ 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)) {
localSha = await plugin.app.vault.adapter.read(localShaPath);
}

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);

Expand Down
18 changes: 14 additions & 4 deletions plugin/views/settings/file-config-tab.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +15,7 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ 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<Record<string, string>>({});
const [pathExistence, setPathExistence] = useState<Record<string, boolean>>({});
Expand Down Expand Up @@ -70,7 +71,8 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ plugin }) => {
logFolderPath,
defaultDestinationPath,
backupFolderPath,
templatePaths
templatePaths,
fabricPaths
];

const existenceResults = await Promise.all(
Expand All @@ -81,7 +83,7 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ plugin }) => {
};

checkPaths();
}, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, backupFolderPath, templatePaths]);
}, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, backupFolderPath, templatePaths, fabricPaths]);

useEffect(() => {
const newWarnings: Record<string, string> = {};
Expand All @@ -98,6 +100,7 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ plugin }) => {
checkPath(defaultDestinationPath, 'defaultDestinationPath');
checkPath(backupFolderPath, 'backupFolderPath');
checkPath(templatePaths, 'templatePaths');
checkPath(fabricPaths, 'fabricPaths');

// Special check for ignoreFolders
if (ignoreFolders !== "*") {
Expand All @@ -108,7 +111,7 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ plugin }) => {
}

setWarnings(newWarnings);
}, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, ignoreFolders, backupFolderPath, templatePaths]);
}, [pathToWatch, attachmentsPath, logFolderPath, defaultDestinationPath, ignoreFolders, backupFolderPath, templatePaths, fabricPaths]);

const renderSettingItem = (
name: string,
Expand Down Expand Up @@ -204,6 +207,13 @@ export const FileConfigTab: React.FC<FileConfigTabProps> = ({ 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'
)}
</div>
);
};

0 comments on commit 681cbbd

Please sign in to comment.