Skip to content

Commit 79b62c4

Browse files
committed
feat: refactor content-block default styles, apply to YouTubeEmbed.
1 parent 7def34e commit 79b62c4

10 files changed

+44
-37
lines changed

e2e-tests/about-us.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test.describe('About us', () => {
1818
it('should have the correct content', async ({ page }) => {
1919
await page.goto(new URL('/about-us/', base).toString())
2020

21-
expect(await page.getByTitle('YouTube embed')).toHaveAttribute(
21+
expect(await page.getByTitle('About Distribute Aid!')).toHaveAttribute(
2222
'src',
2323
'https://www.youtube.com/embed/msizPweg3kE',
2424
)

src/components/about-us/AboutHero.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { FC } from 'react'
33

44
const AboutHero: FC = () => (
55
<div className="py-8 md:py-20 mx-auto" style={{ maxWidth: 800 }}>
6-
<YouTubeEmbed videoUrl="https://www.youtube.com/embed/msizPweg3kE" />
6+
<YouTubeEmbed
7+
title="About Distribute Aid!"
8+
url="https://www.youtube.com/embed/msizPweg3kE"
9+
/>
710
</div>
811
)
912

src/components/section/ContentBlock.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ type BlocksProps = {
1919

2020
export const Blocks: FC<BlocksProps> = ({ blocks }) => {
2121
const blockElems = blocks.map((block, i) => (
22-
<Block className="mb-8 last:mb-0" key={i} block={block} />
22+
<Block
23+
className="mb-8 last:mb-0 border-l-2 pl-4 border-navy-400"
24+
key={i}
25+
block={block}
26+
/>
2327
))
2428

2529
return <>{blockElems}</>
@@ -53,10 +57,9 @@ export const Block: FC<BlockProps> = ({ block, className }) => {
5357
/>
5458
)
5559
case 'DABlockYoutube':
56-
return <BlockYouTube
57-
block={block as BlockYoutubeType}
58-
className={className}
59-
/>
60+
return (
61+
<BlockYouTube block={block as BlockYoutubeType} className={className} />
62+
)
6063

6164
// wishlist
6265
case 'DABlockTimeline':

src/components/section/blocks/BlockLinksList.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ type BlockTextProps = {
1111
export const BlockLinksList: FC<BlockTextProps> = ({ block, className }) => {
1212
return (
1313
<>
14-
{/* TODO: replace w/ <BlockTitle> once that no longer needs a full Node */}
1514
{block.title && (
1615
<BlockTitle className={className} block={{ text: block.title }} />
1716
)}
18-
<div className={`${className} border-l-2 pl-4 border-navy-400`}>
17+
<div className={`${className}`}>
1918
{/* NOTE: we're intentionally dropping the title so it doesn't get repeated */}
2019
<LinksList list={{ links: block.links }} />
2120
</div>

src/components/section/blocks/BlockText.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type BlockTextProps = {
99

1010
export const BlockText: FC<BlockTextProps> = ({ block, className }) => {
1111
return (
12-
<div className={`${className} border-l-2 pl-4 border-navy-400`}>
12+
<div className={`${className}`}>
1313
<MarkdownContent content={block.text} />
1414
</div>
1515
)

src/components/section/blocks/BlockTitle.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ type BlockTitleProps = {
77
}
88

99
export const BlockTitle: FC<BlockTitleProps> = ({ block, className }) => {
10-
return (
11-
<h2 className={`${className} pl-4 border-l-2 border-navy-600`}>
12-
{block.text}
13-
</h2>
14-
)
10+
return <h2 className={`${className} border-navy-600`}>{block.text}</h2>
1511
}

src/components/section/blocks/BlockUpdatesList.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ type BlockTextProps = {
1212
export const BlockUpdatesList: FC<BlockTextProps> = ({ block, className }) => {
1313
return (
1414
<>
15-
{/* TODO: replace w/ <BlockTitle> once that no longer needs a full Node */}
1615
{block.title && (
1716
<BlockTitle className={className} block={{ text: block.title }} />
1817
)}
19-
<div className={`${className} border-l-2 pl-4 border-navy-400`}>
18+
<div className={`${className}`}>
2019
{/* NOTE: we're intentionally dropping the title so it doesn't get repeated */}
2120
<UpdatesList list={{ visibleCount: 10, updates: block.updates }} />
2221
</div>
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { YouTubeEmbed } from '@components/youtube-embed/YouTubeEmbed'
22
import { FC } from 'react'
33
import { BlockYoutube as BlockYoutubeType } from '../../../types/generic-page.d'
4+
import { BlockTitle } from './BlockTitle'
45

56
type BlockYouTubeProps = {
6-
block: BlockYoutubeType,
7+
block: BlockYoutubeType
78
className?: string | undefined
89
}
910

1011
export const BlockYouTube: FC<BlockYouTubeProps> = ({ block, className }) => {
1112
return (
12-
<div className={className}>
13-
<YouTubeEmbed videoUrl={block.embedUrl} videoTitle={block.title} />
14-
</div>
13+
<>
14+
{block.title && (
15+
<BlockTitle className={className} block={{ text: block.title }} />
16+
)}
17+
<div className={`${className}`}>
18+
{/* NOTE: we're intentionally dropping the title so it doesn't get repeated */}
19+
<YouTubeEmbed url={block.embedUrl} />
20+
</div>
21+
</>
1522
)
1623
}

src/components/youtube-embed/YouTubeEmbed.test.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ describe('<YouTubeEmbed/>', () => {
55
it('renders the video and title', () => {
66
render(
77
<YouTubeEmbed
8-
videoTitle="the title of the video"
9-
videoUrl="https://example.com/video"
8+
title="the title of the video"
9+
url="https://example.com/video"
1010
/>,
1111
)
1212

13-
expect(screen.getByText('the title of the video'))
14-
expect(screen.getByTitle('YouTube embed')).toBeInTheDocument()
13+
expect(screen.getByText('the title of the video')).toBeInTheDocument()
14+
expect(screen.getByTitle('the title of the video')).toBeInTheDocument()
1515
})
1616

1717
it('does not render title when none is given', () => {
18-
render(<YouTubeEmbed videoUrl="https://example.com/video" />)
18+
render(<YouTubeEmbed url="https://example.com/video" />)
1919

20-
expect(screen.getByTitle('YouTube embed')).toBeInTheDocument()
21-
expect(screen.queryByTestId('videoTitle')).not.toBeInTheDocument()
20+
expect(screen.getByTitle('Youtube Video')).toBeInTheDocument()
21+
expect(screen.queryByTestId('YouTubeEmbed-Title')).not.toBeInTheDocument()
2222
})
2323
})

src/components/youtube-embed/YouTubeEmbed.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import { FC, PropsWithChildren } from 'react'
22

33
export const YouTubeEmbed: FC<
44
PropsWithChildren<{
5-
videoUrl: string
6-
videoTitle?: string | undefined
5+
url: string
6+
title?: string | undefined
77
}>
8-
> = ({ videoUrl, videoTitle }) => (
9-
<figure>
8+
> = ({ url, title }) => (
9+
<figure className="first:mt-0 last:mb-0">
1010
<iframe
1111
className="aspect-video w-full"
12-
src={videoUrl}
13-
title="YouTube embed"
12+
src={url}
13+
title={title || 'Youtube Video'}
1414
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
1515
frameBorder="0"
1616
allowFullScreen
1717
/>
18-
{videoTitle && (
19-
<figcaption data-testid="videoTitle" className="text-sm mt-4">
20-
{videoTitle}
18+
{title && (
19+
<figcaption data-testid="YouTubeEmbed-Title" className="text-sm mt-4">
20+
{title}
2121
</figcaption>
2222
)}
2323
</figure>

0 commit comments

Comments
 (0)