Skip to content

Commit

Permalink
feat: filters (decentraland#161)
Browse files Browse the repository at this point in the history
* feat: rarity and gender filters + results count

* chore: added missing translations

* style: reduce padding

* chore: address feedback

* chore: warning
  • Loading branch information
cazala authored Mar 3, 2020
1 parent 863f788 commit 7be3e6b
Show file tree
Hide file tree
Showing 37 changed files with 730 additions and 101 deletions.
5 changes: 3 additions & 2 deletions webapp/src/components/AccountPage/AccountPage.container.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'react-redux'
import { replace } from 'connected-react-router'
import { replace, push } from 'connected-react-router'
import { RouteComponentProps } from 'react-router'

import { RootState } from '../../modules/reducer'
Expand All @@ -26,7 +26,8 @@ const mapState = (
}

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
onNavigate: path => dispatch(replace(path))
onNavigate: path => dispatch(push(path)),
onRedirect: path => dispatch(replace(path))
})

export default connect(mapState, mapDispatch)(AccountPage)
6 changes: 3 additions & 3 deletions webapp/src/components/AccountPage/AccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Props } from './AccountPage.types'
import './AccountPage.css'

const AccountPage = (props: Props) => {
const { address, wallet, isConnecting, onNavigate } = props
const { address, wallet, isConnecting, onNavigate, onRedirect } = props

const isCurrentAccount =
address === undefined || (wallet && wallet.address === address)
Expand All @@ -35,9 +35,9 @@ const AccountPage = (props: Props) => {
// Redirect to signIn if trying to access current account without a wallet
useEffect(() => {
if (isCurrentAccount && !isConnecting && !wallet) {
onNavigate(locations.signIn())
onRedirect(locations.signIn())
}
}, [isCurrentAccount, isConnecting, wallet, onNavigate])
}, [isCurrentAccount, isConnecting, wallet, onRedirect])

