/** * External dependencies */ import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { Spinner } from '@wordpress/components'; import classNames from 'classnames'; import { withDispatch, withSelect } from '@wordpress/data'; /** * WooCommerce dependencies */ import { Card, Pagination, EmptyContent } from '@woocommerce/components'; /** * Internal dependencies */ import './style.scss' import { recordEvent } from 'lib/tracks'; import { Slider } from '../../components'; import { STORE_KEY } from '../../data/constants'; class KnowledgeBase extends Component { constructor( props ) { super( props ); this.state = { page: 1, animate: null, isLoading: true, }; this.onPaginationPageChange = this.onPaginationPageChange.bind( this ); } onPaginationPageChange( newPage ) { const { page } = this.state; let animate; if ( newPage > page ) { animate = 'left'; recordEvent( 'marketing_knowledge_carousel', { direction: 'forward', page: newPage } ); } else { animate = 'right'; recordEvent( 'marketing_knowledge_carousel', { direction: 'back', page: newPage } ); } this.setState( { page: newPage, animate, } ); } onPostClick( post ) { recordEvent( 'marketing_knowledge_article', { title: post.title } ); } /** * Get the 2 posts we need for the current page */ getCurrentSlide() { const { posts } = this.props; const { page } = this.state; const currentPosts = posts.slice( ( page - 1 ) * 2, ( page - 1 ) * 2 + 2 ); const pageClass = classNames( 'woocommerce-marketing-knowledgebase-card__page', { 'page-with-single-post': currentPosts.length === 1, } ); return (
By { post.author_name } { post.author_avatar && ( ) }