diff --git a/build/manifestPlugin.ts b/build/manifestPlugin.ts index 4003480..f88070c 100644 --- a/build/manifestPlugin.ts +++ b/build/manifestPlugin.ts @@ -23,6 +23,11 @@ type Project = { private: boolean; }; +type File = { + name: string; + content: string; +}; + export const manifest = (): Plugin => ({ name: "generate-pages-plugin", buildStart: async () => { @@ -86,14 +91,27 @@ export const manifest = (): Plugin => ({ }); } + const files: Array = []; + for (const file of manifest.files) { + const content = await getRepoFileContent("pihkaal", file); + + files.push({ + name: file, + content, + }); + } + const code = ` const projects = ${JSON.stringify(projects, null, 2)} as const; const links = ${JSON.stringify(manifest.links, null, 2)} as const; + const files = ${JSON.stringify(files, null, 2)} as const; + export const assets = { projects, - links + links, + files }; `; diff --git a/src/components/Nvim/NvimTree/NvimTreeChild.tsx b/src/components/Nvim/NvimTree/NvimTreeChild.tsx index 18cf69e..2c973e8 100644 --- a/src/components/Nvim/NvimTree/NvimTreeChild.tsx +++ b/src/components/Nvim/NvimTree/NvimTreeChild.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { DEFAULT_ICON } from "~/utils/icons"; import { type Child } from "~/utils/tree"; @@ -10,12 +11,26 @@ export const NvimTreeChild = (props: { onOpen: (file: Child) => void; }) => { const icon = props.child.icon ?? DEFAULT_ICON; + const [lastClick, setLastClick] = useState(); + + const handleClick = () => { + props.onSelect(props.y); + + if (lastClick) { + if (Date.now() - lastClick <= 500) { + props.onOpen(props.child); + } + + setLastClick(undefined); + } else { + setLastClick(Date.now()); + } + }; return (
  • props.onSelect(props.y)} - onDoubleClick={() => props.onOpen(props.child)} + onMouseDown={handleClick} > {" "} {props.inDirectory && ( diff --git a/src/components/Nvim/NvimTree/NvimTreeDirectory.tsx b/src/components/Nvim/NvimTree/NvimTreeDirectory.tsx index d7196e3..67f37c9 100644 --- a/src/components/Nvim/NvimTree/NvimTreeDirectory.tsx +++ b/src/components/Nvim/NvimTree/NvimTreeDirectory.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { type Folder } from "~/utils/tree"; export const NvimTreeDirectory = (props: { @@ -6,20 +7,37 @@ export const NvimTreeDirectory = (props: { selected: boolean; onSelect: (y: number) => void; onOpen: (directory: Folder) => void; -}) => ( -
  • props.onSelect(props.y)} - onDoubleClick={() => props.onOpen(props.directory)} - > - {props.directory.opened ? ( - <>  - ) : ( - <> - {" "} - - )} - {props.directory.name} -
  • -); +}) => { + const [lastClick, setLastClick] = useState(); + + const handleClick = () => { + props.onSelect(props.y); + + if (lastClick) { + if (Date.now() - lastClick <= 500) { + props.onOpen(props.directory); + } + + setLastClick(undefined); + } else { + setLastClick(Date.now()); + } + }; + + return ( +
  • + {props.directory.opened ? ( + <>  + ) : ( + <> + {" "} + + )} + {props.directory.name} +
  • + ); +}; diff --git a/src/components/Nvim/NvimTree/index.tsx b/src/components/Nvim/NvimTree/index.tsx index 0f86fce..1376dc4 100644 --- a/src/components/Nvim/NvimTree/index.tsx +++ b/src/components/Nvim/NvimTree/index.tsx @@ -28,7 +28,7 @@ const buildTree = () => project(p.name, p.content, p.url, p.language, p.private), ), ), - file("README.md", "hey", getIcon("README.md")), + ...assets.files.map((f) => file(f.name, f.content)), ]); export const NvimTree = ( diff --git a/src/components/Nvim/index.tsx b/src/components/Nvim/index.tsx index ed68f26..c08fb61 100644 --- a/src/components/Nvim/index.tsx +++ b/src/components/Nvim/index.tsx @@ -43,7 +43,6 @@ const InnerNvimTree = (props: InnerKittyProps) => {
    ({ icon, }); -export const file = (name: string, content: string, icon: Icon): File => ({ +export const file = ( + name: string, + content: string, + icon: Icon = getIcon(name), +): File => ({ type: "file", name, content,