Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel search: abort previous requests #6420

Draft
wants to merge 2 commits into
base: develop-minor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/src/components/Dialogs/SearchDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/>
</div>

<div v-if="query?.length > 1" class="k-search-dialog-results">
<div v-if="query?.length > 1 && !isLoading" class="k-search-dialog-results">
<!-- Results -->
<k-collection
v-if="items.length"
Expand Down
30 changes: 3 additions & 27 deletions panel/src/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Notification from "./notification.js";
import Language from "./language.js";
import Plugins from "./plugins.js";
import Menu from "./menu.js";
import Search from "./search.js";
import System from "./system.js";
import Translation from "./translation.js";
import { buildUrl, isUrl } from "@/helpers/url.js";
Expand Down Expand Up @@ -72,6 +73,7 @@ export default {
this.activation = Activation(this);
this.drag = Drag(this);
this.events = Events(this);
this.searcher = Search(this);
this.upload = Upload(this);

// state objects
Expand Down Expand Up @@ -284,34 +286,8 @@ export default {
});
},

/**
* 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) {
// close menu on mobile
this.menu.escape();

return this.dialog.open({
component: "k-search-dialog",
props: {
type: type
}
});
}

const { $search } = await this.get(`/search/${type}`, {
query: { query, ...options }
});

return $search;
return this.searcher.search(type, query, options);
},

/**
Expand Down
48 changes: 48 additions & 0 deletions panel/src/panel/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export default (panel) => {
return {
controller: null,

/**
* Open the search dialog
* @param {String} type to preselect
*/
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;
}
};
};
Loading