From 4eb0f1283e6eb0c6989fd7145a7177acf4ce3616 Mon Sep 17 00:00:00 2001 From: Kiarash Sotoudeh Date: Thu, 7 Nov 2024 23:44:28 -0500 Subject: [PATCH] Refactor components to use Next.js Image for better performance and remove unused imports --- frontend/src/app/about/page.tsx | 5 +++-- frontend/src/app/components/AboutYourScore.tsx | 1 - frontend/src/app/components/Navbar.tsx | 1 - frontend/src/app/components/TransactionMap.tsx | 18 ++++++++---------- .../components/charts/CompaniesPieChart.tsx | 2 +- .../components/charts/FootprintLineGraph.tsx | 2 +- frontend/src/app/dashboard/page.tsx | 13 +------------ frontend/src/app/layout.tsx | 4 +--- frontend/src/app/page.tsx | 6 +----- frontend/src/app/transactions/page.tsx | 2 +- 10 files changed, 17 insertions(+), 37 deletions(-) diff --git a/frontend/src/app/about/page.tsx b/frontend/src/app/about/page.tsx index ed3942b..d47217f 100644 --- a/frontend/src/app/about/page.tsx +++ b/frontend/src/app/about/page.tsx @@ -1,4 +1,5 @@ import { Metadata } from "next"; +import Image from "next/image"; export const metadata: Metadata = { title: @@ -36,10 +37,10 @@ export default function About() { id="right-col" className="flex h-full flex-col items-center justify-center rounded-2xl md:col-span-6" > - RATTM CO2 Calculator diff --git a/frontend/src/app/components/AboutYourScore.tsx b/frontend/src/app/components/AboutYourScore.tsx index 1b7c193..8f86d0c 100644 --- a/frontend/src/app/components/AboutYourScore.tsx +++ b/frontend/src/app/components/AboutYourScore.tsx @@ -1,7 +1,6 @@ "use client"; import React from "react"; -import dynamic from "next/dynamic"; const AboutYourScore: React.FC = () => { return ( diff --git a/frontend/src/app/components/Navbar.tsx b/frontend/src/app/components/Navbar.tsx index 897ce08..1b2e6bf 100644 --- a/frontend/src/app/components/Navbar.tsx +++ b/frontend/src/app/components/Navbar.tsx @@ -1,5 +1,4 @@ // src/app/components/Navbar.tsx - import Image from "next/image"; import React, { useEffect, useState } from "react"; import Link from "next/link"; diff --git a/frontend/src/app/components/TransactionMap.tsx b/frontend/src/app/components/TransactionMap.tsx index eaa7d58..0dd6d12 100644 --- a/frontend/src/app/components/TransactionMap.tsx +++ b/frontend/src/app/components/TransactionMap.tsx @@ -1,9 +1,7 @@ "use client"; -// import jsVectorMap from "jsvectormap"; -// import "jsvectormap/dist/jsvectormap.css"; + import mapboxgl from "mapbox-gl"; import React, { useEffect, useRef } from "react"; -// import "../../js/us-aea-en"; mapboxgl.accessToken = "pk.eyJ1IjoiZ2FicmllbGV6cmF0aG9tcHNvbiIsImEiOiJjbTJ6OWpwcTQwOTh2MmxvZ3BpaW5wajhkIn0.BFA_fvxSDOBkZkAdXjnxiQ"; @@ -14,13 +12,13 @@ const TransactionMap: React.FC = () => { useEffect(() => { // Initialize the Mapbox map const map = new mapboxgl.Map({ - container: mapContainer.current, - style: "mapbox://styles/mapbox/streets-v11", // Map style - center: [-74.5, 40], // Initial position [lng, lat] - zoom: 9, // Initial zoom level + container: mapContainer.current || "", + style: "mapbox://styles/mapbox/streets-v11", + center: [-74.5, 40], + zoom: 9, }); - return () => map.remove(); // Clean up on unmount + return () => map.remove(); }, []); return ( @@ -33,8 +31,8 @@ const TransactionMap: React.FC = () => { height: "69vh", minHeight: "400px", maxHeight: "100%", - borderRadius: "20px", // Added rounded corners - overflow: "hidden", // Ensures the map content does not overflow the rounded edges + borderRadius: "20px", + overflow: "hidden", }} /> ); diff --git a/frontend/src/app/components/charts/CompaniesPieChart.tsx b/frontend/src/app/components/charts/CompaniesPieChart.tsx index 30b9fb1..3b2af36 100644 --- a/frontend/src/app/components/charts/CompaniesPieChart.tsx +++ b/frontend/src/app/components/charts/CompaniesPieChart.tsx @@ -108,7 +108,7 @@ const CompaniesPieChart: React.FC = () => {
{(options.colors || []).map((color, index) => ( -
+
{
- {series.map(({ name, data, color }) => ( + {series.map(({ name, color }) => (
{ - const [displayName, setDisplayName] = useState(null); const [loading, setLoading] = useState(true); const router = useRouter(); useEffect(() => { const unsubscribe = auth.onAuthStateChanged((user) => { if (user) { - setDisplayName(user.displayName || "User"); setLoading(false); } else { - router.replace("/main-site/auth/SignInWithGoogle"); // Use replace instead of push + router.replace("/main-site/auth/SignInWithGoogle"); } }); return () => unsubscribe(); }, [router]); - const handleSignOut = async () => { - try { - await auth.signOut(); - router.replace("/"); // Use replace instead of push - } catch (error) { - console.error("Sign out error:", error); - } - }; - if (loading) { return (
diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index c086b5a..7290a85 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -3,7 +3,7 @@ import "jsvectormap/dist/jsvectormap.css"; import "flatpickr/dist/flatpickr.min.css"; import "@/css/satoshi.css"; import "@/css/style.css"; -import React, { useEffect, useState } from "react"; +import React from "react"; import Navbar from "@/app/components/Navbar"; export default function RootLayout({ @@ -11,8 +11,6 @@ export default function RootLayout({ }: Readonly<{ children: React.ReactNode; }>) { - const [sidebarOpen, setSidebarOpen] = useState(false); - return ( diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index f590963..1c609db 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -3,15 +3,11 @@ import Image from "next/image"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { auth } from "@/app/firebase/firebaseConfig"; -import { useRouter } from "next/navigation"; import { User } from "firebase/auth"; -import { Metadata } from "next"; export default function Home() { - const [menuOpen, setMenuOpen] = useState(false); const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); - const router = useRouter(); useEffect(() => { const unsubscribe = auth.onAuthStateChanged((currentUser) => { @@ -27,7 +23,7 @@ export default function Home() { return (
- RATTM CO2 Calculator All recent transactions -

I'll put stuff here later

+

I'll put stuff here later

); }