-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bose/2659' into staging
- Loading branch information
Showing
10 changed files
with
508 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getNameFromLocale } from '../../../lib/localization' | ||
import { sanityClient } from '../../../lib/sanity.server' | ||
import { getNewsArticlesByPage } from '../../../lib/queries/newsroom' | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const lang = req.query.lang === 'no' ? getNameFromLocale('no') : getNameFromLocale('en') // Defaults to 'en' if the lang parameter is not 'no' | ||
|
||
console.log('get next from req.query.lastId', req.query.lastId) | ||
console.log('get next from req.query.lastPublishedAt', req.query.lastPublishedAt) | ||
try { | ||
const news = await sanityClient.fetch(getNewsArticlesByPage(false, true), { | ||
lang, | ||
lastId: req.query.lastId, | ||
lastPublishedAt: req.query.lastPublishedAt, | ||
}) | ||
res.status(200).json({ news: news }) | ||
} catch (err) { | ||
res.status(500).json({ error: 'Failed to fetch news' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getNameFromLocale } from '../../../lib/localization' | ||
import { sanityClient } from '../../../lib/sanity.server' | ||
import { getNewsArticlesByPage } from '../../../lib/queries/newsroom' | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const lang = req.query.lang === 'no' ? getNameFromLocale('no') : getNameFromLocale('en') // Defaults to 'en' if the lang parameter is not 'no' | ||
|
||
try { | ||
const news = await sanityClient.fetch(getNewsArticlesByPage(true, false), { | ||
lang, | ||
lastId: req.query.lastId, | ||
lastPublishedAt: req.query.lastPublishedAt, | ||
}) | ||
res.status(200).json({ news: news }) | ||
} catch (err) { | ||
res.status(500).json({ error: 'Failed to fetch news' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FormattedDate } from '@components/FormattedDateTime' | ||
import { forwardRef, HTMLAttributes } from 'react' | ||
import { BaseLink } from '@core/Link' | ||
import { Typography } from '@core/Typography' | ||
import Image, { Ratios } from '../../../pageComponents/shared/SanityImage' | ||
import envisTwMerge from '../../../twMerge' | ||
import { NewsRoomNewsItem } from '../../../types/algoliaIndexPage' | ||
import { SanityImageObject } from '@sanity/image-url/lib/types/types' | ||
import Blocks from '../../../pageComponents/shared/portableText/Blocks' | ||
|
||
export type NewsHeadlinerProps = { | ||
data: NewsRoomNewsItem | ||
fallbackImage?: SanityImageObject | ||
} & HTMLAttributes<HTMLLIElement> | ||
|
||
const NewsHeadlinerSanity = forwardRef<HTMLLIElement, NewsHeadlinerProps>(function NewsHeadlinerSanity( | ||
{ data, fallbackImage, className = '', ...rest }, | ||
ref, | ||
) { | ||
const { slug, title, ingress, publishDateTime, heroImage, tags, countryTags } = data | ||
|
||
return ( | ||
<section ref={ref} {...rest} className={envisTwMerge('', className)}> | ||
<BaseLink href={slug} className="group flex flex-col gap-2 pb-6"> | ||
{(heroImage?.image?.asset || fallbackImage) && ( | ||
<div className="aspect-video relative max-h-[324px] mb-2"> | ||
<Image | ||
//@ts-ignore: TODO Fix SanityImage to take SanityImageObject | ||
image={heroImage?.image?.asset ? heroImage?.image : fallbackImage} | ||
fill | ||
priority | ||
aspectRatio={Ratios.NINE_TO_SIXTEEN} | ||
sizes="(max-width: 800px) 100vw, 1440px" | ||
className="rounded-xs" | ||
aria-hidden | ||
/> | ||
</div> | ||
)} | ||
{publishDateTime && ( | ||
<FormattedDate datetime={publishDateTime} uppercase className="pt-4 text-2xs font-normal leading-normal" /> | ||
)} | ||
{title && ( | ||
<Typography as="h2" variant="lg" className="pb-6 group-hover:underline"> | ||
{title} | ||
</Typography> | ||
)} | ||
<div className="pb-2 flex gap-3 text-xs divide-x-2 divide-energy-red-100"> | ||
{tags?.map((tag: any, i: number) => { | ||
return ( | ||
<span key={tag.label} className=" text-xs inline-block text-grey-60 pl-3 pr-3 first:pl-0"> | ||
{tag.label} | ||
{i < tags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
{countryTags?.length > 0 && <span className="sr-only">,</span>} | ||
{countryTags?.map((country: any, i: number) => { | ||
return ( | ||
<span key={country.label} className=" inline-block text-grey-60 pl-3 pr-3 first:pl-0"> | ||
{country.label} | ||
{i < countryTags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
</div> | ||
{Array.isArray(ingress) ? ( | ||
<Blocks value={ingress} className="text-sm max-w-prose" /> | ||
) : ( | ||
<Typography variant="body" className="text-sm max-w-prose`"> | ||
{ingress} | ||
</Typography> | ||
)} | ||
</BaseLink> | ||
</section> | ||
) | ||
}) | ||
export default NewsHeadlinerSanity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { FormattedDate } from '@components/FormattedDateTime' | ||
import { forwardRef, HTMLAttributes } from 'react' | ||
import { BaseLink } from '@core/Link' | ||
import { Typography } from '@core/Typography' | ||
import Image, { Ratios } from '../../../pageComponents/shared/SanityImage' | ||
import envisTwMerge from '../../../twMerge' | ||
import { NewsRoomNewsItem } from '../../../types/algoliaIndexPage' | ||
import { SanityImageObject } from '@sanity/image-url/lib/types/types' | ||
|
||
export type NewsListItemProps = { | ||
data: NewsRoomNewsItem | ||
fallbackImage?: SanityImageObject | ||
} & HTMLAttributes<HTMLLIElement> | ||
|
||
/* Not a semantic list even tho name implies it, used as other news pages with sections */ | ||
const NewsItemSanity = forwardRef<HTMLLIElement, NewsListItemProps>(function NewsItemSanity( | ||
{ data, fallbackImage, className = '', ...rest }, | ||
ref, | ||
) { | ||
const { slug, title, publishDateTime, heroImage, thumbnailUrl, tags, countryTags } = data || {} | ||
|
||
return ( | ||
<section ref={ref} className={envisTwMerge('border-b border-grey-30', className)} {...rest}> | ||
<BaseLink href={slug} className="h-full group grid grid-cols-[60%_30%] justify-between gap-4 lg:gap-6"> | ||
<div className="flex flex-col py-6"> | ||
{publishDateTime && ( | ||
<FormattedDate datetime={publishDateTime} uppercase className="text-2xs font-normal leading-normal pb-1" /> | ||
)} | ||
{title && ( | ||
<Typography as="h2" variant="base" className="text-base pb-6 max-w-text text-pretty group-hover:underline"> | ||
{title} | ||
</Typography> | ||
)} | ||
<div className="pb-4 flex gap-3 text-xs divide-x-2 divide-energy-red-100"> | ||
{tags?.map((tag: any, i: number) => { | ||
return ( | ||
<span key={tag?.label} className={`inline-block text-grey-60 pl-3 pr-3 first:pl-0`}> | ||
{tag?.label} | ||
{i < tags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
{countryTags?.length > 0 && <span className="sr-only">,</span>} | ||
{countryTags?.map((country: any, i: number) => { | ||
return ( | ||
<span key={country?.label} className="inline-block text-grey-60 pl-3 pr-3 first:pl-0"> | ||
{country?.label} | ||
{i < countryTags.length - 1 && <span className="sr-only">,</span>} | ||
</span> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
<div className=" relative object-cover"> | ||
{(heroImage?.image?.asset || fallbackImage || thumbnailUrl) && ( | ||
<> | ||
{thumbnailUrl ? ( | ||
<img | ||
className="relative rounded-xs" | ||
src={thumbnailUrl} | ||
alt="" | ||
style={{ objectFit: 'cover' }} | ||
sizes="(max-width: 800px) 100vw, 800px" | ||
role={'presentation'} | ||
/> | ||
) : ( | ||
(heroImage?.image?.asset || fallbackImage) && ( | ||
<Image | ||
//@ts-ignore: TODO Fix SanityImage to take SanityImageObject | ||
image={heroImage?.image?.asset ? heroImage?.image : fallbackImage} | ||
aria-hidden | ||
aspectRatio={Ratios.NINE_TO_SIXTEEN} | ||
sizes="(max-width: 800px) 100vw, 800px" | ||
fill | ||
className="rounded-xs" | ||
/> | ||
) | ||
)} | ||
</> | ||
)} | ||
</div> | ||
</BaseLink> | ||
</section> | ||
) | ||
}) | ||
export default NewsItemSanity |
Oops, something went wrong.