Skip to content

Commit

Permalink
remove currentLanguage from mainContext, use router.locale instead (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesurowiec authored Sep 27, 2021
1 parent 4e0b83d commit 3125579
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
5 changes: 3 additions & 2 deletions components/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { SupportSection } from 'components/page-footer/SupportSection'
import { DeprecationBanner } from 'components/page-header/DeprecationBanner'
import { useMainContext } from 'components/context/MainContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { useRouter } from 'next/router'

type Props = { children?: React.ReactNode }
export const DefaultLayout = (props: Props) => {
const {
page,
error,
isHomepageVersion,
currentLanguage,
currentPathWithoutLanguage,
currentVersion,
currentProduct,
Expand All @@ -24,6 +24,7 @@ export const DefaultLayout = (props: Props) => {
status,
} = useMainContext()
const { t } = useTranslation(['errors', 'scroll_button'])
const router = useRouter()
return (
<div className="d-lg-flex">
<Head>
Expand Down Expand Up @@ -52,7 +53,7 @@ export const DefaultLayout = (props: Props) => {
{page.topics.length > 0 && <meta name="keywords" content={page.topics.join(',')} />}

{/* For analytics events */}
{currentLanguage && <meta name="path-language" content={currentLanguage} />}
{router.locale && <meta name="path-language" content={router.locale} />}
{currentVersion && <meta name="path-version" content={currentVersion} />}
{currentProduct && <meta name="path-product" content={currentProduct.id} />}
{relativePath && (
Expand Down
2 changes: 0 additions & 2 deletions components/context/MainContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export type MainContextT = {
relativePath?: string
enterpriseServerReleases: EnterpriseServerReleases
currentPathWithoutLanguage: string
currentLanguage: string
userLanguage: string
allVersions: Record<string, VersionItem>
currentVersion?: string
Expand Down Expand Up @@ -162,7 +161,6 @@ export const getMainContext = (req: any, res: any): MainContextT => {
'supported',
]),
enterpriseServerVersions: req.context.enterpriseServerVersions,
currentLanguage: req.context.currentLanguage,
userLanguage: req.context.userLanguage || '',
allVersions: req.context.allVersions,
currentVersion: req.context.currentVersion,
Expand Down
14 changes: 4 additions & 10 deletions components/page-header/HeaderNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ type Notif = {
export const HeaderNotifications = () => {
const router = useRouter()
const { currentVersion } = useVersion()
const {
relativePath,
allVersions,
data,
currentLanguage,
userLanguage,
currentPathWithoutLanguage,
} = useMainContext()
const { relativePath, allVersions, data, userLanguage, currentPathWithoutLanguage } =
useMainContext()
const { languages } = useLanguages()
const { t } = useTranslation('header')

Expand All @@ -39,12 +33,12 @@ export const HeaderNotifications = () => {
type: NotificationType.TRANSLATION,
content: data.reusables.policies.translation,
})
} else if (languages[currentLanguage].wip !== true) {
} else if (router.locale && languages[router.locale].wip !== true) {
translationNotices.push({
type: NotificationType.TRANSLATION,
content: t('notices.localization_complete'),
})
} else if (languages[currentLanguage].wip) {
} else if (router.locale && languages[router.locale].wip) {
translationNotices.push({
type: NotificationType.TRANSLATION,
content: t('notices.localization_in_progress'),
Expand Down
10 changes: 6 additions & 4 deletions components/release-notes/GHESReleaseNotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@primer/octicons-react'
import { useMainContext } from 'components/context/MainContext'
import dayjs from 'dayjs'
import { useRouter } from 'next/router'

import { Link } from 'components/Link'
import { MarkdownContent } from 'components/ui/MarkdownContent'
Expand All @@ -18,7 +19,8 @@ type Props = {
context: GHESReleaseNotesContextT
}
export function GHESReleaseNotes({ context }: Props) {
const { currentLanguage, currentProduct } = useMainContext()
const router = useRouter()
const { currentProduct } = useMainContext()
const [focusedPatch, setFocusedPatch] = useState('')
const {
prevRelease,
Expand All @@ -37,7 +39,7 @@ export function GHESReleaseNotes({ context }: Props) {
{prevRelease ? (
<Link
className="btn btn-outline"
href={`/${currentLanguage}/${currentVersion.plan}@${prevRelease}/${currentProduct?.id}/release-notes`}
href={`/${router.locale}/${currentVersion.plan}@${prevRelease}/${currentProduct?.id}/release-notes`}
>
<ChevronLeftIcon /> {prevRelease}
</Link>
Expand All @@ -52,7 +54,7 @@ export function GHESReleaseNotes({ context }: Props) {
{nextRelease ? (
<Link
className="btn btn-outline"
href={`/${currentLanguage}/${currentVersion.plan}@${nextRelease}/${currentProduct?.id}/release-notes`}
href={`/${router.locale}/${currentVersion.plan}@${nextRelease}/${currentProduct?.id}/release-notes`}
>
{nextRelease} <ChevronRightIcon />
</Link>
Expand Down Expand Up @@ -87,7 +89,7 @@ export function GHESReleaseNotes({ context }: Props) {
<MarkdownContent data-search="article-content">
<ul className="list-style-none pl-0 text-bold">
{releases.map((release) => {
const releaseLink = `/${currentLanguage}/${currentVersion.plan}@${release.version}/${currentProduct?.id}/release-notes`
const releaseLink = `/${router.locale}/${currentVersion.plan}@${release.version}/${currentProduct?.id}/release-notes`

if (!release.patches || release.patches.length === 0) {
return (
Expand Down

0 comments on commit 3125579

Please sign in to comment.