Skip to content

Commit c2d7187

Browse files
Merge pull request #75 from SundeepChand/home-ui-update
Home UI update for search filters
2 parents e02bf71 + 8f25eb3 commit c2d7187

File tree

12 files changed

+200
-69
lines changed

12 files changed

+200
-69
lines changed

cypress/integration/test_filters.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ describe('Test the filters and search for stories in Home page', () => {
77
category: Cypress.env('testCategory')
88
}
99

10+
const selectProduct = (productName) => {
11+
cy.get(`[data-cy=${productName.split(' ').join('-')}-card]`)
12+
.click({ force: true })
13+
}
14+
1015
const setDropdown = (dropdown, value) => {
1116
cy.get('[data-cy=search-input-div]')
1217
.get(`[data-cy=${dropdown}-dropdown]`)
@@ -32,13 +37,15 @@ describe('Test the filters and search for stories in Home page', () => {
3237
})
3338

3439
it('Filters stories based on product', () => {
35-
setDropdown('product', 'EOS User Story')
40+
selectProduct('EOS User Story')
3641

3742
cy.contains('No stories')
3843

39-
setDropdown('product', testStory.product)
44+
selectProduct(testStory.product)
4045

4146
cy.contains(testStory.title)
47+
48+
selectProduct(testStory.product)
4249
})
4350

4451
it('Filters stories based on category', () => {

src/assets/scss/components/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
@import 'footer';
2222
@import 'alerts';
2323
@import 'search';
24+
@import 'productList.scss';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.product-list-container {
2+
text-align: center;
3+
4+
.product-list {
5+
margin-bottom: 10px;
6+
min-height: 160px;
7+
width: 100%;
8+
}
9+
}
10+
11+
.product-card {
12+
border-radius: 5px;
13+
box-shadow: 0px 2px 15px $shadow-color;
14+
margin: 8px 15px;
15+
min-width: 240px;
16+
padding: 10px;
17+
text-transform: uppercase;
18+
transition: 0.2s;
19+
width: 28%;
20+
21+
.circle-container {
22+
width: 100%;
23+
24+
.circle {
25+
border: 1px solid $primary;
26+
border-radius: 50%;
27+
height: 10px;
28+
margin: auto;
29+
margin-top: 10px;
30+
width: 10px;
31+
}
32+
}
33+
34+
.product-logo {
35+
min-height: 80px;
36+
width: 260px;
37+
38+
img {
39+
width: 260px;
40+
}
41+
}
42+
43+
&-selected {
44+
background-color: $primary;
45+
color: $eos-white;
46+
transform: scale(1.03);
47+
48+
.circle {
49+
background-color: $eos-white;
50+
}
51+
}
52+
53+
&:hover {
54+
cursor: pointer;
55+
transform: scale(1.03);
56+
}
57+
}

src/assets/scss/components/search.scss

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
.search-controls {
2+
.btn-search {
3+
padding: 4px 14px;
4+
5+
.eos-icons {
6+
margin: 0px;
7+
}
8+
}
9+
}
10+
111
.search-input {
2-
border: 0;
312
border-bottom: 2px solid $dark-color;
4-
border-radius: 0;
5-
justify-content: space-between;
6-
outline: none;
7-
padding: 0px 10px;
8-
padding-left: 0px;
913
position: relative;
1014

1115
.dropdown-container {
@@ -29,10 +33,6 @@
2933
}
3034
}
3135

32-
.search {
33-
margin: 0.5rem;
34-
}
35-
3636
.user-suggest-dropdown {
3737
background-color: $eos-white;
3838
border-radius: 10px 0px 10px 10px;

src/assets/scss/pages/home.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $subheader-font-size: 18px;
44
.product-introduction {
55
display: flex;
66
font-family: $font-family-spartan;
7-
margin: 88px 0px;
7+
margin: 32px 0px;
88

99
.subheader {
1010
font-size: $subheader-font-size;

src/components/Pagination.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react'
22

33
const Pagination = (props) => {
4-
const { getPage, storyCount, status, product } = props
4+
const { getPage, storyCount, status, productQuery } = props
55

66
const [currNumber, setCurrNumber] = useState(1)
77

@@ -13,7 +13,7 @@ const Pagination = (props) => {
1313
getPage(1)
1414
}
1515
resetPage()
16-
}, [status, product, getPage])
16+
}, [status, productQuery, getPage])
1717

1818
useEffect(() => {
1919
if (storyCount) {

src/components/ProductList.jsx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, { useState, useEffect } from 'react'
2+
import Skeleton from 'react-loading-skeleton'
3+
import userStory from '../services/user_story'
4+
5+
const ProductSkeleton = () => {
6+
return (
7+
<div className='flex flex-row flex-center product-card'>
8+
<div className='product-logo'>
9+
<Skeleton height={80} />
10+
</div>
11+
<div className='circle-container'>
12+
<div className='circle'></div>
13+
</div>
14+
</div>
15+
)
16+
}
17+
18+
const ProductCard = ({ product, selected, setProduct }) => {
19+
return (
20+
<div
21+
className={`flex flex-center flex-align-center product-card ${
22+
selected ? 'product-card-selected' : ''
23+
}`}
24+
data-cy={`${product.Name.split(' ').join('-')}-card`}
25+
onClick={() => {
26+
if (!selected) {
27+
setProduct(product.Name)
28+
} else {
29+
setProduct('All')
30+
}
31+
}}
32+
>
33+
<div className='product-logo'>
34+
<img src={product.logo?.url} alt={`${product.Name} logo`} />
35+
</div>
36+
<div className='circle-container'>
37+
<div className='circle'></div>
38+
</div>
39+
</div>
40+
)
41+
}
42+
43+
const ProductList = ({ setProductQuery }) => {
44+
const [productCount, setProductCount] = useState(3)
45+
46+
const [product, setProduct] = useState('All')
47+
48+
const [products, setProducts] = useState(null)
49+
50+
useEffect(() => {
51+
const fetchProductCount = async () => {
52+
const response = await userStory.getProductCount()
53+
setProductCount(response.data.data.productsConnection.aggregate.count)
54+
}
55+
const fetchProducts = async () => {
56+
const response = await userStory.getProducts()
57+
return response.data.data.product !== null
58+
? setProducts([...response.data.data.products])
59+
: setProducts([])
60+
}
61+
fetchProductCount()
62+
fetchProducts()
63+
}, [])
64+
65+
useEffect(() => {
66+
if (product !== 'All') {
67+
setProductQuery(`product : {Name: "${product}"}`)
68+
} else {
69+
setProductQuery(``)
70+
}
71+
}, [product, setProductQuery])
72+
73+
return (
74+
<div className='product-list-container'>
75+
<h4>Select a Product</h4>
76+
<div className='flex flex-row flex-center product-list'>
77+
{!products &&
78+
Array(productCount)
79+
.fill()
80+
.map((_, index) => <ProductSkeleton key={index} />)}
81+
{products !== null &&
82+
products.map((p) => (
83+
<ProductCard
84+
key={p.Name}
85+
product={p}
86+
selected={p.Name === product}
87+
setProduct={setProduct}
88+
/>
89+
))}
90+
</div>
91+
</div>
92+
)
93+
}
94+
95+
export default ProductList

src/components/Stories.js

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SearchInput from '../modules/SearchInput'
99

1010
import Lists from '../utils/Lists'
1111
import userStory from '../services/user_story'
12+
import ProductList from './ProductList'
1213

1314
const Stories = ({ authorId, followerId }) => {
1415
const [currentStateSelected, selectState] = useState('Under consideration')
@@ -19,14 +20,10 @@ const Stories = ({ authorId, followerId }) => {
1920

2021
const [status, setStatus] = useState('Under consideration')
2122

22-
const [product, setProduct] = useState('All')
23-
2423
const [sort, setSort] = useState('Most Voted')
2524

2625
const [category, setCategory] = useState('All')
2726

28-
const [products, setProducts] = useState([])
29-
3027
const [categories, setCategories] = useState([])
3128

3229
const [searchTerm, setSearchTerm] = useState('')
@@ -39,8 +36,6 @@ const Stories = ({ authorId, followerId }) => {
3936

4037
const statusDropdownContainer = useRef()
4138

42-
const productDropdownContainer = useRef()
43-
4439
const sortDropdownContainer = useRef()
4540

4641
const categoryDropdownContainer = useRef()
@@ -81,7 +76,6 @@ const Stories = ({ authorId, followerId }) => {
8176
fetchStoryCount()
8277
}, [
8378
currentStateSelected,
84-
product,
8579
categoryQuery,
8680
productQuery,
8781
searchQuery,
@@ -91,11 +85,6 @@ const Stories = ({ authorId, followerId }) => {
9185
])
9286

9387
useEffect(() => {
94-
if (product !== 'All') {
95-
setProductQuery(`product : {Name: "${product}"}`)
96-
} else {
97-
setProductQuery(``)
98-
}
9988
if (category !== 'All') {
10089
setCategoryQuery(`Category : "${category}"`)
10190
} else {
@@ -107,7 +96,7 @@ const Stories = ({ authorId, followerId }) => {
10796
if (userTerm === '') {
10897
setAuthorQuery('')
10998
}
110-
}, [product, category, searchTerm, userTerm])
99+
}, [category, searchTerm, userTerm])
111100

112101
useEffect(() => {
113102
const fetchStories = async () => {
@@ -135,21 +124,6 @@ const Stories = ({ authorId, followerId }) => {
135124
followerId
136125
])
137126

138-
useEffect(() => {
139-
const fetchProducts = async () => {
140-
const response = await userStory.getProducts()
141-
return response.data.data.product !== null
142-
? setProducts([
143-
'All',
144-
...response.data.data.products?.map((ele) => {
145-
return ele.Name
146-
})
147-
])
148-
: setProducts(['All'])
149-
}
150-
fetchProducts()
151-
}, [])
152-
153127
useEffect(() => {
154128
const fetchCategories = async () => {
155129
const response = await userStory.getCategories()
@@ -186,6 +160,7 @@ const Stories = ({ authorId, followerId }) => {
186160

187161
return (
188162
<div>
163+
<ProductList setProductQuery={setProductQuery} />
189164
<div className='roadmap-container'>
190165
<div className='roadmap'>
191166
{Lists.stateList &&
@@ -234,14 +209,6 @@ const Stories = ({ authorId, followerId }) => {
234209
setAuthorQuery={setAuthorQuery}
235210
/>
236211
<div className='flex flex-row options-bar'>
237-
<Dropdown
238-
title='Product'
239-
reference={productDropdownContainer}
240-
curr={product}
241-
setCurr={setProduct}
242-
itemList={products}
243-
data-cy='product-dropdown'
244-
/>
245212
<Dropdown
246213
title='Categories'
247214
reference={categoryDropdownContainer}
@@ -260,18 +227,13 @@ const Stories = ({ authorId, followerId }) => {
260227
</div>
261228
</div>
262229
<div className='stories-div'>
263-
<StoriesList
264-
stories={stories}
265-
state={currentStateSelected}
266-
product={product}
267-
isLoading={promiseInProgress}
268-
/>
230+
<StoriesList stories={stories} isLoading={promiseInProgress} />
269231
</div>
270232
<Pagination
271233
getPage={getPage}
272234
storyCount={storyCount}
273235
status={currentStateSelected}
274-
product={product}
236+
productQuery={productQuery}
275237
/>
276238
</div>
277239
)

0 commit comments

Comments
 (0)