Skip to content
Snippets Groups Projects
Commit eba7f934 authored by Eugen Ciur's avatar Eugen Ciur
Browse files

use async/await style for doSearch action

parent 9097511f
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ import { A } from '@ember/array';
export default class SearchComponent extends Component {
@service requests;
@tracked query;
autocomplete_items = A([]);
@tracked autocomplete_items = A([]);
/*
@tracked autocomplete_items = A([
{
......@@ -35,27 +35,16 @@ export default class SearchComponent extends Component {
*/
@action
doSearch() {
let that = this;
async doSearch() {
let response = await this.requests.search(this.query);
let data = await response.json();
this.requests.search(this.query).then(
resp => resp.json()
).then(data => {
data.forEach(item => {
console.log(`pushing item ${item.title}`);
that.autocomplete_items.push(
{
'title': item.title,
'type': 'document',
'path': item.breadcrumb,
}
)
});
this.autocomplete_items = data.map(item => {
return {
'title': item.title,
'type': 'document',
'path': item.breadcrumb,
}
});
if (this.autocomplete_items) {
//pass
}
}
}
......@@ -85,7 +85,7 @@ export default class Requests extends Service {
async search(query) {
let url;
url = `${base_url()}/search?q=${query}`;
url = `${base_url()}/search/?q=${query}`;
return fetch(url, {
method: 'GET',
......
......@@ -9,20 +9,26 @@
width: 100%;
top: 3rem;
background-color: white;
padding: 0rem 1rem;
border: 1px solid #d4d4d4;
margin: 0;
padding: 0;
li:hover {
background-color: #e9e9e9;
border-left: 1px solid #0d6efd;
cursor: pointer;
}
li {
background-color: #fff;
border-left: 1px solid #d4d4d4;
z-index: 1000;
margin-top: 0.5rem;
list-style: none;
display: flex;
align-items: center;
margin: 0;
padding: 0.75rem 1rem;
.path {
padding-left: 2rem;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment