Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free Listings + Paid Ads: Add the paid ads previews to the boost product listings section #1650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8735780
Add new images for the mockups of ad previews
eason9487 Aug 24, 2022
1bde4a9
Add the container for ad previews
eason9487 Aug 24, 2022
7e1d5a5
Implement shared components for the mockups of ad previews
eason9487 Aug 24, 2022
ca99756
Implement the Google Shopping mockup of ad previews
eason9487 Aug 24, 2022
88cfb40
Implement the YouTube mockup of ad previews
eason9487 Aug 24, 2022
87ce3bc
Implement the Google Search mockup of ad previews
eason9487 Aug 24, 2022
ced245d
Implement the Google Map mockup of ad previews
eason9487 Aug 24, 2022
1aa32c6
Implement the Google Display Network mockup of ad previews
eason9487 Aug 24, 2022
3b73e32
Implement the Gmail mockup of ad previews
eason9487 Aug 24, 2022
f3cc043
Move useCountdown.js to hooks directory and change the `handle` param…
eason9487 Aug 24, 2022
05779b9
Add ad previews to the paid ads features section
eason9487 Aug 24, 2022
3279a21
Rebalance the bundlewatch's max size of index.css to 120% of the new …
eason9487 Aug 24, 2022
6fe6ba7
Update the sample product image file to remove the white border from …
eason9487 Aug 25, 2022
8e72981
Fix a typo in the JSDoc of js/src/components/paid-ads/campaign-previe…
eason9487 Aug 30, 2022
656aeb9
Fix the broken layout of PaidAdsFeaturesSection for the smaller viewp…
eason9487 Aug 30, 2022
c6908de
Merge thinnest, thinner, and thicker props as a single stroke prop fo…
eason9487 Aug 30, 2022
631e8fe
Merge smaller and larger props as a single size prop for ScaledText.
eason9487 Aug 30, 2022
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'stylelint',
'@wordpress/stylelint-config',
'@pmmmwh/react-refresh-webpack-plugin',
'react-transition-group',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Just curiosity. Not an issue. Why is needed to add this dependency here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR uses the same react-transition-group dependency as the one @woocommerce/components depends on, so react-transition-group is not listed in this repo's package.json file. Therefore, this change is to let eslint know it's one of the core modules and to prevent from the eslint error import/no-extraneous-dependencies.

],
'import/resolver': { webpack: webpackResolver },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Notice, Flex } from '@wordpress/components';
*/
import { useAppDispatch } from '.~/data';
import useIsMounted from '.~/hooks/useIsMounted';
import useCountdown from './useCountdown';
import useCountdown from '.~/hooks/useCountdown';
import Section from '.~/wcdl/section';
import Subsection from '.~/wcdl/subsection';
import AppButton from '.~/components/app-button';
Expand Down
94 changes: 94 additions & 0 deletions js/src/components/paid-ads/campaign-preview/campaign-preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* External dependencies
*/
import { _x } from '@wordpress/i18n';
import { useState, useCallback, useEffect } from '@wordpress/element';
import { CSSTransition, TransitionGroup } from 'react-transition-group';

/**
* Internal dependencies
*/
import useCountdown from '.~/hooks/useCountdown';
import MockupShopping from './mockup-shopping';
import MockupYouTube from './mockup-youtube';
import MockupSearch from './mockup-search';
import MockupGmail from './mockup-gmail';
import MockupDisplay from './mockup-display';
import MockupMap from './mockup-map';
import productSampleImageURL from './images/product-sample-image.jpg';
import shopSampleLogoURL from './images/shop-sample-logo.png';
import './campaign-preview.scss';

/**
* @typedef { import("./index.js").AdPreviewData } AdPreviewData
*/

/**
* @type {AdPreviewData}
*/
const fallbackProduct = {
title: _x(
'White tee',
'A sample product title for demonstrating the paid ads shown on Google services.',
'google-listings-and-ads'
),
price: _x(
'$10.00',
'A sample product price for demonstrating the paid ads shown on Google services.',
'google-listings-and-ads'
),
shopName: _x(
`Colleen's Tee Store`,
'A sample name of an online shop for demonstrating the paid ads shown on Google services.',
'google-listings-and-ads'
),
coverUrl: productSampleImageURL,
shopLogoUrl: shopSampleLogoURL,
shopUrl: 'colleensteestore.com',
};

const mockups = [
MockupShopping,
MockupYouTube,
MockupSearch,
MockupMap,
MockupDisplay,
MockupGmail,
];

export default function CampaignPreview() {
const [ index, setIndex ] = useState( 0 );
const { second, callCount, startCountdown } = useCountdown();

// TODO: Fetch required data from API.
const product = fallbackProduct;

const moveBy = useCallback( ( step ) => {
setIndex( ( currentIndex ) => {
return ( currentIndex + step + mockups.length ) % mockups.length;
} );
}, [] );

useEffect( () => {
if ( second === 0 ) {
if ( callCount > 0 ) {
moveBy( 1 );
}
startCountdown( 5 );
}
}, [ second, callCount, startCountdown, moveBy ] );
Comment on lines +61 to +79
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 This maybe can be wrapped in some kind of useTimingIndex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping this to another custom hook sometimes also increases the complexity. In this case, the CampaignPreview component doesn't have much code, therefore, I think it ok to stay with the current implementation.


const Mockup = mockups[ index ];

return (
<TransitionGroup className="gla-campaign-preview">
<CSSTransition
key={ index }
classNames="gla-campaign-preview__transition-blur"
timeout={ 500 }
>
<Mockup product={ product } />
</CSSTransition>
</TransitionGroup>
);
}
Loading