feat: fetch root files at build step and handle double click on mobile

This commit is contained in:
Pihkaal
2024-09-10 18:21:36 +02:00
parent 2b48e71248
commit 477f6b6c66
7 changed files with 78 additions and 25 deletions

View File

@@ -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<File> = [];
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
};
`;

View File

@@ -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<number>();
const handleClick = () => {
props.onSelect(props.y);
if (lastClick) {
if (Date.now() - lastClick <= 500) {
props.onOpen(props.child);
}
setLastClick(undefined);
} else {
setLastClick(Date.now());
}
};
return (
<li
style={{ background: props.selected ? "#504651" : "" }}
onMouseDown={() => props.onSelect(props.y)}
onDoubleClick={() => props.onOpen(props.child)}
onMouseDown={handleClick}
>
{" "}
{props.inDirectory && (

View File

@@ -1,3 +1,4 @@
import { useState } from "react";
import { type Folder } from "~/utils/tree";
export const NvimTreeDirectory = (props: {
@@ -6,12 +7,28 @@ export const NvimTreeDirectory = (props: {
selected: boolean;
onSelect: (y: number) => void;
onOpen: (directory: Folder) => void;
}) => (
}) => {
const [lastClick, setLastClick] = useState<number>();
const handleClick = () => {
props.onSelect(props.y);
if (lastClick) {
if (Date.now() - lastClick <= 500) {
props.onOpen(props.directory);
}
setLastClick(undefined);
} else {
setLastClick(Date.now());
}
};
return (
<li
className="text-[#a0b6ee]"
style={{ background: props.selected ? "#504651" : "" }}
onMouseDown={() => props.onSelect(props.y)}
onDoubleClick={() => props.onOpen(props.directory)}
onMouseDown={handleClick}
>
{props.directory.opened ? (
<> </>
@@ -23,3 +40,4 @@ export const NvimTreeDirectory = (props: {
{props.directory.name}
</li>
);
};

View File

@@ -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 = (

View File

@@ -43,7 +43,6 @@ const InnerNvimTree = (props: InnerKittyProps<typeof Nvim>) => {
<NvimTree {...props} onOpen={handleOpenChild} />
</div>
<div
className="overflow-y-auto break-all"
style={{
gridArea: "1 / 2 / 1 / 3",
overflowY: "auto",

View File

@@ -16,7 +16,6 @@ import { WaybarPowerWidget } from "./Widgets/WaybarPowerWidget";
import { WaybarTrayWidget } from "./Widgets/WaybarTrayWidget";
import { WaybarToggleThemeWidget } from "./Widgets/WaybarToggleThemeWidget";
import { WaybarWeatherWidget } from "./Widgets/WaybarWeatherWidget";
import { Responsive } from "../Responsive";
import { cn, hideIf } from "~/utils/react";
import { useApp } from "~/hooks/useApp";

View File

@@ -1,4 +1,4 @@
import { DEFAULT_ICON, ICONS } from "./icons";
import { DEFAULT_ICON, ICONS, getIcon } from "./icons";
export type Icon = {
char: string;
@@ -62,7 +62,11 @@ export const link = (name: string, url: string, icon: Icon): Link => ({
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,