From d0cb74bea83ac25e78a3bfc62001beaa341be917 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 13 Mar 2024 02:52:59 -0600 Subject: [PATCH] ttcmd: adds hr element help pages: adds a way to extract the table of contents to the parent, smoothes out the rough loading on help pages --- actions/readMD.ts | 5 ++ actions/temp.ts | 5 -- app/globals.css | 7 ++ app/help/[article]/client.tsx | 38 ++++++++++ app/help/[article]/loading.tsx | 5 ++ app/help/[article]/page.tsx | 32 ++++----- app/layout.tsx | 4 +- components/loader.tsx | 30 ++++++++ components/ttcmd/index.tsx | 103 ++++++++++++++++++++------- lib/tcmd/TokenIdentifiers.ts | 16 ++++- lib/tcmd/index.ts | 18 +---- md/help articles/How to use ttcMD.md | 6 +- 12 files changed, 199 insertions(+), 70 deletions(-) create mode 100644 actions/readMD.ts delete mode 100644 actions/temp.ts create mode 100644 app/help/[article]/client.tsx create mode 100644 app/help/[article]/loading.tsx create mode 100644 components/loader.tsx diff --git a/actions/readMD.ts b/actions/readMD.ts new file mode 100644 index 0000000..6512c9e --- /dev/null +++ b/actions/readMD.ts @@ -0,0 +1,5 @@ +"use server"; + +import { readFile } from "fs/promises"; + +export const readMD = async (path: string) => await readFile(path, "utf-8"); diff --git a/actions/temp.ts b/actions/temp.ts deleted file mode 100644 index 57d4638..0000000 --- a/actions/temp.ts +++ /dev/null @@ -1,5 +0,0 @@ -"use server"; - -import { readFile } from "fs/promises"; - -export const readMD = async () => await readFile("./test.md", "utf-8"); diff --git a/app/globals.css b/app/globals.css index dda59e5..ee1a459 100644 --- a/app/globals.css +++ b/app/globals.css @@ -56,6 +56,13 @@ .poppable { @apply card dark:bg-mixed-300 bg-primary-600 p-2 rounded-lg transition-opacity data-[visible=true]:z-10 data-[visible=true]:opacity-100 data-[visible=false]:opacity-0 -z-10 max-w-[400px] absolute; } + + .skeleton { + @apply animate-pulse bg-black/20 rounded-md text-white/0; + } +} + +@keyframes identifier { } @layer utilities { diff --git a/app/help/[article]/client.tsx b/app/help/[article]/client.tsx new file mode 100644 index 0000000..3ca480b --- /dev/null +++ b/app/help/[article]/client.tsx @@ -0,0 +1,38 @@ +"use client"; + +import { TTCMD, TTCMDRenderer } from "@/components/ttcmd"; +import { FC, use, useCallback, useState } from "react"; + +export const HelpClient: FC<{ body: Promise; title: string }> = ({ + body: bodyPromise, + title, +}) => { + const body = use(bodyPromise); + const [toc, setToc] = useState(); + const escapeTOC = useCallback((t: Token[]) => { + setToc(t); + return true; + }, []); + + return ( + <> +
+

Help

+

{decodeURIComponent(title)}

+
+
+
+ +
+ {toc && ( +
+ +
+ )} +
+ + ); +}; diff --git a/app/help/[article]/loading.tsx b/app/help/[article]/loading.tsx new file mode 100644 index 0000000..72af60f --- /dev/null +++ b/app/help/[article]/loading.tsx @@ -0,0 +1,5 @@ +import { Loader } from "@/components/loader"; + +export default function Loading() { + return ; +} diff --git a/app/help/[article]/page.tsx b/app/help/[article]/page.tsx index 632a01b..8bca31c 100644 --- a/app/help/[article]/page.tsx +++ b/app/help/[article]/page.tsx @@ -1,31 +1,25 @@ -import { TTCMD } from "@/components/ttcmd"; -import { ArrowLeftCircleIcon } from "@heroicons/react/24/solid"; -import { readFile } from "fs/promises"; +import { readMD } from "@/actions/readMD"; +import { HelpClient } from "./client"; import { Suspense } from "react"; +import { Loader } from "@/components/loader"; + +// export const export default async function Help({ params, }: { params: { article: string }; }) { - if (!params.article.endsWith(".md")) return <>; - const body = readFile( + if (!params.article.endsWith(".md")) return; + const body = readMD( "./md/help articles/" + decodeURIComponent(params.article), - "utf-8", ); return ( - <> -
-

Help

-

{decodeURIComponent(params.article).replace(".md", "")}

-
-
-
- - - -
-
- + }> + + ); } diff --git a/app/layout.tsx b/app/layout.tsx index 26408b6..c16fbc5 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -53,7 +53,7 @@ export default function RootLayout({ return ( -