Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamically update document title #18

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading