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

chore(web): Move organization subpage content into separate component #16915

Merged
merged 2 commits into from
Nov 18, 2024
Merged
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
285 changes: 156 additions & 129 deletions apps/web/screens/Organization/SubPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Locale } from '@island.is/shared/types'
import { useRouter } from 'next/router'
import { ParsedUrlQuery } from 'querystring'

Expand All @@ -14,6 +13,7 @@ import {
Stack,
Text,
} from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import {
getThemeConfig,
OrganizationWrapper,
Expand Down Expand Up @@ -60,46 +60,13 @@ export interface SubPageProps {
customContentfulIds?: (string | undefined)[]
}

const SubPage: Screen<SubPageProps> = ({
organizationPage,
const SubPageContent = ({
subpage,
namespace,
locale,
customContent,
customBreadcrumbItems,
customContentfulIds,
backLink,
}) => {
const router = useRouter()
const { activeLocale } = useI18n()

organizationPage,
}: Pick<SubPageProps, 'subpage' | 'organizationPage' | 'namespace'>) => {
RunarVestmann marked this conversation as resolved.
Show resolved Hide resolved
const n = useNamespace(namespace)
const { linkResolver } = useLinkResolver()

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

useContentfulId(...contentfulIds)

const pathname = new URL(router.asPath, 'https://island.is').pathname
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
const navList: NavigationItem[] = organizationPage?.menuLinks.map(
({ primaryLink, childrenLinks }) => ({
title: primaryLink?.text,
href: primaryLink?.url,
active:
primaryLink?.url === pathname ||
childrenLinks.some((link) => link.url === pathname),
items: childrenLinks.map(({ text, url }) => ({
title: text,
href: url,
active: url === pathname,
})),
}),
)

const { activeLocale } = useI18n()
const content = (
<>
{subpage?.showTableOfContents && (
Expand Down Expand Up @@ -147,45 +114,8 @@ const SubPage: Screen<SubPageProps> = ({
</GridRow>
</>
)

return (
<OrganizationWrapper
showExternalLinks={true}
showReadSpeaker={false}
pageTitle={subpage?.title ?? ''}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
organizationPage={organizationPage}
fullWidthContent={true}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
pageFeaturedImage={
subpage?.featuredImage ?? organizationPage?.featuredImage
}
backLink={backLink}
breadcrumbItems={
customBreadcrumbItems
? customBreadcrumbItems
: [
{
title: 'Ísland.is',
href: linkResolver('homepage', [], locale).href,
},
{
title: organizationPage?.title ?? '',
href: linkResolver(
'organizationpage',
[organizationPage?.slug ?? ''],
locale,
).href,
},
]
}
navigationData={{
title: n('navigationTitle', 'Efnisyfirlit'),
items: navList,
}}
>
<>
<GridContainer>
<Box paddingTop={4}>
<GridRow>
Expand All @@ -199,62 +129,58 @@ const SubPage: Screen<SubPageProps> = ({
subpage?.links?.length ? '7/12' : '12/12',
]}
>
{customContent ? (
customContent
) : (
<>
<Box className="rs_read" marginBottom={2}>
<Text variant="h1" as="h1">
{subpage?.title}
</Text>
</Box>
<Box
display="flex"
alignItems="center"
columnGap={2}
rowGap={2}
marginBottom={3}
flexWrap="wrap"
>
<Webreader
marginTop={0}
marginBottom={0}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
readId={null}
readClass="rs_read"
<>
<Box className="rs_read" marginBottom={2}>
<Text variant="h1" as="h1">
{subpage?.title}
</Text>
</Box>
<Box
display="flex"
alignItems="center"
columnGap={2}
rowGap={2}
marginBottom={3}
flexWrap="wrap"
>
<Webreader
marginTop={0}
marginBottom={0}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
readId={null}
readClass="rs_read"
/>
{subpage?.signLanguageVideo?.url && (
<SignLanguageButton
videoUrl={subpage.signLanguageVideo.url}
videoThumbnailImageUrl={
subpage.signLanguageVideo.thumbnailImageUrl
}
content={
<>
<Box className="rs_read" marginBottom={2}>
<Text variant="h2">{subpage.title}</Text>
</Box>
{content}
{renderSlices(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
subpage.slices,
subpage.sliceCustomRenderer,
subpage.sliceExtraText,
namespace,
organizationPage?.slug,
)}
</>
}
/>
{subpage?.signLanguageVideo?.url && (
<SignLanguageButton
videoUrl={subpage.signLanguageVideo.url}
videoThumbnailImageUrl={
subpage.signLanguageVideo.thumbnailImageUrl
}
content={
<>
<Box className="rs_read" marginBottom={2}>
<Text variant="h2">{subpage.title}</Text>
</Box>
{content}
{renderSlices(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
subpage.slices,
subpage.sliceCustomRenderer,
subpage.sliceExtraText,
namespace,
organizationPage?.slug,
)}
</>
}
/>
)}
</Box>
</>
)}
)}
</Box>
</>
</GridColumn>
</GridRow>
{!customContent && content}
{content}
</GridContainer>
</GridColumn>
</GridRow>
Expand All @@ -277,6 +203,107 @@ const SubPage: Screen<SubPageProps> = ({
organizationPage.slug,
)}
</Stack>
</>
)
}

const SubPage: Screen<SubPageProps> = ({
organizationPage,
subpage,
namespace,
locale,
customContent,
customBreadcrumbItems,
customContentfulIds,
backLink,
}) => {
const router = useRouter()

const n = useNamespace(namespace)
const { linkResolver } = useLinkResolver()

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

useContentfulId(...contentfulIds)
RunarVestmann marked this conversation as resolved.
Show resolved Hide resolved

const pathname = new URL(router.asPath, 'https://island.is').pathname
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
const navList: NavigationItem[] = organizationPage?.menuLinks.map(
({ primaryLink, childrenLinks }) => ({
title: primaryLink?.text,
href: primaryLink?.url,
active:
primaryLink?.url === pathname ||
childrenLinks.some((link) => link.url === pathname),
items: childrenLinks.map(({ text, url }) => ({
title: text,
href: url,
active: url === pathname,
})),
}),
)
RunarVestmann marked this conversation as resolved.
Show resolved Hide resolved

return (
<OrganizationWrapper
showExternalLinks={true}
showReadSpeaker={false}
pageTitle={subpage?.title ?? ''}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
organizationPage={organizationPage}
fullWidthContent={true}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
pageFeaturedImage={
subpage?.featuredImage ?? organizationPage?.featuredImage
}
backLink={backLink}
breadcrumbItems={
customBreadcrumbItems
? customBreadcrumbItems
: [
{
title: 'Ísland.is',
href: linkResolver('homepage', [], locale).href,
},
{
title: organizationPage?.title ?? '',
href: linkResolver(
'organizationpage',
[organizationPage?.slug ?? ''],
locale,
).href,
},
]
}
navigationData={{
title: n('navigationTitle', 'Efnisyfirlit'),
items: navList,
}}
>
{customContent ? (
<GridContainer>
<Box paddingTop={4}>
<GridRow>
<GridColumn
span={['9/9', '9/9', '7/9']}
offset={['0', '0', '1/9']}
>
{customContent}
</GridColumn>
</GridRow>
</Box>
</GridContainer>
) : (
<SubPageContent
subpage={subpage}
namespace={namespace}
organizationPage={organizationPage}
/>
)}
</OrganizationWrapper>
)
}
Expand Down