-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Panel search: abort previous requests
- Loading branch information
1 parent
065b695
commit cb8223b
Showing
2 changed files
with
47 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default (panel) => { | ||
return { | ||
controller: null, | ||
|
||
open(type) { | ||
// close menu on mobile | ||
panel.menu.escape(); | ||
|
||
panel.dialog.open({ | ||
component: "k-search-dialog", | ||
props: { | ||
type | ||
} | ||
}); | ||
}, | ||
|
||
/** | ||
* Use one of the installed search types | ||
* to search for content in the panel | ||
* | ||
* @param {String} type | ||
* @param {Object} query | ||
* @param {Object} options { limit, page } | ||
* @returns {Object} { code, path, referrer, results, timestamp } | ||
*/ | ||
async search(type, query, options) { | ||
// open the search dialog | ||
if (!query) { | ||
return this.open(type); | ||
} | ||
|
||
// abort previous search requests | ||
this.controller?.abort(); | ||
this.controller = new AbortController(); | ||
|
||
const { $search } = await panel.get(`/search/${type}`, { | ||
query: { query, ...options }, | ||
signal: this.controller.signal | ||
}); | ||
|
||
return $search; | ||
} | ||
}; | ||
}; |