Skip to content

Commit

Permalink
Merge pull request #1306 from Coflnet/show-icons-for-filter-options
Browse files Browse the repository at this point in the history
add image to filter options
  • Loading branch information
matthias-luger authored Sep 8, 2024
2 parents 550728b + dd0810d commit 0771547
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/FilterElement/FilterElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function FilterElement(props: Props) {
options={options}
defaultValue={props.defaultValue}
onChange={onFilterElementChange}
showIcon={hasFlag(options.type, FilterType.SHOW_ICON)}
/>
)
}
Expand Down
30 changes: 29 additions & 1 deletion components/FilterElement/FilterElements/EqualFilterElement.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
'use client'
import React from 'react'
import { convertTagToName } from '../../../utils/Formatter'
import { Typeahead } from 'react-bootstrap-typeahead'
import { Menu, MenuItem, Typeahead, withItem } from 'react-bootstrap-typeahead'
import { Option } from 'react-bootstrap-typeahead/types/types'
import api from '../../../api/ApiHelper'

const Item = withItem(MenuItem)

interface Props {
onChange(n: string)
options: FilterOptions
defaultValue?: any
isValid?: boolean
showIcon?: boolean
}

export function EqualFilterElement(props: Props) {
Expand All @@ -29,6 +34,29 @@ export function EqualFilterElement(props: Props) {
selectHint={(shouldSelect, event) => {
return event.key === 'Enter' || shouldSelect
}}
renderMenu={(results, menuProps) => (
<Menu {...menuProps}>
{results.map((result, index) => {
if (result['paginationOption']) {
return (
<MenuItem option={result} position={index}>
More results...
</MenuItem>
)
}
return (
<Item option={result} position={index}>
{typeof result === 'string' ? convertTagToName(result as string) : (result as Option)['label']}
{props.showIcon && result !== 'None' && result !== 'Any' && (
<div style={{ float: 'right' }}>
<img src={api.getItemImageUrl({ tag: result as string })} style={{ width: '24px', height: '24px' }}></img>
</div>
)}
</Item>
)
})}
</Menu>
)}
></Typeahead>
)
}
3 changes: 2 additions & 1 deletion components/FilterElement/FilterType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export enum FilterType {
PLAYER = 64,
SIMPLE = 128,
BOOLEAN = 256,
PLAYER_WITH_RANK = 512
PLAYER_WITH_RANK = 512,
SHOW_ICON = 1024,
}

/**
Expand Down

0 comments on commit 0771547

Please sign in to comment.