mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-23 00:20:40 +07:00
fix(i18n): resolve bilingual data through a pure field() helper
useField and useFieldArray were hooks called from inside .map() callbacks - 11 rules-of-hooks errors. field(lang, value, valueEn) is a plain function, so the same selection is legal in a callback, with lang read once at component top level. One helper covers scalar and array values because both need the same lockstep rule. resolvedTheme is now theme directly: resolveTheme() was an identity helper left behind by the removed system variant.
This commit is contained in:
1 parent
df65f4c774
commit
29a884fd4d
12 files changed
+46
-53
No files matched your search
@@ -5,7 +5,7 @@ import { Tag } from '@/components/ui/Tag'
|
|||||||
import { profile } from '@/data/profile'
|
import { profile } from '@/data/profile'
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
export function About() {
|
export function About() {
|
||||||
const { lang } = useLanguage()
|
const { lang } = useLanguage()
|
||||||
return (
|
return (
|
||||||
@@ -23,7 +23,7 @@ export function About() {
|
|||||||
>
|
>
|
||||||
<SectionHeading title={strings.about.heading[lang]} tag={strings.about.heading[lang]} />
|
<SectionHeading title={strings.about.heading[lang]} tag={strings.about.heading[lang]} />
|
||||||
<p className="prose-lede lede-wide">
|
<p className="prose-lede lede-wide">
|
||||||
{useField(profile.bio, profile.bioEn)}
|
{field(lang, profile.bio, profile.bioEn)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 className="subheading">
|
<h3 className="subheading">
|
||||||
@@ -41,8 +41,8 @@ export function About() {
|
|||||||
whileHover={{ scale: 1.02, y: -4 }}
|
whileHover={{ scale: 1.02, y: -4 }}
|
||||||
whileTap={{ scale: 0.98 }}
|
whileTap={{ scale: 0.98 }}
|
||||||
>
|
>
|
||||||
<h3>{point.title}</h3>
|
<h3>{field(lang, point.title, point.titleEn)}</h3>
|
||||||
<p>{point.description}</p>
|
<p>{field(lang, point.description, point.descriptionEn)}</p>
|
||||||
<div className="philosophy-keywords">
|
<div className="philosophy-keywords">
|
||||||
{point.keywords.map((kw) => (
|
{point.keywords.map((kw) => (
|
||||||
<Tag key={kw}>{kw}</Tag>
|
<Tag key={kw}>{kw}</Tag>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { experiences } from "@/data/experience"
|
|||||||
import { InView } from "@/components/ui/InView"
|
import { InView } from "@/components/ui/InView"
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField, useFieldArray } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
export function Experience() {
|
export function Experience() {
|
||||||
const { lang } = useLanguage()
|
const { lang } = useLanguage()
|
||||||
@@ -36,7 +36,7 @@ export function Experience() {
|
|||||||
<div className="timeline-marker" />
|
<div className="timeline-marker" />
|
||||||
<div className="timeline-header">
|
<div className="timeline-header">
|
||||||
<div className="timeline-title">
|
<div className="timeline-title">
|
||||||
{useField(exp.title, exp.titleEn)}
|
{field(lang, exp.title, exp.titleEn)}
|
||||||
</div>
|
</div>
|
||||||
<div className="timeline-company">{exp.company}</div>
|
<div className="timeline-company">{exp.company}</div>
|
||||||
<div className="timeline-meta">
|
<div className="timeline-meta">
|
||||||
@@ -47,7 +47,7 @@ export function Experience() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className="timeline-responsibilities">
|
<ul className="timeline-responsibilities">
|
||||||
{useFieldArray(exp.responsibilities, exp.responsibilitiesEn).map((r) => (
|
{field(lang, exp.responsibilities, exp.responsibilitiesEn).map((r) => (
|
||||||
<li key={r}>{r}</li>
|
<li key={r}>{r}</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { skillGroups } from "@/data/skills"
|
|||||||
import { InView } from "@/components/ui/InView"
|
import { InView } from "@/components/ui/InView"
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
export function Expertise() {
|
export function Expertise() {
|
||||||
const { lang } = useLanguage()
|
const { lang } = useLanguage()
|
||||||
@@ -34,7 +34,7 @@ export function Expertise() {
|
|||||||
whileHover={{ scale: 1.02, y: -4 }}
|
whileHover={{ scale: 1.02, y: -4 }}
|
||||||
whileTap={{ scale: 0.98 }}
|
whileTap={{ scale: 0.98 }}
|
||||||
>
|
>
|
||||||
<h3>{useField(group.title, group.titleEn)}</h3>
|
<h3>{field(lang, group.title, group.titleEn)}</h3>
|
||||||
<ul className="expertise-skills">
|
<ul className="expertise-skills">
|
||||||
{group.skills.map((skill) => (
|
{group.skills.map((skill) => (
|
||||||
<li key={skill} className="expertise-skill">
|
<li key={skill} className="expertise-skill">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {resumeAvailable, resumeLanguages, resumeUrlFor, resumeLanguageLabels} fr
|
|||||||
import type {Language} from '@/types'
|
import type {Language} from '@/types'
|
||||||
import {useLanguage} from '@/hooks/useLanguage'
|
import {useLanguage} from '@/hooks/useLanguage'
|
||||||
import {strings} from '@/i18n/strings'
|
import {strings} from '@/i18n/strings'
|
||||||
import {useField} from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
import {DownloadResumeDropdown} from '@/components/sections/DownloadResume'
|
import {DownloadResumeDropdown} from '@/components/sections/DownloadResume'
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ export function Hero() {
|
|||||||
viewport={{once: true, amount: 0.2}}
|
viewport={{once: true, amount: 0.2}}
|
||||||
transition={{duration: 0.45, ease: "easeOut", delay: 0.08}}
|
transition={{duration: 0.45, ease: "easeOut", delay: 0.08}}
|
||||||
>
|
>
|
||||||
<span className="name-highlight">{useField(profile.name, profile.nameEn)}</span>
|
<span className="name-highlight">{field(lang, profile.name, profile.nameEn)}</span>
|
||||||
</motion.h1>
|
</motion.h1>
|
||||||
<motion.p
|
<motion.p
|
||||||
className="hero-title"
|
className="hero-title"
|
||||||
@@ -88,7 +88,7 @@ export function Hero() {
|
|||||||
whileInView={{opacity: 1, y: 0}}
|
whileInView={{opacity: 1, y: 0}}
|
||||||
viewport={{once: true, amount: 0.2}}
|
viewport={{once: true, amount: 0.2}}
|
||||||
transition={{duration: 0.45, ease: "easeOut", delay: 0.24}}
|
transition={{duration: 0.45, ease: "easeOut", delay: 0.24}}
|
||||||
dangerouslySetInnerHTML={{__html: useField(profile.tagline, profile.taglineEn)}}
|
dangerouslySetInnerHTML={{__html: field(lang, profile.tagline, profile.taglineEn)}}
|
||||||
/>
|
/>
|
||||||
<motion.div
|
<motion.div
|
||||||
className="hero-cta"
|
className="hero-cta"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { projects } from "@/data/projects"
|
|||||||
import { InView } from "@/components/ui/InView"
|
import { InView } from "@/components/ui/InView"
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
const MotionLink = motion.create(Link)
|
const MotionLink = motion.create(Link)
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ export function Projects() {
|
|||||||
>
|
>
|
||||||
<div className="project-card-content">
|
<div className="project-card-content">
|
||||||
<div className="project-card-header">
|
<div className="project-card-header">
|
||||||
<h3>{project.title}</h3>
|
<h3>{field(lang, project.title, project.titleEn)}</h3>
|
||||||
<Badge variant="outline">
|
<Badge variant="outline">
|
||||||
{strings.projects.categories[project.category][lang]}
|
{strings.projects.categories[project.category][lang]}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<p className="project-card-summary">{useField(project.summary, project.summaryEn)}</p>
|
<p className="project-card-summary">{field(lang, project.summary, project.summaryEn)}</p>
|
||||||
<div className="project-card-techs">
|
<div className="project-card-techs">
|
||||||
{project.technologies.slice(0, 4).map((tech) => (
|
{project.technologies.slice(0, 4).map((tech) => (
|
||||||
<span key={tech} className="tag">
|
<span key={tech} className="tag">
|
||||||
|
|||||||
@@ -42,15 +42,11 @@ function getInitialPalette(): Palette {
|
|||||||
return 'red'
|
return 'red'
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveTheme(theme: Theme): 'dark' | 'light' {
|
|
||||||
return theme
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||||
const [theme, setThemeState] = useState<Theme>(getInitialTheme)
|
const [theme, setThemeState] = useState<Theme>(getInitialTheme)
|
||||||
const [palette, setPaletteState] = useState<Palette>(getInitialPalette)
|
const [palette, setPaletteState] = useState<Palette>(getInitialPalette)
|
||||||
|
|
||||||
const resolvedTheme = resolveTheme(theme)
|
const resolvedTheme = theme
|
||||||
|
|
||||||
// Set data-theme during render so it's available before paint
|
// Set data-theme during render so it's available before paint
|
||||||
document.documentElement.setAttribute('data-theme', resolvedTheme)
|
document.documentElement.setAttribute('data-theme', resolvedTheme)
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import type { Language } from '@/types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select one value from a bilingual pair. Plain function, not a hook: `lang` is
|
||||||
|
* read once at component top level with `useLanguage()`, so `field` is safe
|
||||||
|
* inside `.map()` callbacks.
|
||||||
|
*
|
||||||
|
* Convention: `value` is the Vietnamese value, `valueEn` the English one. When a
|
||||||
|
* pair has no English variant yet, `valueEn` is undefined and both languages
|
||||||
|
* render `value`.
|
||||||
|
*/
|
||||||
|
export function field<T>(lang: Language, value: T, valueEn: T | undefined): T {
|
||||||
|
return lang === 'vi' ? value : (valueEn ?? value)
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { useLanguage } from '@/hooks/useLanguage'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* React hook: select field by language. Must be called at component top level.
|
|
||||||
*/
|
|
||||||
export function useField<T>(value: T, valueEn: T | undefined): T {
|
|
||||||
const { lang } = useLanguage()
|
|
||||||
return lang === 'vi' ? value : (valueEn ?? value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* React hook: select array field by language. Must be called at component top level.
|
|
||||||
*/
|
|
||||||
export function useFieldArray<T>(value: T[], valueEn: T[] | undefined): T[] {
|
|
||||||
const { lang } = useLanguage()
|
|
||||||
return lang === 'vi' ? value : (valueEn ?? value)
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import { profile } from '@/data/profile'
|
|||||||
import { skillGroups } from '@/data/skills'
|
import { skillGroups } from '@/data/skills'
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
export function AboutPage() {
|
export function AboutPage() {
|
||||||
const { lang } = useLanguage()
|
const { lang } = useLanguage()
|
||||||
@@ -30,7 +30,7 @@ export function AboutPage() {
|
|||||||
tag={strings.about.heading[lang]}
|
tag={strings.about.heading[lang]}
|
||||||
/>
|
/>
|
||||||
<p className="prose-lede lede-wide">
|
<p className="prose-lede lede-wide">
|
||||||
{useField(profile.bio, profile.bioEn)}
|
{field(lang, profile.bio, profile.bioEn)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 className="subheading">
|
<h3 className="subheading">
|
||||||
@@ -48,8 +48,8 @@ export function AboutPage() {
|
|||||||
whileHover={{ scale: 1.02, y: -4 }}
|
whileHover={{ scale: 1.02, y: -4 }}
|
||||||
whileTap={{ scale: 0.98 }}
|
whileTap={{ scale: 0.98 }}
|
||||||
>
|
>
|
||||||
<h3>{point.title}</h3>
|
<h3>{field(lang, point.title, point.titleEn)}</h3>
|
||||||
<p>{point.description}</p>
|
<p>{field(lang, point.description, point.descriptionEn)}</p>
|
||||||
<div className="philosophy-keywords">
|
<div className="philosophy-keywords">
|
||||||
{point.keywords.map((kw) => (
|
{point.keywords.map((kw) => (
|
||||||
<Tag key={kw}>{kw}</Tag>
|
<Tag key={kw}>{kw}</Tag>
|
||||||
@@ -96,7 +96,7 @@ export function AboutPage() {
|
|||||||
whileHover={{ scale: 1.02, y: -4 }}
|
whileHover={{ scale: 1.02, y: -4 }}
|
||||||
whileTap={{ scale: 0.98 }}
|
whileTap={{ scale: 0.98 }}
|
||||||
>
|
>
|
||||||
<h3>{useField(group.title, group.titleEn)}</h3>
|
<h3>{field(lang, group.title, group.titleEn)}</h3>
|
||||||
<ul className="expertise-skills">
|
<ul className="expertise-skills">
|
||||||
{group.skills.map((skill: string) => (
|
{group.skills.map((skill: string) => (
|
||||||
<li key={skill} className="expertise-skill">
|
<li key={skill} className="expertise-skill">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { InView } from '@/components/ui/InView'
|
|||||||
import { experiences } from '@/data/experience'
|
import { experiences } from '@/data/experience'
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField, useFieldArray } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
export function ExperiencePage() {
|
export function ExperiencePage() {
|
||||||
const { lang } = useLanguage()
|
const { lang } = useLanguage()
|
||||||
@@ -34,7 +34,7 @@ export function ExperiencePage() {
|
|||||||
>
|
>
|
||||||
<div className="timeline-marker" />
|
<div className="timeline-marker" />
|
||||||
<div className="timeline-header">
|
<div className="timeline-header">
|
||||||
<div className="timeline-title">{useField(exp.title, exp.titleEn)}</div>
|
<div className="timeline-title">{field(lang, exp.title, exp.titleEn)}</div>
|
||||||
<div className="timeline-company">{exp.company}</div>
|
<div className="timeline-company">{exp.company}</div>
|
||||||
<div className="timeline-meta">
|
<div className="timeline-meta">
|
||||||
<span className="timeline-duration">{exp.duration}</span>
|
<span className="timeline-duration">{exp.duration}</span>
|
||||||
@@ -42,7 +42,7 @@ export function ExperiencePage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className="timeline-responsibilities">
|
<ul className="timeline-responsibilities">
|
||||||
{useFieldArray(exp.responsibilities, exp.responsibilitiesEn).map((r) => (
|
{field(lang, exp.responsibilities, exp.responsibilitiesEn).map((r) => (
|
||||||
<li key={r}>{r}</li>
|
<li key={r}>{r}</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { InView } from '@/components/ui/InView'
|
|||||||
import { projects } from '@/data/projects'
|
import { projects } from '@/data/projects'
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
const sectionVariants = {
|
const sectionVariants = {
|
||||||
hidden: { opacity: 0 },
|
hidden: { opacity: 0 },
|
||||||
@@ -64,7 +64,7 @@ export function ProjectDetailPage() {
|
|||||||
viewport={{ once: true, amount: 0.2 }}
|
viewport={{ once: true, amount: 0.2 }}
|
||||||
transition={itemTransition(0)}
|
transition={itemTransition(0)}
|
||||||
>
|
>
|
||||||
<h1 id="project-title" style={{ flex: 1 }}>{project.title}</h1>
|
<h1 id="project-title" style={{ flex: 1 }}>{field(lang, project.title, project.titleEn)}</h1>
|
||||||
<Badge variant="outline">{strings.projects.categories[project.category][lang]}</Badge>
|
<Badge variant="outline">{strings.projects.categories[project.category][lang]}</Badge>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ export function ProjectDetailPage() {
|
|||||||
viewport={{ once: true, amount: 0.2 }}
|
viewport={{ once: true, amount: 0.2 }}
|
||||||
transition={itemTransition(0.08)}
|
transition={itemTransition(0.08)}
|
||||||
>
|
>
|
||||||
{useField(project.summary, project.summaryEn)}
|
{field(lang, project.summary, project.summaryEn)}
|
||||||
</motion.p>
|
</motion.p>
|
||||||
|
|
||||||
<div className="prose">
|
<div className="prose">
|
||||||
@@ -140,8 +140,8 @@ export function ProjectDetailPage() {
|
|||||||
viewport={{ once: true, amount: 0.2 }}
|
viewport={{ once: true, amount: 0.2 }}
|
||||||
transition={itemTransition(0.48 + idx * 0.08)}
|
transition={itemTransition(0.48 + idx * 0.08)}
|
||||||
>
|
>
|
||||||
<h4>{useField(section.title, section.titleEn)}</h4>
|
<h4>{field(lang, section.title, section.titleEn)}</h4>
|
||||||
<p>{useField(section.content, section.contentEn)}</p>
|
<p>{field(lang, section.content, section.contentEn)}</p>
|
||||||
<Tag accent>{section.type}</Tag>
|
<Tag accent>{section.type}</Tag>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { InView } from '@/components/ui/InView'
|
|||||||
import { projects } from '@/data/projects'
|
import { projects } from '@/data/projects'
|
||||||
import { useLanguage } from '@/hooks/useLanguage'
|
import { useLanguage } from '@/hooks/useLanguage'
|
||||||
import { strings } from '@/i18n/strings'
|
import { strings } from '@/i18n/strings'
|
||||||
import { useField } from '@/i18n/useField'
|
import { field } from '@/i18n/field'
|
||||||
|
|
||||||
import { Link } from 'react-router'
|
import { Link } from 'react-router'
|
||||||
|
|
||||||
@@ -41,12 +41,12 @@ export function ProjectsListPage() {
|
|||||||
whileTap={{ scale: 0.98 }}
|
whileTap={{ scale: 0.98 }}
|
||||||
>
|
>
|
||||||
<div className="project-card-header">
|
<div className="project-card-header">
|
||||||
<h3>{project.title}</h3>
|
<h3>{field(lang, project.title, project.titleEn)}</h3>
|
||||||
<Badge variant="outline">
|
<Badge variant="outline">
|
||||||
{strings.projects.categories[project.category][lang]}
|
{strings.projects.categories[project.category][lang]}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<p className="project-card-summary">{useField(project.summary, project.summaryEn)}</p>
|
<p className="project-card-summary">{field(lang, project.summary, project.summaryEn)}</p>
|
||||||
<div className="project-card-techs">
|
<div className="project-card-techs">
|
||||||
{project.technologies.slice(0, 4).map((tech) => (
|
{project.technologies.slice(0, 4).map((tech) => (
|
||||||
<span key={tech} className="tag">
|
<span key={tech} className="tag">
|
||||||
|
|||||||
Reference in new issue
Block a user