Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/css/welcome.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'common/theme';
@use 'common/badges';
@use 'common/toolbar';
@use 'common/subnav';
@use 'common/wp-admin';
@use 'common/page-header';

Expand All @@ -9,8 +10,8 @@
}

.code-snippets-updates {
display: flex;
flex-direction: row;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;

> * {
Expand All @@ -22,7 +23,8 @@

.code-snippets-header-wrapper {
display: flex;
flex-flow: row;
flex-flow: row wrap;
gap: 16px;
justify-content: space-between;
align-items: center;
border-block-end: 1px solid var(--cs-color-border-subtle);
Expand All @@ -35,12 +37,9 @@
margin: 0;
}

@media (width <= 960px) {
flex-direction: column;
}
}

.code-snippets-hero {
.code-snippets-news-item {
display: flex;
flex-flow: column;
border: 1px solid var(--cs-color-border-subtle);
Expand Down Expand Up @@ -148,30 +147,24 @@
}
}

.code-snippets-changelog-entries {
.code-snippets-changelog-version {
font-size: 0.9rem;
line-height: 1.5;
overflow-y: scroll;
max-block-size: 500px;
color: var(--cs-color-text);
padding-inline-end: 1em;

h3 {
h2 {
font-size: 16px;
display: flex;

&:not(:first-of-type) {
margin-block-start: 100px;
}

span {
font-size: 14px;
font-weight: normal;
margin-inline-start: auto;
}
}

h4 {
h3 {
font-size: 14px;
margin: 1em 0;
}
Expand Down Expand Up @@ -217,6 +210,11 @@
}
}

.code-snippets-changelog-card {
padding: 32px;
margin-block-end: 32px;
}

.code-snippets-loading-spinner {
block-size: 0;
inline-size: 0;
Expand Down
57 changes: 29 additions & 28 deletions src/js/components/WelcomeMenu/Changelog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment } from 'react'
import React from 'react'
import { __, sprintf } from '@wordpress/i18n'
import { CHANGELOG_SECTIONS } from '../../types/schema/WelcomeSchema'
import type { ChangelogSectionTitle } from '../../types/schema/WelcomeSchema'
Expand Down Expand Up @@ -37,10 +37,10 @@ interface ChangelogSectionProps {

const ChangelogSection: React.FC<ChangelogSectionProps> = ({ section, entries }) =>
<>
<h4>
<h3>
<span className={`dashicons dashicons-${CHANGELOG_ICONS[section]}`} aria-hidden="true"></span>
{CHANGELOG_LABELS[section]}
</h4>
</h3>
<ul>
{Object.entries(entries).map(([pluginType, changes]) =>
changes.map(change =>
Expand All @@ -56,34 +56,35 @@ const ChangelogSection: React.FC<ChangelogSectionProps> = ({ section, entries })

export const Changelog = () =>
<div id="latest-changes" className="code-snippets-changelog">
<div className="code-snippets-header-wrapper">
<h2>{__('Latest changes', 'code-snippets')}</h2>
<a
href="https://wordpress.org/plugins/code-snippets/changelog"
className="button button-primary button-large"
target="_blank" rel="noreferrer"
{CHANGELOG_DATA?.map(({ version, date, entries }) =>
<section
key={version}
className="code-snippets-changelog-version"
aria-labelledby={`changelog-version-${version}`}
>
{__('View changelog', 'code-snippets')}
<span className="screen-reader-text">
{__('(opens in a new tab)', 'code-snippets')}
</span>
</a>
</div>
<div className="code-snippets-changelog-entries">
{CHANGELOG_DATA?.map(({ version, date, entries }) =>
<Fragment key={version}>
<h3>
{sprintf(
/* translators: %s: version number. */
__('Version %s', 'code-snippets'),
version
)}
<span>{date}</span>
</h3>
<h2 id={`changelog-version-${version}`}>
{sprintf(
/* translators: %s: version number. */
__('Version %s', 'code-snippets'),
version
)}
<span>{date}</span>
</h2>
<div className="code-snippets-card code-snippets-changelog-card">
{CHANGELOG_SECTIONS.map(section =>
entries[section]
? <ChangelogSection key={section} section={section} entries={entries[section]} />
: null)}
</Fragment>)}
</div>
</div>
</section>)}
<a
href="https://wordpress.org/plugins/code-snippets/changelog"
className="button button-primary button-large"
target="_blank" rel="noopener noreferrer"
>
{__('View changelog', 'code-snippets')}
<span className="screen-reader-text">
{__('(opens in a new tab)', 'code-snippets')}
</span>
</a>
</div>
110 changes: 77 additions & 33 deletions src/js/components/WelcomeMenu/WelcomeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,64 @@ import { __, sprintf } from '@wordpress/i18n'
import React, { useEffect, useState } from 'react'
import { revealLocationHash } from '../../utils/urls'
import { ScreenMetaSlot } from '../common/ScreenMetaSlot'
import { SubnavTabs, getTabFromQuery } from '../common/SubnavTabs'
import { Toolbar } from '../common/Toolbar'
import { Changelog } from './Changelog'
import type { ImageLinkSchema } from '../../types/schema/WelcomeSchema'
import type { SubnavTab } from '../common/SubnavTabs'

const DATA = window.CODE_SNIPPETS_WELCOME
const TAB_QUERY_PARAM = 'tab'

const HeroImage = () => {
const [isImageLoaded, setImageLoaded] = useState(false)
type WelcomeTabName = 'whats-new' | 'changelog' | 'resources'

const TABS: SubnavTab<WelcomeTabName>[] = [
{
name: 'whats-new',
label: __("What's new", 'code-snippets')
},
{
name: 'changelog',
label: __('Changelog', 'code-snippets')
},
{
name: 'resources',
label: __('Resources', 'code-snippets')
}
]

const WhatsNew = () => {
const [loadedImages, setLoadedImages] = useState<string[]>([])

return (
<div className="code-snippets-hero">
<div className="code-snippets-header-wrapper">
<h2>{DATA?.hero.name}</h2>
<a
className="button button-primary button-large"
href={DATA?.hero.follow_url}
target="_blank"
rel="noopener noreferrer"
>
{__('Read more', 'code-snippets')}
<span className="screen-reader-text">
{__('(opens in a new tab)', 'code-snippets')}
</span>
</a>
</div>
<figure>
{!isImageLoaded && <div className="code-snippets-loading-spinner" aria-hidden="true"></div>}
<img
src={DATA?.hero.image_url}
alt={__('Latest news image', 'code-snippets')}
onLoad={() => setImageLoaded(true)}
/>
</figure>
</div>
<>
{DATA?.hero.map(({ name, follow_url, image_url }) => (
<div key={follow_url} className="code-snippets-card code-snippets-news-item">
<div className="code-snippets-header-wrapper">
<h2>{name}</h2>
<a
className="button button-primary button-large"
href={follow_url}
target="_blank"
rel="noopener noreferrer"
>
{__('Read more', 'code-snippets')}
<span className="screen-reader-text">
{__('(opens in a new tab)', 'code-snippets')}
</span>
</a>
</div>
<figure>
{!loadedImages.includes(image_url) && <div className="code-snippets-loading-spinner" aria-hidden="true"></div>}
<img
src={image_url}
alt={__('Latest news image', 'code-snippets')}
onLoad={() => setLoadedImages(images => [...images, image_url])}
/>
</figure>
</div>
))}
</>
)
}

Expand Down Expand Up @@ -100,29 +124,49 @@ const Articles: React.FC<ArticlesProps> = ({ articles }) =>
</>

export const WelcomeMenu = () => {
const [currentTab, setCurrentTab] = useState(() => getTabFromQuery(TABS, TAB_QUERY_PARAM))

useEffect(revealLocationHash, [])

return (
<>
<Toolbar />

<SubnavTabs
ariaLabel={__('Welcome sections', 'code-snippets')}
tabs={TABS}
currentTab={currentTab}
setCurrentTab={setCurrentTab}
queryParamName={TAB_QUERY_PARAM}
/>

<ScreenMetaSlot />

<div className="snippets-page-header">
<h1>{__('Resources and Updates', 'code-snippets')}</h1>
<h1>{currentTab.label}</h1>
</div>

<hr className="wp-header-end" />

<div className="code-snippets-welcome">
{'whats-new' === currentTab.name && (
<div className="code-snippets-welcome-panel code-snippets-updates whats-new-panel">
<WhatsNew />
</div>
)}

<div className="code-snippets-updates">
<HeroImage />
<Changelog />
</div>
{'changelog' === currentTab.name && (
<div className="code-snippets-welcome-panel changelog-panel">
<Changelog />
</div>
)}

{DATA?.features && <Articles articles={DATA.features} />}
{DATA?.partners && <Partners partners={DATA.partners} />}
{'resources' === currentTab.name && (
<div className="code-snippets-welcome-panel resources-panel">
{DATA?.features && <Articles articles={DATA.features} />}
{DATA?.partners && <Partners partners={DATA.partners} />}
</div>
)}
</div>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/common/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const UpperNavItems = () =>
<UpperNavItem
name="welcome"
url={window.CODE_SNIPPETS.urls.welcome}
label={__("What's New", 'code-snippets')}
label={__('New', 'code-snippets')}
/>)}

<UpperNavItem
Expand Down
2 changes: 1 addition & 1 deletion src/js/types/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ declare global {
name: string
follow_url: string
image_url: string
}
}[]
changelog: ChangelogSchema[]
features: ImageLinkSchema[]
partners: ImageLinkSchema[]
Expand Down
24 changes: 21 additions & 3 deletions src/php/Admin/Contextual_Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,28 @@ private function load_welcome_help() {

$this->add_help_tab(
'whats-new',
__( "What's New", 'code-snippets' ),
__( "What's new", 'code-snippets' ),
[
__( 'The Latest Changes section summarizes new features, improvements, bug fixes, security updates and other changes in recent releases.', 'code-snippets' ),
__( 'Select View Changelog to read the complete release notes.', 'code-snippets' ),
__( "The What's new tab highlights the latest Code Snippets news and featured updates.", 'code-snippets' ),
__( 'Select Read more to open the full article in a new tab.', 'code-snippets' ),
]
);

$this->add_help_tab(
'changelog',
__( 'Changelog', 'code-snippets' ),
[
__( 'The Changelog tab summarizes new features, improvements, bug fixes, security updates and other changes in recent releases.', 'code-snippets' ),
__( 'Select View changelog to read the complete release notes.', 'code-snippets' ),
]
);

$this->add_help_tab(
'resources',
__( 'Resources', 'code-snippets' ),
[
__( 'The Resources tab includes helpful articles and exclusive deals from Code Snippets partners.', 'code-snippets' ),
__( 'Select Read more for an article or Visit for a partner offer. Links open in a new tab.', 'code-snippets' ),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/php/Admin/Menus/Welcome_Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function enqueue_assets() {
'CODE_SNIPPETS_WELCOME',
[
'banner' => $this->client->get_banner(),
'hero' => $this->client->get_hero_item(),
'hero' => $this->client->get_hero_items(),
'changelog' => $this->client->get_changelog(),
'features' => $this->client->get_features(),
'partners' => $this->client->get_partners(),
Expand Down
Loading
Loading