From dc3b96e1f43a4573a24b064f0b1ac51f82bf3255 Mon Sep 17 00:00:00 2001 From: "benjamin.747" Date: Mon, 4 Nov 2024 17:21:12 +0800 Subject: [PATCH] fix ui issue --- Cargo.toml | 6 +-- mono/src/server/ssh_server.rs | 2 +- .../app/(dashboard)/blob/[...path]/page.tsx | 2 +- moon/src/app/(dashboard)/page.tsx | 40 ++++++++++++------- .../app/(dashboard)/tree/[...path]/page.tsx | 4 +- moon/src/components/BreadCrumb.tsx | 2 - moon/src/components/CodeTable.tsx | 3 +- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0c03202b..dec0c59e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,15 +57,15 @@ sha1 = "0.10.6" futures = "0.3.30" futures-util = "0.3.30" go-defer = "0.1.0" -russh = "0.45.0" -russh-keys = "0.45.0" +russh = "0.46.0" +russh-keys = "0.46.0" axum = "0.7.7" axum-extra = "0.9.4" axum-server = "0.7.1" tower-http = "0.6.1" tower = "0.5.1" hex = "0.4.3" -sea-orm = "1.1.0" +sea-orm = "1.1.1" flate2 = "1.0.34" bstr = "1.10.0" colored = "2.1.0" diff --git a/mono/src/server/ssh_server.rs b/mono/src/server/ssh_server.rs index 710dbd044..04c9f77e2 100644 --- a/mono/src/server/ssh_server.rs +++ b/mono/src/server/ssh_server.rs @@ -80,7 +80,7 @@ pub fn load_key() -> KeyPair { KeyPair::Ed25519(keypair) } else { // generate a keypair if not exists - let keys = KeyPair::generate_ed25519().unwrap(); + let keys = KeyPair::generate_ed25519(); if let KeyPair::Ed25519(inner_pair) = &keys { let secret = serde_json::json!({ "secret_key": *inner_pair.to_pkcs8_pem(LineEnding::CR).unwrap() diff --git a/moon/src/app/(dashboard)/blob/[...path]/page.tsx b/moon/src/app/(dashboard)/blob/[...path]/page.tsx index 6efa76f90..c68309222 100644 --- a/moon/src/app/(dashboard)/blob/[...path]/page.tsx +++ b/moon/src/app/(dashboard)/blob/[...path]/page.tsx @@ -51,7 +51,7 @@ export default function BlobPage({ params }: { params: Params }) {
- + {/* */} diff --git a/moon/src/app/(dashboard)/page.tsx b/moon/src/app/(dashboard)/page.tsx index 8defa5a21..b87d9ce04 100644 --- a/moon/src/app/(dashboard)/page.tsx +++ b/moon/src/app/(dashboard)/page.tsx @@ -1,9 +1,26 @@ +'use client' + import CodeTable from '@/components/CodeTable' -export const revalidate = 0 +import { useEffect, useState } from 'react'; + +export default function HomePage() { + const [directory, setDirectory] = useState([]); + const [readmeContent, setReadmeContent] = useState(""); + + const fetchData = async () => { + try { + let directory = await getDirectory("/"); + setDirectory(directory); + let readmeContent = await getReadmeContent("/", directory); + setReadmeContent(readmeContent); + } catch (error) { + console.error('Error fetching data:', error); + } + }; -export default async function HomePage() { - let directory = await getDirectory() - let readmeContent = await getReadmeContent(directory) + useEffect(() => { + fetchData(); + }, []); return (
@@ -11,27 +28,22 @@ export default async function HomePage() {
); } - -async function getDirectory() { - const res = await fetch(`http://localhost:3000/api/tree/commit-info?path=/`); - +async function getDirectory(pathname: string) { + const res = await fetch(`/api/tree/commit-info?path=${pathname}`); const response = await res.json(); const directory = response.data.data; - return directory } -async function getReadmeContent(directory) { - let readmeContent = ''; - +async function getReadmeContent(pathname, directory) { + var readmeContent = ''; for (const project of directory || []) { if (project.name === 'README.md' && project.content_type === 'file') { - const res = await fetch(`http://localhost:3000/api/blob?path=/README.md`); + const res = await fetch(`/api/blob?path=${pathname}/README.md`); const response = await res.json(); readmeContent = response.data.data; break; } } - return readmeContent } diff --git a/moon/src/app/(dashboard)/tree/[...path]/page.tsx b/moon/src/app/(dashboard)/tree/[...path]/page.tsx index 45453d0aa..f7a80ae0f 100644 --- a/moon/src/app/(dashboard)/tree/[...path]/page.tsx +++ b/moon/src/app/(dashboard)/tree/[...path]/page.tsx @@ -23,7 +23,7 @@ export default function Page({ params }: { params: Params }) { try { let directory = await getDirectory(new_path); setDirectory(directory); - let readmeContent = await getReadmeContent(path, directory); + let readmeContent = await getReadmeContent(new_path, directory); setReadmeContent(readmeContent); let shown_clone_btn = await pathCanClone(new_path); setCloneBtn(shown_clone_btn); @@ -34,7 +34,7 @@ export default function Page({ params }: { params: Params }) { } }; fetchData(); - }, [path]); + }, [new_path]); const treeStyle = { borderRadius: 8, diff --git a/moon/src/components/BreadCrumb.tsx b/moon/src/components/BreadCrumb.tsx index 4218bddc5..b021353b5 100644 --- a/moon/src/components/BreadCrumb.tsx +++ b/moon/src/components/BreadCrumb.tsx @@ -1,10 +1,8 @@ import 'github-markdown-css/github-markdown-light.css' -import { useRouter } from 'next/navigation' import { Breadcrumb } from 'antd/lib' import styles from './BreadCrumb.module.css' const Bread = ({ path }) => { - const router = useRouter(); const breadCrumbItems = path.map((sub_path, index) => { if (index == path.length - 1) { return { diff --git a/moon/src/components/CodeTable.tsx b/moon/src/components/CodeTable.tsx index 266ebeb80..22f53f394 100644 --- a/moon/src/components/CodeTable.tsx +++ b/moon/src/components/CodeTable.tsx @@ -92,7 +92,8 @@ const CodeTable = ({ directory, readmeContent }) => {
{ return { onClick: (event) => { handleRowClick(record) }