return (
<div className="AccountPage">
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/AccountPage/AccountPage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export type Props = {
wallet: Wallet | null
isConnecting: boolean
onNavigate: (path: string) => void
onRedirect: (path: string) => void
}

export type MapStateProps = Pick<Props, 'address' | 'wallet' | 'isConnecting'>
export type MapDispatchProps = Pick<Props, 'onNavigate'>
export type MapDispatchProps = Pick<Props, 'onNavigate' | 'onRedirect'>
export type MapDispatch = Dispatch<CallHistoryMethodAction>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { Link } from 'react-router-dom'
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
import { Loader, Mana, Icon } from 'decentraland-ui'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import {
Expand All @@ -11,6 +10,7 @@ import {
TransactionStatus,
Transaction
} from 'decentraland-dapps/dist/modules/transaction/types'
import { formatDistanceToNow } from '../../../../lib/date'
import { locations } from '../../../../modules/routing/locations'
import { NFTImage } from '../../../NFTImage'
import { Props } from './Transaction.types'
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/components/Bid/Bid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback } from 'react'
import { Link } from 'react-router-dom'
import { Loader, Stats, Mana, Button } from 'decentraland-ui'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
import { locations } from '../../modules/routing/locations'
import { addressEquals } from '../../modules/wallet/utils'
import { NFTProvider } from '../NFTProvider'
Expand All @@ -11,6 +10,7 @@ import { Address } from '../Address'
import { AcceptButton } from './AcceptButton'
import { WarningMessage } from './WarningMessage'
import { formatMANA } from '../../lib/mana'
import { formatDistanceToNow } from '../../lib/date'
import { Props } from './Bid.types'
import './Bid.css'

Expand Down Expand Up @@ -59,14 +59,14 @@ const Bid = (props: Props) => {
<div className="wrapper">
<div className="info">
{!isBidder ? (
<Stats className="from" title="from">
<Stats className="from" title={t('bid.from')}>
<Address address={bid.bidder} />
</Stats>
) : null}
<Stats title="price">
<Stats title={t('bid.price')}>
<Mana>{formatMANA(bid.price)}</Mana>
</Stats>
<Stats title="time left">
<Stats title={t('bid.time_left')}>
{formatDistanceToNow(+bid.expiresAt)}
</Stats>
</div>
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/components/CategoriesMenu/CategoriesMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const CategoriesMenu = (props: Props) => {
Section.WEARABLES_FEET,
Section.WEARABLES_ACCESORIES,
Section.WEARABLES_EARRING,
Section.WEARABLES_EYEWEAR,
Section.WEARABLES_HAT,
Section.WEARABLES_HELMET,
Section.WEARABLES_MASK,
Expand Down Expand Up @@ -86,6 +87,7 @@ const CategoriesMenu = (props: Props) => {
sections={[
Section.WEARABLES_ACCESORIES,
Section.WEARABLES_EARRING,
Section.WEARABLES_EYEWEAR,
Section.WEARABLES_HAT,
Section.WEARABLES_HELMET,
Section.WEARABLES_MASK,
Expand Down
46 changes: 46 additions & 0 deletions webapp/src/components/NFTListPage/ArrayFilter/ArrayFilter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.ArrayFilter {
display: flex;
flex-direction: column;
}

.ArrayFilter + .ArrayFilter {
margin-top: 14px;
}

.ArrayFilter .ui.sub.header.name {
margin-bottom: 12px;
font-weight: 600;
}

.ArrayFilter .options {
display: flex;
flex-flow: wrap;
}

.ArrayFilter .options .option {
padding: 5px 12px;
background-color: #37333d;
border-radius: 16px;
text-transform: uppercase;
font-weight: 600;
cursor: pointer;
margin-right: 8px;
margin-bottom: 8px;
}

.ArrayFilter .options .option.selected {
background-color: var(--primary);
}

@media (max-width: 768px) {
.ArrayFilter {
margin-bottom: 12px;
}

.ArrayFilter .options .option {
font-size: 13px;
line-height: 18px;
margin-right: 16px;
margin-bottom: 16px;
}
}
42 changes: 42 additions & 0 deletions webapp/src/components/NFTListPage/ArrayFilter/ArrayFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { Header } from 'decentraland-ui'

import { Props } from './ArrayFilter.types'
import './ArrayFilter.css'

const getClasses = (value: string, values: string[]) => {
const classes = ['option']
if (values.includes(value)) {
classes.push('selected')
}
return classes.join(' ')
}

const getNewValues = (value: string, values: string[]) => {
return values.some(x => x === value)
? values.filter(x => x !== value)
: [...values, value]
}

const ArrayFilter = (props: Props) => {
const { name, values, options, onChange } = props
return (
<div className="ArrayFilter">
<Header sub className="name">
{name}
</Header>
<div className="options">
{options.map(option => (
<div
className={getClasses(option.value, values)}
onClick={() => onChange(getNewValues(option.value, values))}
>
{option.label}
</div>
))}
</div>
</div>
)
}

export default ArrayFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Props = {
name: string
values: string[]
options: { value: string; label: string }[]
onChange: (newValues: string[]) => void
}
3 changes: 3 additions & 0 deletions webapp/src/components/NFTListPage/ArrayFilter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ArrayFilter from './ArrayFilter'

export { ArrayFilter }
23 changes: 23 additions & 0 deletions webapp/src/components/NFTListPage/ClearFilter/ClearFilter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.ClearFilter {
cursor: pointer;
display: flex;
align-items: center;
}

.ClearFilter .name {
display: inline-block;
color: var(--primary);
font-weight: 600;
text-transform: uppercase;
}

.ClearFilter .close {
width: 16px;
height: 16px;
background-image: url(../../../images/close.svg);
background-position: center;
background-size: cover;
display: inline-block;
margin-left: 8px;
margin-right: 16px;
}
16 changes: 16 additions & 0 deletions webapp/src/components/NFTListPage/ClearFilter/ClearFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

import { Props } from './ClearFilter.types'
import './ClearFilter.css'

const ClearFilter = (props: Props) => {
const { name, onClear } = props
return (
<div className="ClearFilter" onClick={onClear}>
<div className="name">{name}</div>
<div className="close" />
</div>
)
}

export default ClearFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Props = {
name: string
onClear: () => void
}
3 changes: 3 additions & 0 deletions webapp/src/components/NFTListPage/ClearFilter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ClearFilter from './ClearFilter'

export { ClearFilter }
8 changes: 7 additions & 1 deletion webapp/src/components/NFTListPage/NFTListPage.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
getUIPage,
getUISection,
getUISortBy,
getUIOnlyOnSale
getUIOnlyOnSale,
getAssetsCount,
getUIWearableRarities,
getUIWearableGenders
} from '../../modules/ui/selectors'
import { getLoading } from '../../modules/nft/selectors'
import NFTListPage from './NFTListPage'
Expand All @@ -23,6 +26,9 @@ const mapState = (state: RootState): MapStateProps => ({
page: getUIPage(state),
section: getUISection(state),
sortBy: getUISortBy(state),
count: getAssetsCount(state),
wearableRarities: getUIWearableRarities(state),
wearableGenders: getUIWearableGenders(state),
onlyOnSale: getUIOnlyOnSale(state),
isLoading: isLoadingType(getLoading(state), FETCH_NFTS_REQUEST)
})
Expand Down
52 changes: 52 additions & 0 deletions webapp/src/components/NFTListPage/NFTListPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,55 @@
);
}

.NFTListPage .results {
margin: 0px;
}

.NFTListPage .filters {
padding: 16px;
background-color: var(--card);
border-radius: 16px;
margin-bottom: 32px;
user-select: none;
outline: none;
padding-bottom: 8px;
margin-top: -8px;
}

.NFTListPage .open-filters-wrapper {
display: inline-block;
height: 15px;
margin-left: 24px;
position: relative;
cursor: pointer;
}

.NFTListPage .open-filters-wrapper .label {
color: var(--primary);
text-transform: uppercase;
margin-right: 30px;
font-weight: 500;
}

.NFTListPage .open-filters {
width: 20px;
height: 20px;
background-image: url(../../images/filters.svg);
background-size: 16px;
background-repeat: no-repeat;
background-position: center;

display: inline-block;
position: absolute;
right: 0px;
top: 0px;
}

.NFTListPage .open-filters.active {
background-image: url(../../images/filters-active.svg);
background-size: 20px;
}

.FiltersModal .CategoriesMenu ul.menu li:hover,
.FiltersModal .CategoriesMenu ul.menu li.active {
background-color: var(--secondary-on-modal);
Expand Down Expand Up @@ -101,4 +150,7 @@
.CategoriesMenu ul.menu li {
width: calc(100% - 32px);
}
.NFTListPage .filters {
margin-top: 0px;
}
}
Loading

0 comments on commit 7be3e6b

Please sign in to comment.