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

Added debounce to product select #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cypress/integration/test_filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Test the filters and search for stories in Home page', () => {
const selectProduct = (productName) => {
cy.get(`[data-cy=${productName.split(' ').join('-')}-card]`)
.click({ force: true })
cy.wait(1000)
}

const setDropdown = (dropdown, value) => {
Expand Down
21 changes: 14 additions & 7 deletions src/components/ProductList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react'
import Skeleton from 'react-loading-skeleton'
import { debounce } from 'lodash'
import userStory from '../services/user_story'

const ProductSkeleton = () => {
Expand All @@ -15,20 +16,26 @@ const ProductSkeleton = () => {
)
}

const handleProductCardClick = debounce(
(product, selected, setProduct) => {
if (!selected) {
setProduct(product.Name)
} else {
setProduct('All')
}
},
600,
{ leading: true, trailing: false }
)

const ProductCard = ({ product, selected, setProduct }) => {
return (
<div
className={`flex flex-center flex-align-center product-card ${
selected ? 'product-card-selected' : ''
}`}
data-cy={`${product.Name.split(' ').join('-')}-card`}
onClick={() => {
if (!selected) {
setProduct(product.Name)
} else {
setProduct('All')
}
}}
onClick={() => handleProductCardClick(product, selected, setProduct)}
>
<div className='product-logo'>
<img src={product.logo?.url} alt={`${product.Name} logo`} />
Expand Down