From 95e6fda526f5d3663d5a1fd2a470ae8bba31ebf2 Mon Sep 17 00:00:00 2001 From: Dhruvan Ganadhandayuthapani Date: Wed, 11 Sep 2024 17:51:45 +0200 Subject: [PATCH] Notebook frontend --- frontend/src/app/Navbar.tsx | 67 +++++++++++++++++++++- frontend/src/app/notebooks/[name]/page.tsx | 28 +++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 frontend/src/app/notebooks/[name]/page.tsx diff --git a/frontend/src/app/Navbar.tsx b/frontend/src/app/Navbar.tsx index c4d9752..f9f49b7 100644 --- a/frontend/src/app/Navbar.tsx +++ b/frontend/src/app/Navbar.tsx @@ -26,10 +26,16 @@ interface DataSource { description: string; } +interface Notebook { + name: string; + url_name: string; +} + export default function Navbar() { // Handle dropdowns logic const [isIndicatorDropdownOpen, setIsIndicatorDropdownOpen] = useState(false); const [isDataSourceDropdownOpen, setIsDataSourceDropdownOpen] = useState(false); + const [isNotebookDropdownOpen, setIsNotebookDropdownOpen] = useState(false); const handleIndicatorMouseEnter = () => setIsIndicatorDropdownOpen(true); const handleIndicatorMouseLeave = (e: React.MouseEvent) => { @@ -47,6 +53,14 @@ export default function Navbar() { } }; + const handleNotebookMouseEnter = () => setIsNotebookDropdownOpen(true); + const handleNotebookMouseLeave = (e: React.MouseEvent) => { + const relatedTarget = e.relatedTarget as Element; + if (!relatedTarget || !(relatedTarget instanceof Element) || !relatedTarget.closest('.notebook-dropdown-area')) { + setIsNotebookDropdownOpen(false); + } + }; + // Fetch indicators data const [indicators, setIndicators] = useState([]); const [indicatorsIsLoading, setIndicatorsIsLoading] = useState(true); @@ -93,6 +107,9 @@ export default function Navbar() { fetchCategories(); }, []); + // Notebooks data + const notebooks: Notebook[] = [{name: 'Thermocap Multiple', url_name: 'thermocap-multiple'}, {name: 'Bitcoin Decay Channel', url_name: 'bitcoin-decay-channel'}] + return (
diff --git a/frontend/src/app/notebooks/[name]/page.tsx b/frontend/src/app/notebooks/[name]/page.tsx new file mode 100644 index 0000000..c590c4b --- /dev/null +++ b/frontend/src/app/notebooks/[name]/page.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { notFound } from "next/navigation"; + +async function fetchHtml(name: string) { + const res = await fetch(`https://api.gnanadhandayuthapani.com/api/research/notebooks/${name}`); + + return res.text(); +} + +export default async function NotebookPage({ params }: { params: { name: string } }) { + const { name } = params; + const htmlContent = await fetchHtml(name); + + return ( +
+