Skip to content

Commit

Permalink
feat: dynamically update document title
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-cheng committed Mar 23, 2024
1 parent ece084d commit a06d7ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<link rel="icon" type="image/png" href="/favicon.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Vitamin" />
<meta name="description" content="Aha Front-End Assessment" />
<meta name="theme-color" content="#42b883" />
<title>Vitamin</title>
<title>Aha Front-End Assessment</title>
</head>
<body class="bg-background text-white">
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "vitamin",
"name": "aha-frontend-assessment",
"license": "MIT",
"private": true,
"version": "0.0.0",
Expand Down
13 changes: 12 additions & 1 deletion src/components/common/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { hasTagsNotificationAtom } from 'atoms/core'
import { useAtom } from 'jotai'
import { useEffect, type ReactElement } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { Link, useLocation, useSearchParams } from 'react-router-dom'
import cn from 'utils/cn'
import ArrowBackSvg from '../../../icons/ArrowBack.svg?react'
import Logo from '../Logo'
import NavButton from './NavButton'

export default function NavBar(): ReactElement {
const { pathname } = useLocation()
const [searchParams] = useSearchParams()

const [hasTagsNotification, setHasTagsNotification] = useAtom(
hasTagsNotificationAtom
Expand All @@ -20,6 +21,16 @@ export default function NavBar(): ReactElement {
}
}, [pathname, setHasTagsNotification])

useEffect(() => {
let title = 'Aha Front-End Assessment'
if (pathname === '/tags') {
title = `Tags - ${title}`
} else if (pathname === '/results') {
title = `${searchParams.get('keyword')} - ${title}`
}
document.title = title
}, [pathname, searchParams])

return (
<>
<div
Expand Down

0 comments on commit a06d7ce

Please sign in to comment.