mirror of
https://github.com/lordmathis/lemma.git
synced 2025-12-24 10:34:22 +00:00
Add FolderSelector component and integrate with CreateFileModal
This commit is contained in:
44
app/src/utils/fileTreeUtils.ts
Normal file
44
app/src/utils/fileTreeUtils.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { FileNode } from '@/types/models';
|
||||
|
||||
/**
|
||||
* Recursively filter tree to only include folders
|
||||
* @param nodes - Array of FileNode objects
|
||||
* @returns New tree structure with only folder nodes
|
||||
*/
|
||||
export const filterToFolders = (nodes: FileNode[]): FileNode[] => {
|
||||
return nodes
|
||||
.filter((node) => node.children !== undefined)
|
||||
.map((node) => {
|
||||
const filtered: FileNode = {
|
||||
id: node.id,
|
||||
name: node.name,
|
||||
path: node.path,
|
||||
};
|
||||
if (node.children) {
|
||||
filtered.children = filterToFolders(node.children);
|
||||
}
|
||||
return filtered;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a specific folder node by its path
|
||||
* @param nodes - Array of FileNode objects
|
||||
* @param path - Path to search for
|
||||
* @returns The found FileNode or null
|
||||
*/
|
||||
export const findFolderByPath = (
|
||||
nodes: FileNode[],
|
||||
path: string
|
||||
): FileNode | null => {
|
||||
for (const node of nodes) {
|
||||
if (node.path === path && node.children !== undefined) {
|
||||
return node;
|
||||
}
|
||||
if (node.children) {
|
||||
const found = findFolderByPath(node.children, path);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user