feat(playground): enhance file tree structure by adding path property to FileTree
This commit is contained in:
parent
2cdd9adf3e
commit
ac7e34dfc5
@ -26,12 +26,13 @@ import { ChevronRight, File, Folder, FolderOpen } from "lucide-react";
|
|||||||
|
|
||||||
interface FileTree {
|
interface FileTree {
|
||||||
name: string;
|
name: string;
|
||||||
|
path: string;
|
||||||
type: "blob" | "tree";
|
type: "blob" | "tree";
|
||||||
children?: { [key: string]: FileTree };
|
children?: { [key: string]: FileTree };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildFileTree(tree: GitEntry[]): FileTree {
|
export function buildFileTree(tree: GitEntry[]): FileTree {
|
||||||
const root: FileTree = { name: "", type: "tree", children: {} };
|
const root: FileTree = { name: "", type: "tree", path: "", children: {} };
|
||||||
|
|
||||||
tree.forEach((entry: GitEntry) => {
|
tree.forEach((entry: GitEntry) => {
|
||||||
if (!entry.path) return;
|
if (!entry.path) return;
|
||||||
@ -39,14 +40,17 @@ export function buildFileTree(tree: GitEntry[]): FileTree {
|
|||||||
const pathParts = entry.path.split("/");
|
const pathParts = entry.path.split("/");
|
||||||
let currentLevel = root;
|
let currentLevel = root;
|
||||||
|
|
||||||
pathParts.forEach((part: string) => {
|
pathParts.forEach((part: string, index: number) => {
|
||||||
if (!currentLevel.children) {
|
if (!currentLevel.children) {
|
||||||
currentLevel.children = {};
|
currentLevel.children = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fullPath = pathParts.slice(0, index + 1).join("/");
|
||||||
|
|
||||||
if (!currentLevel.children[part]) {
|
if (!currentLevel.children[part]) {
|
||||||
currentLevel.children[part] = {
|
currentLevel.children[part] = {
|
||||||
name: part,
|
name: part,
|
||||||
|
path: fullPath,
|
||||||
type: entry.type as "blob" | "tree",
|
type: entry.type as "blob" | "tree",
|
||||||
children: {},
|
children: {},
|
||||||
};
|
};
|
||||||
@ -78,6 +82,7 @@ export function PlaygroundSidebar({
|
|||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const [fileTree, setFileTree] = React.useState<FileTree>({
|
const [fileTree, setFileTree] = React.useState<FileTree>({
|
||||||
name: "",
|
name: "",
|
||||||
|
path: "",
|
||||||
type: "tree",
|
type: "tree",
|
||||||
children: {},
|
children: {},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user