Skip to content

Commit

Permalink
fix(search): need to connect SearchBar to fetch url for notes
Browse files Browse the repository at this point in the history
  • Loading branch information
trollepierre committed Aug 22, 2022
1 parent a9591ea commit 73378dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Autosuggest from 'react-autosuggest'
import debounce from 'lodash.debounce'
import { fetchRawIntent } from 'lib/intents'
import logger from 'lib/logger'
import { models, withClient } from 'cozy-client'

const INTENT_VERB = 'OPEN'
const INTENT_DOCTYPE = 'io.cozy.suggestions'
Expand Down Expand Up @@ -229,12 +230,13 @@ class SearchBar extends Component {
this.setState({ query: null, searching: false })
}

onSuggestionSelected = async (event, { suggestion }) => {
onSuggestionSelected = client => async (event, { suggestion }) => {
const { onSelect } = suggestion
// `onSelect` is a string that describes what should happen when the suggestion is selected. Currently, the only format we're supporting is `open:http://example.com` to change the url of the current page.

if (typeof onSelect === 'function') {
window.location.href = `open:` + (await onSelect())
if (/^id_note:/.test(onSelect)) {
const url = await models.note.fetchURL(client, { id: onSelect.substr(8) })
window.location.href = url
} else if (/^open:/.test(onSelect)) {
window.location.href = onSelect.substr(5)
} else {
Expand Down Expand Up @@ -287,7 +289,7 @@ class SearchBar extends Component {
sourceURLs
} = this.state
if (sourceURLs.length === 0) return null
const { t } = this.props
const { t, client } = this.props

const isInitialSearch = input !== '' && query === null
const hasSuggestions =
Expand Down Expand Up @@ -338,7 +340,7 @@ class SearchBar extends Component {
this.debouncedOnSuggestionsFetchRequested
}
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
onSuggestionSelected={this.onSuggestionSelected}
onSuggestionSelected={this.onSuggestionSelected(client)}
getSuggestionValue={this.getSuggestionValue}
getSectionSuggestions={this.getSectionSuggestions}
renderSectionTitle={this.renderSectionTitle}
Expand All @@ -356,4 +358,4 @@ class SearchBar extends Component {
}
}

export default translate()(SearchBar)
export default translate()(withClient(SearchBar))
2 changes: 1 addition & 1 deletion src/components/__snapshots__/Bar.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ exports[`Bar should display the Searchbar 1`] = `
<div
className="u-flex-grow"
>
<withI18n(SearchBar) />
<withI18n(withClient(SearchBar)) />
</div>
<withI18n(Connect(Settings))
toggleSupport={[Function]}
Expand Down

0 comments on commit 73378dd

Please sign in to comment.