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

901 show pins amount map filter #921

Merged
merged 3 commits into from
Mar 28, 2020
Merged
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
16 changes: 14 additions & 2 deletions src/pages/Maps/Content/Controls/GroupingFilterDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import MultiSelect from '@khanacademy/react-multi-select'
import './GroupingFilter.css'
import ElWithBeforeIcon from 'src/components/ElWithBeforeIcon'
import { IMapGrouping } from 'src/models/maps.models'
import { inject } from 'mobx-react'
import { MapsStore } from 'src/stores/Maps/maps.store'
import { Box } from 'rebass'

interface IProps {
Expand All @@ -16,6 +18,9 @@ interface IState {
initialItems: Array<any>
selectedItems: Array<string>
}
interface IInjectedProps extends IProps {
mapsStore: MapsStore
}

const ItemRenderer = ({ checked, option, onClick }) => {
return (
Expand All @@ -42,13 +47,13 @@ const ItemRenderer = ({ checked, option, onClick }) => {
paddingBottom: '2px',
}}
>
{option.label}
{option.label} ({option.number})
</h4>
</ElWithBeforeIcon>
</div>
)
}

@inject('mapsStore')
class GroupingFilterDesktop extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props)
Expand All @@ -57,6 +62,9 @@ class GroupingFilterDesktop extends React.Component<IProps, IState> {
selectedItems: [],
}
}
get injected() {
return this.props as IInjectedProps
}

handleChange(selectedItems: Array<string>) {
this.setState({ selectedItems })
Expand All @@ -74,6 +82,10 @@ class GroupingFilterDesktop extends React.Component<IProps, IState> {
label: item.displayName,
value: item.subType ? item.subType : item.type,
icon: item.icon,
// add split(' ') method to convert to array
number: this.injected.mapsStore.getPinsNumberByFilterType(
item.subType ? item.subType.split(' ') : item.type.split(' '),
),
}))
}

Expand Down
15 changes: 14 additions & 1 deletion src/pages/Maps/Content/Controls/GroupingFilterMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Text from 'src/components/Text'
import { IMapGrouping } from 'src/models/maps.models'
import checkmarkIcon from 'src/assets/icons/icon-checkmark.svg'
import { Flex, Image } from 'rebass'
import { inject } from 'mobx-react'
import { MapsStore } from 'src/stores/Maps/maps.store'

interface IProps {
items: Array<IMapGrouping>
Expand All @@ -14,7 +16,11 @@ interface IProps {
interface IState {
initialItems: Array<any>
}
interface IInjectedProps extends IProps {
mapsStore: MapsStore
}

@inject('mapsStore')
class GroupingFilterMobile extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props)
Expand All @@ -23,6 +29,10 @@ class GroupingFilterMobile extends React.Component<IProps, IState> {
}
}

get injected() {
return this.props as IInjectedProps
}

addOrRemove = (array, item) => {
// from https://stackoverflow.com/a/52531625
const exists = array.includes(item)
Expand Down Expand Up @@ -52,6 +62,9 @@ class GroupingFilterMobile extends React.Component<IProps, IState> {
label: item.displayName,
value: item.subType ? item.subType : item.type,
icon: item.icon,
number: this.injected.mapsStore.getPinsNumberByFilterType(
item.subType ? item.subType.split(' ') : item.type.split(' '),
),
}))
}

Expand Down Expand Up @@ -80,7 +93,7 @@ class GroupingFilterMobile extends React.Component<IProps, IState> {
<Flex alignItems="center">
<Image width="30px" src={filter.icon} />
<Text medium ml="10px">
{filter.label}
{filter.label} ({filter.number})
</Text>
</Flex>
{selectedItems.includes(filter.value) && (
Expand Down
14 changes: 12 additions & 2 deletions src/stores/Maps/maps.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@ export class MapsStore extends ModuleStore {
return
}

const mapPins = this.filterMapPinsByType(filters)
this.filteredPins = mapPins
}

private filterMapPinsByType(filters: Array<string>) {
// filter pins to include matched pin type or subtype
const mapPins = this.mapPins.filter(pin => {
const filteredMapPins = this.mapPins.filter(pin => {
return pin.subType
? filters.includes(pin.subType)
: filters.includes(pin.type)
})
this.filteredPins = mapPins
return filteredMapPins
}

/**
Expand Down Expand Up @@ -223,6 +228,11 @@ export class MapsStore extends ModuleStore {
profileUrl: `${location.origin}/u/${u.userName}`,
}
}
@action
public getPinsNumberByFilterType(filter: Array<string>) {
const pinsNumber = this.filterMapPinsByType(filter)
return pinsNumber.length
}
}

/**********************************************************************************
Expand Down