From 18a84123d3d978fde33fa77f182116e715394335 Mon Sep 17 00:00:00 2001 From: hzhang Date: Tue, 3 Dec 2024 16:36:32 +0000 Subject: [PATCH] fix render issue --- public/index.html | 3 ++- src/App.js | 22 ++++++++++++++++++- src/AuthProvider.js | 6 ++++- src/components/MainNavigation.js | 2 +- src/components/MarkdownContent.js | 2 +- src/components/SideNavigation.js | 6 ++--- src/index.js | 7 ++++-- .../{fetchWIthCache.js => fetchWithCache.js} | 0 8 files changed, 38 insertions(+), 10 deletions(-) rename src/utils/{fetchWIthCache.js => fetchWithCache.js} (100%) diff --git a/public/index.html b/public/index.html index 5811e1c..cc725ef 100644 --- a/public/index.html +++ b/public/index.html @@ -3,9 +3,10 @@ - React Project + React x Project +

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

\ No newline at end of file diff --git a/src/App.js b/src/App.js index 4995145..c67b684 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,27 @@ import React from "react"; +import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; +import MainNavigation from "./components/MainNavigation"; +import SideNavigation from "./components/SideNavigation"; +import MarkdownContent from "./components/MarkdownContent"; +import "./App.css"; const App = () => { - return

Welcome to My React Project

; + return ( + +
+ +
+ +
+ + Welcome to My React Project} /> + } /> + +
+
+
+
+ ); }; export default App; \ No newline at end of file diff --git a/src/AuthProvider.js b/src/AuthProvider.js index 668d852..1ddbc22 100644 --- a/src/AuthProvider.js +++ b/src/AuthProvider.js @@ -3,7 +3,11 @@ import { UserManager } from "oidc-client-ts"; import {oidcConfig} from "./oicdConfig"; -export const AuthContext = createContext(); +export const AuthContext = createContext({ + user: null, + login: () => {}, + logout: () => {}, +}); const AuthProvider = ({ children }) => { const [user, setUser] = useState(null); diff --git a/src/components/MainNavigation.js b/src/components/MainNavigation.js index 34e6b04..b22e7b7 100644 --- a/src/components/MainNavigation.js +++ b/src/components/MainNavigation.js @@ -13,7 +13,7 @@ const MainNavigation = () => {
  • Home
  • - {user ? ( + { user && user.profile ? (

    {user.profile.name}

    diff --git a/src/components/MarkdownContent.js b/src/components/MarkdownContent.js index 62a547b..c9ad2f6 100644 --- a/src/components/MarkdownContent.js +++ b/src/components/MarkdownContent.js @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; -import {fetchWithCache} from "../utils/fetchWIthCache"; +import {fetchWithCache} from "../utils/fetchWithCache"; const MarkdownContent = () => { const { id } = useParams(); diff --git a/src/components/SideNavigation.js b/src/components/SideNavigation.js index 3757a3d..d1550e6 100644 --- a/src/components/SideNavigation.js +++ b/src/components/SideNavigation.js @@ -3,14 +3,14 @@ import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import "./SideNavigation.css"; -import { fetchWithCache } from "../utils/fetchWithCache"; +import {fetchWithCache} from "../utils/fetchWithCache"; const SideNavigation = () => { const [markdowns, setMarkdowns] = useState([]); const [tree, setTree] = useState(null); useEffect(() => { - fetchWithCache("/api/markdown/") + fetchWithCache("http://127.0.0.1:5000/api/markdown/") .then((data) => { setMarkdowns(data); setTree(buildTree(data)); @@ -44,7 +44,7 @@ const SideNavigation = () => { if (value.markdown) { return (
  • - + {value.markdown.title}
  • diff --git a/src/index.js b/src/index.js index 3ed6c0d..af8b522 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,8 @@ import React from "react"; -import ReactDOM from "react-dom"; +import ReactDOM from "react-dom/client"; import App from "./App"; -ReactDOM.render(, document.getElementById("root")); \ No newline at end of file +//ReactDOM.render(, document.getElementById("root")); + +const root = ReactDOM.createRoot(document.getElementById("root")); +root.render(); \ No newline at end of file diff --git a/src/utils/fetchWIthCache.js b/src/utils/fetchWithCache.js similarity index 100% rename from src/utils/fetchWIthCache.js rename to src/utils/fetchWithCache.js