Skip to content

Commit

Permalink
Merge branch 'staging', remote-tracking branch 'origin' into bose/2088
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Feb 9, 2024
3 parents f391bda + 423b34e + 0ba6db2 commit 370017e
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 47 deletions.
1 change: 1 addition & 0 deletions sanityv3/schemas/objects/videoFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
name: 'thumbnail',
type: 'imageWithAlt',
title: 'Thumbnail',
description: 'Use the alt text below to describe the video content (for screenreaders).',
initialValue: {
isDecorative: true,
},
Expand Down
3 changes: 2 additions & 1 deletion search/IndexSanityContent/events/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language, Page } from '../../common'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

const query = /* groq */ `*[_type match "route_" + $lang + "*" && content->_type == "event" && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"content": content->{
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"eventDate": eventDate.date,
"eventDescription": pt::text(content),
Expand Down
9 changes: 5 additions & 4 deletions search/IndexSanityContent/magazine/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

export enum HeroTypes {
DEFAULT = 'default',
Expand All @@ -23,22 +24,22 @@ const publishDateTimeQuery = /* groq */ `
export const query = /* groq */ `*[_type == "magazine" && _lang == $lang && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"type": _type,
"ingress": pt::text(ingress),
"textBlocks": content[_type == "textBlock"]{
"_key": _key,
"title": select(
isBigText == true =>
pt::text(bigTitle),
pt::text(title)
${plainTextExcludingStrikeThrough('bigTitle')},
${plainTextExcludingStrikeThrough('title')}
),
"ingress": pt::text(ingress),
"text": pt::text(text) // TODO: Do this manually to cover all cases
},
"accordions": content[_type == "accordion"] {
"_key": _key,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"accordionItems":accordion[]{
"id": _key,
Expand Down
9 changes: 5 additions & 4 deletions search/IndexSanityContent/topic/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

export const query = /* groq */ `*[_type match "route_" + $lang + "*" && content->_type == "page" && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"title": pt::text(content->title),
"title": ${plainTextExcludingStrikeThrough('content->title')},
"type": content->_type,
"textBlocks": content->content[_type == "textBlock"]{
"_key": _key,
"title": select(
isBigText == true =>
pt::text(bigTitle),
pt::text(title)
${plainTextExcludingStrikeThrough('bigTitle')},
${plainTextExcludingStrikeThrough('title')}
),
"ingress": pt::text(ingress),
"text": pt::text(text) // TODO: Do this manually to cover all cases
},
"accordions": content->content[_type == "accordion"] {
"_key": _key,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"accordionItems":accordion[]{
"id": _key,
Expand Down
7 changes: 7 additions & 0 deletions search/common/queryHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const plainTextExcludingStrikeThrough = (blockTextField: string) => {
return /* groq */ `
pt::text(${blockTextField}[]{
...,
children[!("s" in marks)]
})`
}
9 changes: 8 additions & 1 deletion web/components/src/HLSPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useVideoAnalytics from '../../../lib/hooks/useVideoAnalytics'
type HLSProps = Omit<HTMLProps<HTMLVideoElement>, 'src'> & {
src: string
playButton?: boolean
videoDescription?: string
}

const Wrapper = styled.div<{ $showSpinner: boolean }>`
Expand Down Expand Up @@ -69,6 +70,8 @@ export const HLSPlayer: React.FC<HLSProps> = ({
controls = false,
playButton = false,
autoPlay = false,
muted = false,
videoDescription,
...props
}) => {
const videoRef = useRef<HTMLVideoElement>(null)
Expand Down Expand Up @@ -157,7 +160,11 @@ export const HLSPlayer: React.FC<HLSProps> = ({
}, [playButton])

return (
<Wrapper $showSpinner={showSpinner}>
<Wrapper
$showSpinner={showSpinner}
role={muted ? 'img' : undefined}
aria-label={muted ? videoDescription : undefined}
>
<video
playsInline
ref={videoRef}
Expand Down
18 changes: 16 additions & 2 deletions web/lib/algolia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import algoliasearch, { AlgoliaSearchOptions } from 'algoliasearch/lite'
import { algolia } from './config'
import { createInMemoryCache } from '@algolia/cache-in-memory'
import { createFallbackableCache } from '@algolia/cache-common'
import { createBrowserLocalStorageCache } from '@algolia/cache-browser-local-storage'

export const searchClient = (options: AlgoliaSearchOptions | undefined) =>
algoliasearch(algolia.applicationId, algolia.searchApiKey, options)
export const searchClient = (options?: AlgoliaSearchOptions) =>
algoliasearch(algolia.applicationId, algolia.searchApiKey, {
...options,
responsesCache: createFallbackableCache({
caches: [
createBrowserLocalStorageCache({
key: `algolia-responses-${algolia.applicationId}`,
timeToLive: 600, // 10 minutes cache
}),
createInMemoryCache(),
],
}),
})
8 changes: 2 additions & 6 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,15 @@ _type == "keyNumbers" =>{
_type == "figure"=>{
"type": _type,
"id": _key,
// For these images, we don't want crop and hotspot
// because we don't know the aspect ratio
"figure": figure{
_type,
"image": {
"asset": image.asset,
"alt": image.alt,
},
image,
attribution,
caption
},
"designOptions": {
"background": coalesce(background.title, 'White'),
"aspectRatio": coalesce(aspectRatio, '16:9'),
},
},
_type == "textWithIconArray"=>{
Expand Down
3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"type-check": "tsc --project tsconfig.json --pretty --noEmit"
},
"dependencies": {
"@algolia/cache-browser-local-storage": "^4.22.1",
"@algolia/cache-common": "^4.22.1",
"@algolia/cache-in-memory": "^4.22.1",
"@chakra-ui/react": "^2.4.2",
"@chakra-ui/skip-nav": "^2.0.12",
"@emotion/react": "^11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Input = styled.input`

export type SearchBoxProps = UseSearchBoxProps

const DEBOUNCE_TIME = 300
const DEBOUNCE_TIME = 800
let timerId: any = undefined

const queryHook: UseSearchBoxProps['queryHook'] = (query, search) => {
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const StyledPagination = styled(Pagination)`
margin-top: var(--space-xLarge);
justify-content: center;
`
const searchClient = client(undefined)
const searchClient = client()
const queriedSearchClient: SearchClient = {
...searchClient,
search(requests: any) {
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSearchBox, UseSearchBoxProps } from 'react-instantsearch'
import ControlledSearchBox from './ControlledSearchBox'
import { SearchContext } from './SearchContext'

const DEBOUNCE_TIME = 300
const DEBOUNCE_TIME = 800

export type SearchBoxProps = ComponentProps<'div'> & UseSearchBoxProps

Expand Down
9 changes: 1 addition & 8 deletions web/pageComponents/shared/Hero/FiftyFiftyHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,7 @@ export const FiftyFiftyHero = ({ title, ingress, link, background, figure, isBig
<StyledHero background={background}>
<StyledMedia>
{figure && (
<Image
maxWidth={4096}
sizes="(min-width: 760px) 50vw, 100vw"
image={figure.image}
fill
style={{ objectFit: 'cover' }}
priority
/>
<Image maxWidth={4096} sizes="(min-width: 760px) 50vw, 100vw" image={figure.image} fill priority />
)}
</StyledMedia>
<StyledContent>
Expand Down
10 changes: 9 additions & 1 deletion web/pageComponents/shared/Hero/LoopingVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ export const LoopingVideo = ({ video }: { video: LoopingVideoData }) => {
return (
<Container $aspectRatio={ratio}>
<StyledFigure>
<StyledHLSPlayer loop muted autoPlay title={title} poster={thumbnailURL.src} src={url} />
<StyledHLSPlayer
loop
muted
autoPlay
title={title}
poster={thumbnailURL.src}
src={url}
videoDescription={thumbnail.alt}
/>
</StyledFigure>
</Container>
)
Expand Down
14 changes: 3 additions & 11 deletions web/pageComponents/shared/SanityImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ export enum Ratios {
const DEFAULT_SIZES = '(max-width: 800px) 100vw, 800px'
const DEFAULT_MAX_WIDTH = 1440

const Image = ({
image,
aspectRatio,
sizes = DEFAULT_SIZES,
maxWidth = DEFAULT_MAX_WIDTH,
fill,
style,
...rest
}: Props) => {
const Image = ({ image, aspectRatio, sizes = DEFAULT_SIZES, maxWidth = DEFAULT_MAX_WIDTH, fill, ...rest }: Props) => {
const imageProps = useSanityLoader(image, maxWidth, aspectRatio)
if (!image?.asset) return <></>
const { width, height, src } = imageProps
Expand All @@ -41,14 +33,14 @@ const Image = ({
// Layout fill
props = {
fill,
style: { ...style, objectFit: 'cover' },
style: { objectFit: 'cover' },
}
} else {
// Layout responsive
props = {
width,
height,
style: { ...style, display: 'flex', width: '100%', height: 'auto' },
style: { display: 'flex', width: '100%', height: 'auto' },
}
}

Expand Down
16 changes: 10 additions & 6 deletions web/pageComponents/topicPages/Figure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FigureData } from '../../types/types'
import styled from 'styled-components'
import { BackgroundContainer, FigureCaption } from '@components'
import { StyledTextBlockWrapper } from './TextBlock'
import Image from '../shared/SanityImage'
import Image, { Ratios } from '../shared/SanityImage'

type TeaserProps = {
data: FigureData
Expand Down Expand Up @@ -35,15 +35,19 @@ const FullWidthImage = ({ data, anchor }: TeaserProps) => {
if (!figure?.image) return null

const { image, caption, attribution } = figure
const { aspectRatio } = designOptions
// If we add more ratios, create a switch statement for the sanity ratios, for now we only have 9:16
const sizes = '(min-width: 2060px) 920px, (min-width: 440px) calc(34.56vw + 215px), calc(76.67vw + 38px)'

return (
<StyledFigureWrapper background={designOptions?.background} id={anchor}>
<StyledFigure>
<Image
image={image}
maxWidth={920}
sizes="(min-width: 2060px) 920px, (min-width: 440px) calc(34.56vw + 215px), calc(76.67vw + 38px)"
/>
{aspectRatio !== 'original' ? (
<Image image={image} aspectRatio={Ratios.NINE_TO_SIXTEEN} maxWidth={920} sizes={sizes} />
) : (
<Image image={image} maxWidth={920} sizes={sizes} />
)}

{(caption || attribution) && (
<FigureCaption>
{caption && <FigureCaption.Caption>{caption}</FigureCaption.Caption>}
Expand Down
25 changes: 25 additions & 0 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export type DesignOptions = {
background?: BackgroundColours
imagePosition?: TeaserImagePosition
imageSize?: TeaserImageSize
aspectRatio?: FigureRatio
}

export type TextBlockData = {
Expand Down Expand Up @@ -376,6 +377,8 @@ export type FullWidthVideoData = {

export type FullWidthVideoRatio = 'fullScreen' | 'narrow' | '2:1'

export type FigureRatio = 'original' | '9:16'

export type FigureData = {
type: string
id: string
Expand Down

0 comments on commit 370017e

Please sign in to comment.