diff --git a/src/App.tsx b/src/App.tsx index 334c972..f7ef41a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,17 +1,19 @@ import './App.css' +import { lazy, Suspense } from 'react' import { BrowserRouter, Routes, Route } from 'react-router' import { ThemeProvider } from '@/hooks/useTheme' import { Layout } from '@/components/layout/Layout' import { LanguageProvider } from '@/hooks/useLanguage' -import { - HomePage, - AboutPage, - ExperiencePage, - ProjectsListPage, - ProjectDetailPage, - PhilosophyPage, - ContactPage, -} from '@/pages' +import { HomePage } from '@/pages/HomePage' + +// HomePage stays eager: it is the landing route and owns the LCP, so its code must +// already be in the entry chunk. The other six split out and load on navigation. +const AboutPage = lazy(() => import('@/pages/AboutPage').then((m) => ({ default: m.AboutPage }))) +const ExperiencePage = lazy(() => import('@/pages/ExperiencePage').then((m) => ({ default: m.ExperiencePage }))) +const ProjectsListPage = lazy(() => import('@/pages/ProjectsListPage').then((m) => ({ default: m.ProjectsListPage }))) +const ProjectDetailPage = lazy(() => import('@/pages/ProjectDetailPage').then((m) => ({ default: m.ProjectDetailPage }))) +const PhilosophyPage = lazy(() => import('@/pages/PhilosophyPage').then((m) => ({ default: m.PhilosophyPage }))) +const ContactPage = lazy(() => import('@/pages/ContactPage').then((m) => ({ default: m.ContactPage }))) function App() { return ( @@ -19,18 +21,22 @@ function App() { - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - + {/* A null fallback keeps the shell (nav, footer) painted without reserving a + box that would shift the page when the route chunk lands. */} + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + + ) } diff --git a/src/components/layout/Navigation.tsx b/src/components/layout/Navigation.tsx index 4f60483..d72d68d 100644 --- a/src/components/layout/Navigation.tsx +++ b/src/components/layout/Navigation.tsx @@ -57,7 +57,7 @@ export function Navigation() { return ( <> - + {/* Trigger first, brand next: the hamburger is the sheet's own control and sits at @@ -143,8 +143,8 @@ export function Navigation() { {resolvedTheme === 'dark' ? ( diff --git a/src/components/sections/Hero.tsx b/src/components/sections/Hero.tsx index 1125dc8..ca8d86b 100644 --- a/src/components/sections/Hero.tsx +++ b/src/components/sections/Hero.tsx @@ -135,9 +135,12 @@ export function Hero() { > diff --git a/src/components/ui/BackToTop.tsx b/src/components/ui/BackToTop.tsx index 1b405a2..3c453c2 100644 --- a/src/components/ui/BackToTop.tsx +++ b/src/components/ui/BackToTop.tsx @@ -1,10 +1,14 @@ import { useEffect, useState } from "react" -import { motion, AnimatePresence } from "motion/react" +import { motion, AnimatePresence, useReducedMotion } from "motion/react" +import { strings } from '@/i18n/strings' +import { useLanguage } from '@/hooks/useLanguage' const SCROLL_THRESHOLD = 300 export function BackToTop() { const [visible, setVisible] = useState(false) + const reduceMotion = useReducedMotion() + const { lang } = useLanguage() useEffect(() => { const handleScroll = () => { @@ -16,7 +20,7 @@ export function BackToTop() { }, []) const scrollToTop = () => { - window.scrollTo({ top: 0, behavior: "smooth" }) + window.scrollTo({ top: 0, behavior: reduceMotion ? 'auto' : 'smooth' }) } return ( @@ -24,7 +28,7 @@ export function BackToTop() { {visible && ( { + if (reduceMotion) return const text = texts[currentTextIndex] let timeout: number @@ -40,12 +44,16 @@ export function Typewriter({ } return () => clearTimeout(timeout) - }, [currentText, currentTextIndex, isDeleting, texts, typeSpeed, deleteSpeed, pauseDuration]) + }, [reduceMotion, currentText, currentTextIndex, isDeleting, texts, typeSpeed, deleteSpeed, pauseDuration]) return ( - - {currentText} - - + <> + {/* Assistive tech gets the whole role list once; the typed prefix is decoration. */} + {texts.join(', ')} + + {reduceMotion ? texts[0] : currentText} + + + > ) } diff --git a/src/i18n/strings.ts b/src/i18n/strings.ts index 408d4af..12a1552 100644 --- a/src/i18n/strings.ts +++ b/src/i18n/strings.ts @@ -21,6 +21,9 @@ export const strings = { langVi: {en: 'Tiếng Việt', vi: 'Tiếng Việt'}, langSwitch: {en: 'Switch language', vi: 'Đổi ngôn ngữ'}, switchTo: {en: 'Switch to', vi: 'Chuyển sang'}, + mainNav: {en: 'Main navigation', vi: 'Điều hướng chính'}, + themeSwitch: {en: 'Switch display mode', vi: 'Đổi chế độ hiển thị'}, + themeMode: {en: 'Display mode', vi: 'Chế độ hiển thị'}, }, social: { heading: {en: 'Connect', vi: 'Kết nối'}, @@ -113,6 +116,7 @@ export const strings = { }, common: { resumeDownload: {en: 'Get Resume', vi: 'Tải CV'}, + backToTop: {en: 'Scroll to top', vi: 'Cuộn lên đầu trang'}, contactTag: {en: 'Contact', vi: 'Liên hệ'}, experienceTag: {en: 'Experience', vi: 'Kinh nghiệm'}, }, diff --git a/src/index.css b/src/index.css index a213b03..b810b02 100644 --- a/src/index.css +++ b/src/index.css @@ -332,6 +332,18 @@ pre code { padding: 80px 0; } +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; + border: 0; +} + @media (max-width: 768px) { .section { padding: 48px 0; diff --git a/src/pages/index.ts b/src/pages/index.ts deleted file mode 100644 index c84e2c9..0000000 --- a/src/pages/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export { HomePage } from './HomePage' -export { AboutPage } from './AboutPage' -export { ExperiencePage } from './ExperiencePage' -export { ProjectsListPage } from './ProjectsListPage' -export { ProjectDetailPage } from './ProjectDetailPage' -export { PhilosophyPage } from './PhilosophyPage.tsx' -export { ContactPage } from './ContactPage'