| 1 |
import { useDebounced } from "@web/core/utils/timing"; |
| 2 |
import { useAutofocus } from "@web/core/utils/hooks"; |
| 3 |
|
| 4 |
import { Component, useEffect, useState } from "@odoo/owl"; |
| 5 |
|
| 6 |
export class SearchMedia extends Component { |
| 7 |
static template = "html_editor.SearchMedia"; |
| 8 |
static props = ["searchPlaceholder", "search", "needle"]; |
| 9 |
setup() { |
| 10 |
useAutofocus({ mobile: true }); |
| 11 |
this.debouncedSearch = useDebounced(this.props.search, 1000); |
| 12 |
|
| 13 |
this.state = useState({ |
| 14 |
input: this.props.needle || "", |
| 15 |
}); |
| 16 |
|
| 17 |
useEffect( |
| 18 |
(input) => { |
| 19 |
// Do not trigger a search on the initial render. |
| 20 |
if (this.hasRendered) { |
| 21 |
this.debouncedSearch(input); |
| 22 |
} else { |
| 23 |
this.hasRendered = true; |
| 24 |
} |
| 25 |
}, |
| 26 |
() => [this.state.input] |
| 27 |
); |
| 28 |
} |
| 29 |
} |