From 0ecac6533c1342956bc994da996d81bf00bada77 Mon Sep 17 00:00:00 2001 From: Altair-sh Date: Fri, 4 Sep 2026 19:36:12 +0200 Subject: [PATCH] added comments --- src/app/api/proxy/functions.ts | 8 ++--- src/app/api/proxy/paths.ts | 2 ++ .../saveParserBackend/[[...path]]/route.ts | 2 ++ src/app/browse/page.tsx | 7 +++-- src/app/layout.tsx | 2 ++ src/app/login/page.tsx | 4 +++ src/app/register/page.tsx | 3 ++ src/components/FormError.tsx | 3 +- src/components/Navbar.tsx | 1 + src/components/SaveFileUploadingDialog.tsx | 6 ++++ src/config/AppConfig.ts | 1 + src/instrumentation.ts | 7 +++-- src/lib/configLoader.ts | 4 +++ src/lib/customConsoleLog.ts | 11 ++++--- src/lib/myFonts.ts | 3 ++ src/services/AuthService.ts | 3 ++ src/services/SaveParserBackendService.ts | 30 +++++++++---------- 17 files changed, 68 insertions(+), 29 deletions(-) diff --git a/src/app/api/proxy/functions.ts b/src/app/api/proxy/functions.ts index 7c2b6a3..eb1b493 100644 --- a/src/app/api/proxy/functions.ts +++ b/src/app/api/proxy/functions.ts @@ -38,8 +38,8 @@ export async function redirectRequest( }) } -/// Browsers send OPTIONS request sometimes to check webserver allowed headers and methods. -/// My backend doesn't support such requests so use proxy to answer to it that all headers and methods are allowed +/// Browsers send OPTIONS request sometimes to check webserver's allowed headers and methods. +/// My C# backend doesn't support OPTIONS, so the proxy answer to OPTIONS request that all headers and methods are allowed. export async function responseToOPTIONS(req: NextRequest): Promise { // console.log('proxy responding to CORS OPTIONS', req.url) @@ -48,8 +48,8 @@ export async function responseToOPTIONS(req: NextRequest): Promise headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, HEAD', - 'Access-Control-Allow-Headers': - req.headers.get('access-control-request-headers') || 'Content-Type, Authorization', + 'Access-Control-Allow-Headers': '*', + // req.headers.get('access-control-request-headers') || 'Content-Type, Authorization' }, }) } diff --git a/src/app/api/proxy/paths.ts b/src/app/api/proxy/paths.ts index 621c063..a80924b 100644 --- a/src/app/api/proxy/paths.ts +++ b/src/app/api/proxy/paths.ts @@ -1,3 +1,5 @@ +// Directories in src/api/proxy/ are routes. +// Their paths are stored here to simplify refactoring. export const PROXY_PATHS = { saveParserBackend: '/api/proxy/saveParserBackend', } diff --git a/src/app/api/proxy/saveParserBackend/[[...path]]/route.ts b/src/app/api/proxy/saveParserBackend/[[...path]]/route.ts index 4ff91e3..0f4a432 100644 --- a/src/app/api/proxy/saveParserBackend/[[...path]]/route.ts +++ b/src/app/api/proxy/saveParserBackend/[[...path]]/route.ts @@ -4,10 +4,12 @@ import { redirectRequest, responseToOPTIONS as respondToOPTIONS } from '@/app/ap import { PROXY_PATHS } from '@/app/api/proxy/paths' import { appConfig } from '@/lib/configLoader' +// Forwards the incoming request to the save parser backend. async function redirect(req: NextRequest): Promise { return await redirectRequest(req, PROXY_PATHS.saveParserBackend, appConfig.services.saveParserBackend.url) } +// handlers for each request method on this route export const GET = redirect export const POST = redirect export const PUT = redirect diff --git a/src/app/browse/page.tsx b/src/app/browse/page.tsx index 4c29877..534575b 100644 --- a/src/app/browse/page.tsx +++ b/src/app/browse/page.tsx @@ -1,15 +1,16 @@ 'use client' import { AgGridReact } from 'ag-grid-react' -import { AllCommunityModule, themeQuartz } from 'ag-grid-community' +import { AllCommunityModule, themeQuartz, colorSchemeDark } from 'ag-grid-community' import { useState, useEffect } from 'react' -import { colorSchemeDark } from 'ag-grid-community' // TODO: create tabs with general info, tables, plots -export default function BrowsePage() { +// Page that shows a save file's parsed data in a grid. +export default function BrowseSaveDataPage() { const [agTheme, setAgTheme] = useState(themeQuartz) + // Keep the grid theme in sync with the browser's light/dark color scheme. useEffect(() => { const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches setAgTheme(prefersDark ? themeQuartz.withPart(colorSchemeDark) : themeQuartz) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 0f94fe8..444228a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -8,7 +8,9 @@ export const metadata: Metadata = { title: 'Home', } +// Root layout wrapping every page with the navbar and shared styles. export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { + // Register the ag-grid community features ModuleRegistry.registerModules([AllCommunityModule]) return ( diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 5330d63..dc48961 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -4,6 +4,7 @@ import { useState } from 'react' import { authService } from '@/services/AuthService' import FormError from '@/components/FormError' +// Page with the login form. export default function LoginPage() { const [formData, setFormData] = useState({ email: '', @@ -13,14 +14,17 @@ export default function LoginPage() { const [error, setError] = useState(null) + // Update the form data with new field value const handleChange = (e: React.ChangeEvent) => { const { name, value, type, checked } = e.target setFormData((prev) => ({ ...prev, + // checkboxes store value in property "checked" [name]: type === 'checkbox' ? checked : value, })) } + // Submit the form data to the auth service or show an error on failure. const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) diff --git a/src/app/register/page.tsx b/src/app/register/page.tsx index f81c109..5d91360 100644 --- a/src/app/register/page.tsx +++ b/src/app/register/page.tsx @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation' import { authService } from '@/services/AuthService' import FormError from '@/components/FormError' +// Page with the registration form. export default function RegisterPage() { const router = useRouter() @@ -17,6 +18,7 @@ export default function RegisterPage() { const [error, setError] = useState(null) + // Update the matching form field by input name. const handleChange = (e: React.ChangeEvent) => { setFormData((prev) => ({ ...prev, @@ -24,6 +26,7 @@ export default function RegisterPage() { })) } + // Validate the passwords match, register the user, then redirect to login. const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) diff --git a/src/components/FormError.tsx b/src/components/FormError.tsx index 1becbf9..4f16dc6 100644 --- a/src/components/FormError.tsx +++ b/src/components/FormError.tsx @@ -2,8 +2,9 @@ interface FormErrorProps { message: string | null } +// Shows a red alert box with an error message, or nothing if there is no message. export default function FormError(props: FormErrorProps) { - if (!props.message || props.message === '') return null + if (!props.message) return null return (
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index c6acb70..af9c9f3 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -3,6 +3,7 @@ import Link from 'next/link' import { font_Hack } from '@/lib/myFonts' +// Top navigation bar with a home link and login/register buttons. export default function Navbar() { return (