diff --git a/src/components/Nvim/NvimEditor.tsx b/src/components/Nvim/NvimEditor.tsx index 4fad7d3..bae7c2e 100644 --- a/src/components/Nvim/NvimEditor.tsx +++ b/src/components/Nvim/NvimEditor.tsx @@ -1,3 +1,8 @@ -export const NvimEditor = (props: { source: string | undefined }) => ( -
{props.source}
-); +import { useState } from "react"; + +export const NvimEditor = (props: { source: string | undefined }) => { + const [data, setData] = useState(); + const [loading, setLoading] = useState(false); + + return
{props.source}
; +}; diff --git a/src/components/Nvim/NvimStatusBar.tsx b/src/components/Nvim/NvimStatusBar.tsx index 74a4b8d..d47a8ba 100644 --- a/src/components/Nvim/NvimStatusBar.tsx +++ b/src/components/Nvim/NvimStatusBar.tsx @@ -1,17 +1,22 @@ +import { ICONS, getIcon } from "~/utils/icons"; + export const NvimStatusBar = (props: { label: string; labelColor: string; + fileIcon?: string; fileName: string; }) => (
- + {` ${props.label} `} {"\ue0ba"} {"\ue0ba"} - {` ${props.fileName} `} + {` ${getIcon(props.fileIcon).char}${ + props.fileName + } `} {"\ue0ba"}
); diff --git a/src/components/Nvim/NvimTree/NvimTreeFile.tsx b/src/components/Nvim/NvimTree/NvimTreeFile.tsx index 1f5a22f..b01629f 100644 --- a/src/components/Nvim/NvimTree/NvimTreeFile.tsx +++ b/src/components/Nvim/NvimTree/NvimTreeFile.tsx @@ -1,4 +1,4 @@ -import { ICONS } from "~/utils/icons"; +import { getIcon } from "~/utils/icons"; import { File } from "~/utils/types"; export const NvimTreeFile = (props: { @@ -8,34 +8,25 @@ export const NvimTreeFile = (props: { inDirectory: boolean | "last"; onSelect: (y: number) => void; onOpen: (file: File) => void; -}) => { - let iconName = props.file.icon; - if (!iconName) { - const parts = props.file.name.split("."); - iconName = parts[parts.length - 1]; - } - - if (!ICONS[iconName]) iconName = "UNKNOWN"; - const icon = ICONS[iconName]; - - return ( -
  • props.onSelect(props.y)} - onDoubleClick={() => props.onOpen(props.file)} - > - {" "} - {props.inDirectory && ( - - {props.inDirectory === "last" ? "└ " : "│ "} - - )} - {`${icon.char}`} - {props.file.name === "README.md" ? ( - README.md - ) : ( - {props.file.name} - )} -
  • - ); -}; +}) => ( +
  • props.onSelect(props.y)} + onDoubleClick={() => props.onOpen(props.file)} + > + {" "} + {props.inDirectory && ( + + {props.inDirectory === "last" ? "└ " : "│ "} + + )} + {`${ + getIcon(props.file).char + }`} + {props.file.name === "README.md" ? ( + README.md + ) : ( + {props.file.name} + )} +
  • +); diff --git a/src/components/Nvim/NvimTree/index.tsx b/src/components/Nvim/NvimTree/index.tsx index 5c40a6e..23bb024 100644 --- a/src/components/Nvim/NvimTree/index.tsx +++ b/src/components/Nvim/NvimTree/index.tsx @@ -159,20 +159,3 @@ export const NvimTree = ( ); }; - -type FileIcon = { - char: string; - color: string; -}; - -const FILE_ICONS: Record = { - md: { - char: " ", - color: "#89bafa", - }, - asc: { - char: "󰷖 ", - color: "#f9e2af", - }, - UNKNOWN: { char: "󰈚 ", color: "#f599ae" }, -}; diff --git a/src/components/Nvim/index.tsx b/src/components/Nvim/index.tsx index 7b4d859..164f09d 100644 --- a/src/components/Nvim/index.tsx +++ b/src/components/Nvim/index.tsx @@ -10,15 +10,21 @@ import { File } from "~/utils/types"; export const Nvim = (_props: {}) => { const kitty = useKitty(); - const [activeFile, setActiveFile] = useState(); + const [activeFile, setActiveFile] = useState<{ + name: string; + url: string; + icon?: string; + }>(); const handleOpenFile = (file: File) => { if (file.type === "link") { window.open(file.url, "_blank")?.focus(); } else { - setActiveFile( - `https://raw.githubusercontent.com/pihkaal/${file.repo}/main/${file.fileName}`, - ); + setActiveFile({ + name: file.repo === "pihkaal" ? file.fileName : file.repo, + icon: file.icon, + url: `https://raw.githubusercontent.com/pihkaal/${file.repo}/main/${file.fileName}`, + }); } }; @@ -36,13 +42,14 @@ export const Nvim = (_props: {}) => {
    - +
    diff --git a/src/utils/icons.ts b/src/utils/icons.ts index a2ef2bd..114215e 100644 --- a/src/utils/icons.ts +++ b/src/utils/icons.ts @@ -1,4 +1,23 @@ -import { Icon } from "./types"; +import { File, Icon } from "./types"; + +export const getIcon = (file: File | string | undefined): Icon => { + if (file === undefined) return ICONS["UNKNOWN"]; + + let iconName; + if (typeof file === "string") { + const parts = file.split("."); + iconName = parts[parts.length - 1]; + } else { + iconName = file.icon; + if (!iconName) { + const parts = file.name.split("."); + iconName = parts[parts.length - 1]; + } + } + + if (!ICONS[iconName]) iconName = "UNKNOWN"; + return ICONS[iconName]; +}; export const ICONS: Record = { md: {