Skip to content

Commit

Permalink
Handle language toggle for org subpages
Browse files Browse the repository at this point in the history
  • Loading branch information
RunarVestmann committed Jun 3, 2024
1 parent b7e2298 commit f389ae0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/LanguageToggler/LanguageToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const LanguageToggler = ({
activeTranslations = res.data?.getContentSlug?.activeTranslations
}

if (resolveLinkTypeLocally) {
if ((type as string) === 'genericListItem' || resolveLinkTypeLocally) {
const localType = typeResolver(pathWithoutQueryParams)?.type
if (localType) {
type = localType
Expand Down
4 changes: 4 additions & 0 deletions apps/web/hooks/useLinkResolver/useLinkResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const routesTemplate = {
is: '/s/[organization]/vidburdir',
en: '/en/o/[organization]/events',
},
organizationsubpagelistitem: {
is: '/s/[organization]/[slug]/[listItemSlug]',
en: '/en/o/[organization]/[slug]/[listItemSlug]',
},
aboutsubpage: {
is: '/s/stafraent-island/[slug]',
en: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const Component: ScreenType<ComponentProps> = ({
text: activeLocale === 'is' ? 'Til baka' : 'Go back', // TODO: perhaps read this value from contentful
url: backLinkUrl,
},
customContentfulIds: [
parentProps.componentProps.organizationPage?.id,
parentProps.componentProps.subpage?.id,
genericListItemProps.item.id,
],
}}
/>
)
Expand Down
8 changes: 7 additions & 1 deletion apps/web/screens/Organization/SubPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface SubPageProps {
customContent?: React.ReactNode
backLink?: { text: string; url: string }
customBreadcrumbItems?: BreadCrumbItem[]
customContentfulIds?: (string | undefined)[]
}

const SubPage: Screen<SubPageProps> = ({
Expand All @@ -66,6 +67,7 @@ const SubPage: Screen<SubPageProps> = ({
locale,
customContent,
customBreadcrumbItems,
customContentfulIds,
backLink,
}) => {
const router = useRouter()
Expand All @@ -74,7 +76,11 @@ const SubPage: Screen<SubPageProps> = ({
const n = useNamespace(namespace)
const { linkResolver } = useLinkResolver()

useContentfulId(organizationPage?.id, subpage?.id)
const contentfulIds = customContentfulIds
? customContentfulIds
: [organizationPage?.id, subpage?.id]

useContentfulId(...contentfulIds)

const pathWithoutHash = router.asPath.split('#')[0]
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
1 change: 1 addition & 0 deletions apps/web/screens/queries/GenericList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const GET_GENERIC_LIST_ITEMS_QUERY = gql`
export const GET_GENERIC_LIST_ITEM_BY_SLUG_QUERY = gql`
query GetGenericListItemBySlug($input: GetGenericListItemBySlugInput!) {
getGenericListItemBySlug(input: $input) {
id
date
title
slug
Expand Down

0 comments on commit f389ae0

Please sign in to comment.