diff --git a/plugin/index.ts b/plugin/index.ts index 2d7df5be..51f2045d 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -642,13 +642,11 @@ export default class FileOrganizer extends Plugin { } } - async createFileInInbox(content: string): Promise { - const fileName = `chunk_${Date.now()}.md`; + + async createFileInInbox(title: string, content: string): Promise { + const fileName = `${title}.md`; const filePath = `${this.settings.pathToWatch}/${fileName}`; await this.app.vault.create(filePath, content); - await this.processFileV2( - this.app.vault.getAbstractFileByPath(filePath) as TFile - ); } async _experimentalIdentifyConcepts(content: string): Promise { diff --git a/plugin/views/organizer/chunks.tsx b/plugin/views/organizer/chunks.tsx index cb83616c..9d67f82d 100644 --- a/plugin/views/organizer/chunks.tsx +++ b/plugin/views/organizer/chunks.tsx @@ -8,28 +8,57 @@ interface DocumentChunksProps { activeFile: TFile; } -export const DocumentChunks: React.FC = ({ plugin, activeFile }) => { +export const AtomicNotes: React.FC = ({ plugin, activeFile }) => { const [concepts, setConcepts] = React.useState([]); const [chunks, setChunks] = React.useState<{ concept: string; content: string }[]>([]); const [loading, setLoading] = React.useState(false); + const [progress, setProgress] = React.useState(""); const parseDocument = async () => { setLoading(true); + setProgress("Starting analysis..."); + setConcepts([]); + setChunks([]); + try { const content = await plugin.app.vault.read(activeFile); - const result = await plugin.identifyConceptsAndFetchChunks(content); - setConcepts(result.map(c => c.name)); - setChunks(result.map(c => ({ concept: c.name, content: c.chunk }))); + + // Handle streaming updates through the progress callback + const allConcepts = await plugin.identifyConceptsAndFetchChunks( + content, + (newConcepts) => { + // Update concepts (names only) + setConcepts(prev => { + const newNames = newConcepts.map(c => c.name); + return Array.from(new Set([...prev, ...newNames])); + }); + + // Update chunks (full data) + setChunks(prev => { + const newChunks = newConcepts.map(c => ({ + concept: c.name, + content: c.chunk + })); + return [...prev, ...newChunks]; + }); + + setProgress(`Processing concepts: ${newConcepts.length} found...`); + } + ); + + setProgress("Analysis complete!"); } catch (error) { logger.error("Error parsing document:", error); + setProgress("Error occurred during analysis"); } finally { setLoading(false); + setTimeout(() => setProgress(""), 3000); } }; - const addToInbox = async (chunkContent: string) => { + const addToInbox = async (title: string, chunkContent: string) => { try { - await plugin.createFileInInbox(chunkContent); + await plugin.createFileInInbox(title, chunkContent); } catch (error) { logger.error("Error adding to inbox:", error); } @@ -37,22 +66,45 @@ export const DocumentChunks: React.FC = ({ plugin, activeFi return (
- - {concepts.map((concept, index) => ( -
-

{concept}

- {chunks - .filter(chunk => chunk.concept === concept) - .map((chunk, chunkIndex) => ( -
-

{chunk.content}

- -
- ))} -
- ))} +
+ + {progress && ( + {progress} + )} +
+ +
+ {concepts.map((concept, index) => ( +
+

{concept}

+ {chunks + .filter(chunk => chunk.concept === concept) + .map((chunk, chunkIndex) => ( +
+

{chunk.content}

+ +
+ ))} +
+ ))} +
); }; \ No newline at end of file diff --git a/plugin/views/organizer/organizer.tsx b/plugin/views/organizer/organizer.tsx index dbe86fce..2040b143 100644 --- a/plugin/views/organizer/organizer.tsx +++ b/plugin/views/organizer/organizer.tsx @@ -5,7 +5,7 @@ import { debounce } from "lodash"; import { SectionHeader } from "./components/section-header"; import { SimilarTags } from "./tags"; -import { DocumentChunks } from "./chunks"; +import { AtomicNotes } from "./chunks"; import { RenameSuggestion } from "./titles/box"; import { SimilarFolderBox } from "./folders/box"; import { RefreshButton } from "./components/refresh-button"; @@ -241,7 +241,7 @@ export const AssistantView: React.FC = ({ <> {renderSection( - , + , "Error loading atomic notes" )}