refactor: rework assets fetching

This commit is contained in:
Pihkaal
2024-07-25 10:02:15 +02:00
parent a0be097c34
commit f8e3e20d9d
15 changed files with 239 additions and 281 deletions

View File

@@ -5,30 +5,27 @@ import { NvimInput } from "./NvimInput";
import { NvimStatusBar } from "./NvimStatusBar";
import { NvimTree } from "./NvimTree";
import { useState } from "react";
import { File, InnerKittyProps } from "~/utils/types";
import { type InnerKittyProps } from "~/utils/types";
import { type Child, type Icon } from "~/utils/tree";
export const Nvim = (_props: {}) => {
export const Nvim = (_props: unknown) => {
const kitty = useKitty();
return kitty && <InnerNvimTree {...kitty} />;
};
const InnerNvimTree = (props: InnerKittyProps<typeof Nvim>) => {
const [activeFile, setActiveFile] = useState<{
const [activeChild, setActiveChild] = useState<{
name: string;
url: string;
icon?: string;
content: string;
icon: Icon;
}>();
const handleOpenFile = (file: File) => {
if (file.type === "link") {
window.open(file.url, "_blank")?.focus();
const handleOpenChild = (child: Child) => {
if (child.type === "link") {
window.open(child.url, "_blank")?.focus();
} else {
setActiveFile({
name: file.repo === "pihkaal" ? file.fileName : file.repo,
icon: file.icon,
url: `https://raw.githubusercontent.com/pihkaal/${file.repo}/main/${file.fileName}`,
});
setActiveChild(child);
}
};
@@ -43,7 +40,7 @@ const InnerNvimTree = (props: InnerKittyProps<typeof Nvim>) => {
}}
>
<div style={{ gridArea: "1 / 1 / 1 / 2" }}>
<NvimTree {...props} onOpen={handleOpenFile} />
<NvimTree {...props} onOpen={handleOpenChild} />
</div>
<div
className="overflow-y-auto break-all"
@@ -53,14 +50,14 @@ const InnerNvimTree = (props: InnerKittyProps<typeof Nvim>) => {
wordWrap: "break-word",
}}
>
<NvimEditor source={activeFile?.url} />
<NvimEditor content={activeChild?.content} />
</div>
<div style={{ gridArea: "2 / 1 / 2 / 3" }}>
<NvimStatusBar
label=" NORMAL"
labelColor="#7ea7ca"
fileIcon={activeFile?.icon}
fileName={activeFile?.name ?? `NvimTree_1`}
fileIcon={activeChild?.icon}
fileName={activeChild?.name}
/>
</div>
<div style={{ gridArea: "3 / 1 / 3 / 3" }}>