-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a block for adoptium news on the main page (#2886)
* [issue-2862] Add a block for Adoptium news on the main page * Change for only 1 news * Create Slice to avoid pb with tests (like the banner) * Change color / Add test / Date is not mandatory * issues-2877: promotion of Adoptium Summit CFP * simplify test * Fix link name and comments * Rename file
- Loading branch information
1 parent
7206b3c
commit f01e08a
Showing
5 changed files
with
76 additions
and
0 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
12 changes: 12 additions & 0 deletions
12
src/components/AdoptiumNews/__tests__/adoptiumNews.test.tsx
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,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest' | ||
import AdoptiumNews from '..'; | ||
|
||
describe('AdoptiumNews component', () => { | ||
it('renders correctly', () => { | ||
const { container } = render(<AdoptiumNews />); | ||
// expect container to either be null or contain a div with the class of alert | ||
expect(container).toBeNull || expect(container.querySelector('div.text-pink')).toBeTruthy(); | ||
}); | ||
}); |
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,53 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
import { Trans } from 'gatsby-plugin-react-i18next'; | ||
import LinkText from '../LinkText' | ||
|
||
const AdoptiumNews = () => { | ||
|
||
// NOTES: | ||
// - You can add a <callToActionLink /> tag to create a link in the body | ||
// - Dates must be with the format: "YYYY-MM-dd" | ||
|
||
const adoptiumNews = { | ||
title: "Adoptium Summit 2024", | ||
body: "Be a part of the first-ever Adoptium Summit on September, 10.<br/>Connect with peers to exchange knowledge on Temurin, AQAvit and other Adoptium's projects.<br/><callToActionLink>Register here</callToActionLink>", | ||
callToActionLink: 'https://www.eclipse.org/events/2024/adoptium-summit/', | ||
date: new Date('2024-09-10'), | ||
startDisplayAt: new Date('2024-05-15'), | ||
stopDisplayAfter: new Date('2024-06-30'), | ||
} | ||
|
||
const now = Date.now(); | ||
if(!adoptiumNews || now < adoptiumNews.startDisplayAt.getTime() || now > adoptiumNews.stopDisplayAfter.getTime()) return; | ||
|
||
return ( | ||
<div className='p-3 mt-4 mb-4 bg-light rounded-3 text-start'> | ||
<div className='container py-5'> | ||
<h2 className='text-pink'>{adoptiumNews.title}</h2> | ||
<div> | ||
{adoptiumNews.date && <p className='m-0 fw-bold'>{moment(adoptiumNews.date).format('D MMMM YYYY')}</p>} | ||
<p className='text-muted lh-sm'> | ||
<Trans | ||
defaults={adoptiumNews.body} | ||
components={{ | ||
callToActionLink: <LinkText href={adoptiumNews.callToActionLink||''} /> | ||
}} | ||
/> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdoptiumNews; | ||
|
||
export interface AdoptiumNewsItem { | ||
title: string; | ||
body: string; | ||
date?: Date; | ||
callToActionLink?: string; | ||
startDisplayAt: Date; | ||
stopDisplayAfter: Date; | ||
} |
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