Skip to content
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
21 changes: 19 additions & 2 deletions packages/mobile/src/screens/search-screen-v2/SearchBarV2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Dimensions } from 'react-native'
import { Dimensions, Pressable } from 'react-native'

import { IconSearch, TextInput, TextInputSize } from '@audius/harmony-native'
import {
IconCloseAlt,
IconSearch,
TextInput,
TextInputSize
} from '@audius/harmony-native'

import { useSearchQuery } from './searchState'

Expand All @@ -12,9 +17,21 @@ const messages = {

export const SearchBarV2 = () => {
const [query, setQuery] = useSearchQuery()

const clearQuery = () => {
setQuery('')
}

return (
<TextInput
startIcon={IconSearch}
endIcon={() =>
query ? (
<Pressable onPress={clearQuery} hitSlop={10}>
<IconCloseAlt size='s' color='subdued' />
</Pressable>
) : null
}
size={TextInputSize.SMALL}
label={messages.label}
placeholder={messages.label}
Expand Down
30 changes: 30 additions & 0 deletions packages/web/src/components/search-bar/ConnectedSearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,35 @@ class ConnectedSearchBar extends Component {
})
}

onClear = () => {
this.props.clearSearch()
this.setState({ value: '' })

const locationSearchParams = new URLSearchParams(
this.props.history.location.search
)

locationSearchParams.delete('query')

let newPath = '/search'

const searchMatch = matchPath(getPathname(this.props.history.location), {
path: SEARCH_PAGE
})

if (searchMatch) {
newPath = generatePath(SEARCH_PAGE, {
...searchMatch.params
})
}
Comment on lines +180 to +196

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i should have made a util for this


this.props.history.push({
pathname: newPath,
search: locationSearchParams.toString(),
state: {}
})
}

render() {
if (!this.props.search.tracks) {
this.props.search.tracks = []
Expand Down Expand Up @@ -307,6 +336,7 @@ class ConnectedSearchBar extends Component {
onSubmit={this.onSubmit}
goToRoute={this.props.goToRoute}
addRecentSearch={this.props.addRecentSearch}
onClear={this.onClear}
/>
</div>
)
Expand Down
11 changes: 10 additions & 1 deletion packages/web/src/components/search/SearchBarV2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
IconArrowRight as IconArrow,
IconSearch,
setupHotkeys,
removeHotkeys
removeHotkeys,
IconCloseAlt,
Flex
} from '@audius/harmony'
import AutoComplete from 'antd/lib/auto-complete'
import Input from 'antd/lib/input'
Expand Down Expand Up @@ -433,6 +435,13 @@ class SearchBar extends Component {
onClick={() => this.props.onSubmit('')}
/>
}
suffix={
this.state.value ? (
<Flex onClick={() => this.props.onClear()}>
<IconCloseAlt size='2xs' color='subdued' />
</Flex>
) : null
}
onKeyDown={this.onKeyDown}
spellCheck={false}
/>
Expand Down