| 1 |
import { __, sprintf } from '@wordpress/i18n' |
| 2 |
import React, { useState } from 'react' |
| 3 |
import { Toolbar } from '../common/Toolbar' |
| 4 |
import { Changelog } from './Changelog' |
| 5 |
import type { ImageLinkSchema } from '../../types/schema/WelcomeSchema' |
| 6 |
|
| 7 |
const DATA = window.CODE_SNIPPETS_WELCOME |
| 8 |
|
| 9 |
const HeroImage = () => { |
| 10 |
const [isImageLoaded, setImageLoaded] = useState(false) |
| 11 |
|
| 12 |
return ( |
| 13 |
<div className="code-snippets-hero"> |
| 14 |
<div className="code-snippets-header-wrapper"> |
| 15 |
<h2>{DATA?.hero.name}</h2> |
| 16 |
<a |
| 17 |
className="button button-primary button-large" |
| 18 |
href={DATA?.hero.follow_url} |
| 19 |
target="_blank" |
| 20 |
rel="noopener noreferrer" |
| 21 |
> |
| 22 |
{__('Read more', 'code-snippets')} |
| 23 |
<span className="screen-reader-text"> |
| 24 |
{__('(opens in a new tab)', 'code-snippets')} |
| 25 |
</span> |
| 26 |
</a> |
| 27 |
</div> |
| 28 |
<figure> |
| 29 |
{!isImageLoaded && <div className="code-snippets-loading-spinner" aria-hidden="true"></div>} |
| 30 |
<img |
| 31 |
src={DATA?.hero.image_url} |
| 32 |
alt={__('Latest news image', 'code-snippets')} |
| 33 |
onLoad={() => setImageLoaded(true)} |
| 34 |
/> |
| 35 |
</figure> |
| 36 |
</div> |
| 37 |
) |
| 38 |
} |
| 39 |
|
| 40 |
interface PartnersProps { |
| 41 |
partners: ImageLinkSchema[] |
| 42 |
} |
| 43 |
|
| 44 |
const Partners: React.FC<PartnersProps> = ({ partners }) => |
| 45 |
<> |
| 46 |
<h2>{__('Exclusive deals from our partners', 'code-snippets')}</h2> |
| 47 |
<ul className="code-snippets-partners"> |
| 48 |
{partners.map(({ title, follow_url, image_url }) => |
| 49 |
<li key={title} className="code-snippets-card"> |
| 50 |
<figure> |
| 51 |
<img src={image_url} alt={__('Partner image', 'code-snippets')} /> |
| 52 |
</figure> |
| 53 |
<div className="code-snippets-header-wrapper"> |
| 54 |
<h3>{title}</h3> |
| 55 |
<a |
| 56 |
href={follow_url} |
| 57 |
target="_blank" |
| 58 |
rel="noopener noreferrer" |
| 59 |
aria-label={sprintf( |
| 60 |
/* translators: %s: partner name. */ |
| 61 |
__('Visit %s (opens in a new tab)', 'code-snippets'), |
| 62 |
title |
| 63 |
)} |
| 64 |
> |
| 65 |
{__('Visit', 'code-snippets')} |
| 66 |
</a> |
| 67 |
</div> |
| 68 |
</li>)} |
| 69 |
</ul> |
| 70 |
</> |
| 71 |
|
| 72 |
interface ArticlesProps { |
| 73 |
articles: ImageLinkSchema[] |
| 74 |
} |
| 75 |
|
| 76 |
const Articles: React.FC<ArticlesProps> = ({ articles }) => |
| 77 |
<> |
| 78 |
<h2>{__('Helpful articles', 'code-snippets')}</h2> |
| 79 |
<ul className="code-snippets-articles"> |
| 80 |
{articles.map(({ title, follow_url, image_url, description, category }) => |
| 81 |
<li key={title} className="code-snippets-card"> |
| 82 |
<figure> |
| 83 |
<img src={image_url} alt={__('Feature image', 'code-snippets')} /> |
| 84 |
</figure> |
| 85 |
<div className="code-snippets-header-wrapper"> |
| 86 |
<p className="item-category">{category}</p> |
| 87 |
<h3>{title}</h3> |
| 88 |
<p className="item-description">{description}</p> |
| 89 |
<a href={follow_url} className="button button-secondary" target="_blank" rel="noopener noreferrer"> |
| 90 |
{__('Read more', 'code-snippets')} |
| 91 |
<span className="screen-reader-text"> |
| 92 |
{__('(opens in a new tab)', 'code-snippets')} |
| 93 |
</span> |
| 94 |
</a> |
| 95 |
</div> |
| 96 |
</li>)} |
| 97 |
</ul> |
| 98 |
</> |
| 99 |
|
| 100 |
export const WelcomeMenu = () => |
| 101 |
<> |
| 102 |
<Toolbar /> |
| 103 |
<div className="code-snippets-welcome"> |
| 104 |
<h1>{__('Resources and Updates', 'code-snippets')}</h1> |
| 105 |
|
| 106 |
<hr className="wp-header-end" /> |
| 107 |
|
| 108 |
<div className="code-snippets-updates"> |
| 109 |
<HeroImage /> |
| 110 |
<Changelog /> |
| 111 |
</div> |
| 112 |
|
| 113 |
{DATA?.features && <Articles articles={DATA.features} />} |
| 114 |
{DATA?.partners && <Partners partners={DATA.partners} />} |
| 115 |
</div> |
| 116 |
</> |
| 117 |
|