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 18, 2022
1 parent 1cf4e0a commit dea25be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/components/Bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ export class Bar extends Component {
{barLeft || this.renderLeft()}
{barCenter || this.renderCenter()}
<div className="u-flex-grow">
{barSearch || (searchBarEnabled ? <SearchBar /> : null)}
{barSearch ||
(searchBarEnabled ? (
<SearchBar client={this.props.cozyClient} />
) : null)}
</div>
{barRight || this.renderRight()}
{!isPublic ? (
Expand Down
12 changes: 7 additions & 5 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 } 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 Down
8 changes: 7 additions & 1 deletion src/components/__snapshots__/Bar.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ exports[`Bar should display the Searchbar 1`] = `
<div
className="u-flex-grow"
>
<withI18n(SearchBar) />
<withI18n(SearchBar)
client={
CozyClient {
"uri": undefined,
}
}
/>
</div>
<withI18n(Connect(Settings))
toggleSupport={[Function]}
Expand Down

0 comments on commit dea25be

Please sign in to comment.