-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
241 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { assets } from "@kaplayjs/crew"; | ||
import { type FC, type PropsWithChildren, useMemo, useState } from "react"; | ||
import { cn } from "../../util/cn"; | ||
import { FileToolbar } from "./FileToolbar"; | ||
import "./FileFolder.css"; | ||
import { useProject } from "../../hooks/useProject"; | ||
import type { FileFolder, FileKind } from "../../stores/storage/files"; | ||
import { FileEntry } from "./FileEntry"; | ||
|
||
type Props = PropsWithChildren<{ | ||
level: 0 | 1 | 2; | ||
title?: string; | ||
toolbar?: boolean; | ||
/** Kind of files on Folder */ | ||
kind?: FileKind; | ||
/** Folder */ | ||
folder: FileFolder; | ||
}>; | ||
|
||
const paddingLevels = { | ||
0: "pl-0", | ||
1: "pl-4", | ||
2: "pl-8", | ||
}; | ||
|
||
export const FileFold: FC<Props> = (props) => { | ||
const [folded, setFolded] = useState(false); | ||
const { getFilesByFolder } = useProject(); | ||
const files = useMemo(() => getFilesByFolder(props.folder), [props.folder]); | ||
|
||
return ( | ||
<div className="mb-2"> | ||
<div className="flex justify-between"> | ||
{props.title && ( | ||
<h2 className="text-lg font-medium">{props.title}</h2> | ||
)} | ||
|
||
{(props.toolbar && props.kind) && ( | ||
<FileToolbar | ||
kind={props.kind} | ||
> | ||
<button | ||
className="btn btn-ghost btn-xs rounded-sm px-1" | ||
onClick={() => setFolded(!folded)} | ||
> | ||
<img | ||
src={assets.arrow.outlined} | ||
alt={folded ? "Open folder" : "Close folder"} | ||
data-folded={folded} | ||
className="folded-icon | h-4" | ||
/> | ||
</button> | ||
</FileToolbar> | ||
)} | ||
</div> | ||
|
||
<ul | ||
className={cn(paddingLevels[props.level], { | ||
"hidden": folded, | ||
})} | ||
> | ||
{files.length === 0 | ||
? ( | ||
<li className="text-gray-500 text-xs"> | ||
Create an {props.folder} to start | ||
</li> | ||
) | ||
: ( | ||
files.map((file) => { | ||
return ( | ||
<li key={file.name}> | ||
<FileEntry | ||
file={file} | ||
/> | ||
</li> | ||
); | ||
}) | ||
)} | ||
</ul> | ||
</div> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,20 @@ | ||
import { useProject } from "../../hooks/useProject"; | ||
import FileEntry from "./FileEntry"; | ||
import FileFolder from "./FileFolder"; | ||
import { View } from "../UI/View"; | ||
import { FileFold } from "./FileFold"; | ||
|
||
export const FileTree = () => { | ||
const { | ||
getFile, | ||
getFilesByFolder, | ||
getProject, | ||
} = useProject(); | ||
|
||
return ( | ||
<div className="flex flex-col p-2 gap-2"> | ||
{getProject().mode === "pj" && ( | ||
<> | ||
<FileFolder level={1} title="Scenes"> | ||
{getFilesByFolder("scenes").length === 0 | ||
? ( | ||
<li className="text-gray-500 text-xs"> | ||
No scenes yet | ||
</li> | ||
) | ||
: ( | ||
getFilesByFolder("scenes").map((file) => { | ||
return ( | ||
<li key={file.name}> | ||
<FileEntry | ||
file={file} | ||
/> | ||
</li> | ||
); | ||
}) | ||
)} | ||
</FileFolder> | ||
<FileFolder level={0} toolbar={false}> | ||
<li> | ||
<> | ||
<FileEntry file={getFile("main.js")!} /> | ||
<FileEntry file={getFile("kaplay.js")!} /> | ||
<FileEntry file={getFile("assets.js")!} /> | ||
</> | ||
</li> | ||
</FileFolder> | ||
</> | ||
)} | ||
</div> | ||
<View direction={"column"} padding={2} gap={2}> | ||
<FileFold | ||
level={1} | ||
title="Scenes" | ||
folder="scenes" | ||
kind="scene" | ||
toolbar | ||
/> | ||
<FileFold | ||
folder="root" | ||
level={0} | ||
/> | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.