Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdoty committed Jan 7, 2023
1 parent 472ca0f commit ea22f31
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/components/Flow/MarkdownNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Handle, Position } from "reactflow";
import ReactMarkdown from 'react-markdown'

const MarkdownNode: FC<any> = memo(({ data, isConnectable }: any) => {
console.log(data, 'data')
return (
<>
<Handle
Expand Down
10 changes: 3 additions & 7 deletions src/pages/api/canvas/[id].ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import type { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import { promises as fs } from "fs";
import { parseData, getExtension } from "../../../utils";
import { getFiles } from "../../../backend/utils";
import { parseData } from "../../../utils";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<any>
) {
const { id } = req.query;
const jsonDirectory = path.join(process.cwd(), "public/obsidian");
const jsonFiles = (await getFiles(jsonDirectory)).filter(
(f) => getExtension(f) === "canvas" && f.includes(id as string)
);


const data = await fs.readFile(jsonDirectory + `/${id}.canvas`, "utf8");
const data = await fs.readFile(jsonDirectory + `/${id ?? 'home'}.canvas`, "utf8");

res.status(200).json({
files: jsonFiles,
active: id,
data: parseData(JSON.parse(data)),
});
Expand Down
15 changes: 1 addition & 14 deletions src/pages/api/canvas/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import { promises as fs } from "fs";
import { getExtension, parseData } from "../../../utils";
import { getFiles } from "../../../backend/utils";
import { parseData } from "../../../utils";

export const readJSON = async (file: string, path: string) => {
const fileContents = await fs.readFile(path, "utf8");
Expand All @@ -17,22 +16,10 @@ export default async function handler(
res: NextApiResponse<any>
) {
const jsonDirectory = path.join(process.cwd(), "public/obsidian");
const jsonFiles = (await getFiles(jsonDirectory)).filter(
(f) => getExtension(f) === "canvas"
);

// const promise: any = [];

// jsonFiles.forEach(async (file) => {
// promise.push(readJSON(file, jsonDirectory + "/" + file));
// });

// const data = await Promise.all(promise);

const data = await fs.readFile(jsonDirectory + "/home.canvas", "utf8");

res.status(200).json({
files: jsonFiles,
active: "home",
data: parseData(JSON.parse(data)),
});
Expand Down
2 changes: 0 additions & 2 deletions src/pages/api/md/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default async function handler(

let data = null;

console.log(mdFiles);

if (mdFiles.length > 0) data = await fs.readFile(mdFiles[0], "utf8");

res.status(200).json({
Expand Down
6 changes: 3 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Flow from "../components/Flow";
import NavBar from "../components/NavBar";

export default function Home() {
const { data, error } = useSWR("/api/canvas", fetcher);
const { data, error, isLoading } = useSWR("/api/canvas", fetcher);

return (
<div>
Expand All @@ -21,8 +21,8 @@ export default function Home() {
</Head>
<NavBar title={data?.active} />
<main className="h-screen">
{error && <div>Failed to load</div>}
{!data && <div>Loading...</div>}
{error && !isLoading && <div>Failed to load</div>}
{isLoading && <div>Loading...</div>}
{data && <Flow data={data.data} />}
</main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/md/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import NavBar from "../../components/NavBar";
export default function MD() {
const { query } = useRouter();
const { id } = query;
const { data, error } = useSWR(`/api/md/${id}`, fetcher);
const { data, error, isLoading } = useSWR(`/api/md/${id}`, fetcher);

return (
<div>
Expand All @@ -24,8 +24,8 @@ export default function MD() {
</Head>
<NavBar title={data?.active} />
<main className="h-screen">
{error && <div>Failed to load</div>}
{!data && <div>Loading...</div>}
{error && !isLoading && <div>Failed to load</div>}
{isLoading && <div>Loading...</div>}
{data && (
<div className="p-12">
<ReactMarkdown>{data.data}</ReactMarkdown>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/view/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import NavBar from "../../components/NavBar";
export default function View() {
const { query } = useRouter();
const { id } = query;
const { data, error } = useSWR(`/api/canvas/${id}`, fetcher);
const { data, error, isLoading } = useSWR(`/api/canvas/${id}`, fetcher);

return (
<div>
Expand All @@ -24,8 +24,8 @@ export default function View() {
</Head>
<NavBar title={data?.active} />
<main className="h-screen">
{error && <div>Failed to load</div>}
{!data && <div>Loading...</div>}
{error && !isLoading && <div>Failed to load</div>}
{isLoading && <div>Loading...</div>}
{data && <Flow data={data.data} />}
</main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Flow from "../../components/Flow";
import NavBar from "../../components/NavBar";

export default function View() {
const { data, error } = useSWR("/api/canvas", fetcher);
const { data, error, isLoading } = useSWR("/api/canvas", fetcher);

return (
<div>
Expand All @@ -21,8 +21,8 @@ export default function View() {
</Head>
<NavBar title={data?.active} />
<main className="h-screen">
{error && <div>Failed to load</div>}
{!data && <div>Loading...</div>}
{error && !isLoading && <div>Failed to load</div>}
{isLoading && <div>Loading...</div>}
{data && <Flow data={data.data} />}
</main>
</div>
Expand Down

0 comments on commit ea22f31

Please sign in to comment.