-
Notifications
You must be signed in to change notification settings - Fork 0
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
85 changed files
with
2,188 additions
and
173 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
"react-dom": "18.3.1", | ||
"react-router": "6.26.0", | ||
"react-router-dom": "6.26.0", | ||
"sass": "1.77.8" | ||
"sass": "1.77.8", | ||
"yaml": "^2.5.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
max-width: 200px; | ||
|
||
.outlet { | ||
flex: 1; | ||
|
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
13 changes: 11 additions & 2 deletions
13
app/client/src/modules/application/components/header/header.component.tsx
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,11 +1,20 @@ | ||
import React from "react"; | ||
import styles from "./header.module.scss"; | ||
import { ContainerComponent } from "shared/components"; | ||
import { ContainerComponent, LinkComponent } from "shared/components"; | ||
|
||
export const HeaderComponent = () => { | ||
return ( | ||
<header className={styles.header}> | ||
<ContainerComponent>header</ContainerComponent> | ||
<ContainerComponent className={styles.container}> | ||
<span>Open Hotel Asset Editor</span> | ||
<div className={styles.items}> | ||
<LinkComponent to="/">Home</LinkComponent> | ||
<LinkComponent to="/file-manager">File Manager</LinkComponent> | ||
<LinkComponent to="/sprite-sheets">Sprite Sheets</LinkComponent> | ||
<LinkComponent to="/furniture">Furniture</LinkComponent> | ||
<LinkComponent to="/human-clothes">Human and Clothes</LinkComponent> | ||
</div> | ||
</ContainerComponent> | ||
</header> | ||
); | ||
}; |
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
173 changes: 173 additions & 0 deletions
173
app/client/src/modules/file-manager/file-manager.component.tsx
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,173 @@ | ||
import React, { | ||
useEffect, | ||
useState, | ||
ChangeEvent, | ||
useRef, | ||
FormEvent, | ||
useMemo, | ||
} from "react"; | ||
import { useData } from "shared/hooks"; | ||
import { File } from "shared/types"; | ||
import { getBase64FromBody } from "shared/utils"; | ||
import { parse } from "yaml"; | ||
import styles from "./file-manager.module.scss"; | ||
|
||
export const FileManagerComponent: React.FC = () => { | ||
const { readDirectory, getFile, addFiles, remove, createDirectory } = | ||
useData(); | ||
|
||
const uploadRef = useRef(); | ||
|
||
const [path, setPath] = useState<string>(""); | ||
const [files, setFiles] = useState<File[]>([]); | ||
|
||
const [currentFile, setCurrentFile] = useState<File>(); | ||
const [currentFileData, setCurrentFileData] = useState<{ | ||
data: string; | ||
format: "image" | "text" | "json"; | ||
}>(); | ||
|
||
useEffect(() => { | ||
if (!currentFile) return setCurrentFileData(null); | ||
|
||
getFile(path + "/" + currentFile.name).then(async (data) => { | ||
if (currentFile.name.endsWith(".png")) { | ||
return setCurrentFileData({ | ||
data: await getBase64FromBody(data), | ||
format: "image", | ||
}); | ||
} | ||
if (currentFile.name.endsWith(".yml")) { | ||
return setCurrentFileData({ | ||
data: parse(await data.text()), | ||
format: "json", | ||
}); | ||
} | ||
if (currentFile.name.endsWith(".json")) { | ||
return setCurrentFileData({ | ||
data: await data.json(), | ||
format: "json", | ||
}); | ||
} | ||
return setCurrentFileData({ | ||
data: await data.text(), | ||
format: "text", | ||
}); | ||
}); | ||
}, [currentFile]); | ||
|
||
const loadFiles = () => { | ||
setCurrentFile(null); | ||
setCurrentFileData(null); | ||
readDirectory(path).then(setFiles); | ||
}; | ||
|
||
useEffect(() => { | ||
loadFiles(); | ||
}, [path]); | ||
|
||
const onClickBack = () => { | ||
if (path === "/") return; | ||
const pathArr = path.split("/"); | ||
setPath(pathArr.slice(0, pathArr.length - 1).join("/")); | ||
}; | ||
|
||
const onClickFile = (file: File) => async () => { | ||
if (file.isDirectory) setPath((path) => path + "/" + file.name); | ||
|
||
if (file.isFile) setCurrentFile(file); | ||
}; | ||
const onClickDeleteFile = (file: File) => async () => { | ||
await remove(path + `/${file.name}`); | ||
loadFiles(); | ||
}; | ||
|
||
const onUploadFiles = async (event: ChangeEvent<HTMLInputElement>) => { | ||
const { files } = event.target; | ||
await addFiles(path, files); | ||
loadFiles(); | ||
//@ts-ignore | ||
uploadRef.current.value = ""; | ||
}; | ||
|
||
const onCreateDirectory = async (event: FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const data = new FormData(event.target as unknown as HTMLFormElement); | ||
const name = data.get("name") as string; | ||
|
||
if (!name.length) return; | ||
|
||
const targetPath = path + `/${name}`; | ||
//@ts-ignore | ||
event.target.reset(); | ||
await createDirectory(targetPath); | ||
loadFiles(); | ||
setPath(targetPath); | ||
}; | ||
|
||
const sortedFiles = useMemo( | ||
() => files.toSorted((fileA, fileB) => (fileA.isDirectory ? -1 : 1)), | ||
[files], | ||
); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.path}> | ||
{path || "/"} | ||
{currentFile?.name ? `/${currentFile?.name}` : ""} | ||
</div> | ||
<hr /> | ||
<div className={styles.files}> | ||
<div onClick={onClickBack} className={styles.back}> | ||
{path ? "⪻" : "|"} | ||
</div> | ||
{sortedFiles.map((file) => ( | ||
<div key={file.name} className={styles.file}> | ||
<label onClick={onClickFile(file)} className={styles.name}> | ||
{file.isDirectory ? "/" : ""} | ||
{file.name} | ||
</label> | ||
<button onClick={onClickDeleteFile(file)}>delete</button> | ||
</div> | ||
))} | ||
</div> | ||
<hr /> | ||
<div className={styles.actions}> | ||
<button onClick={loadFiles}>Reload</button> | ||
<form onSubmit={onCreateDirectory}> | ||
<input name="name" placeholder="Folder Name" /> | ||
<button>+</button> | ||
</form> | ||
<div> | ||
<button> | ||
<label htmlFor="uploadFile">Upload Files</label> | ||
</button> | ||
<input | ||
id="uploadFile" | ||
hidden | ||
ref={uploadRef} | ||
type="file" | ||
multiple | ||
onChange={onUploadFiles} | ||
/> | ||
</div> | ||
</div> | ||
<div className={styles.preview}> | ||
{currentFileData ? ( | ||
<> | ||
{currentFileData.format === "json" ? ( | ||
<textarea readOnly value={JSON.stringify(currentFileData.data)} /> | ||
) : null} | ||
{currentFileData.format === "text" ? ( | ||
<textarea readOnly value={currentFileData.data} /> | ||
) : null} | ||
{currentFileData.format === "image" ? ( | ||
<img alt="" src={currentFileData.data} /> | ||
) : null} | ||
</> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.