-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1650 from woocommerce/add/1610-paid-ads-previews
Free Listings + Paid Ads: Add the paid ads previews to the boost product listings section
- Loading branch information
Showing
29 changed files
with
1,111 additions
and
12 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
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
94 changes: 94 additions & 0 deletions
94
js/src/components/paid-ads/campaign-preview/campaign-preview.js
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,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 ] ); | ||
|
||
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> | ||
); | ||
} |
Oops, something went wrong.