mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:03:46 +08:00
FIX: Error in Ember CLI environment
There are a few fixes at play here: 1) We were still not initializing objects to the correct types. 2) If a debounce timed out, it was returning a string instead of an array which was not appropriately handled. 3) In testing mode we never cancel the search promise for stability.
This commit is contained in:
parent
f4cca4af75
commit
cddba50570
|
@ -20,12 +20,11 @@ function updateCache(term, results) {
|
|||
|
||||
function searchTags(term, categories, limit) {
|
||||
return new Promise((resolve) => {
|
||||
const clearPromise = later(
|
||||
() => {
|
||||
let clearPromise = isTesting()
|
||||
? null
|
||||
: later(() => {
|
||||
resolve(CANCELLED_STATUS);
|
||||
},
|
||||
isTesting() ? 50 : 5000
|
||||
);
|
||||
}, 5000);
|
||||
|
||||
const debouncedSearch = (q, cats, resultFunc) => {
|
||||
discourseDebounce(
|
||||
|
|
|
@ -9,6 +9,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||
import { Promise } from "rsvp";
|
||||
import { search as searchCategoryTag } from "discourse/lib/category-tag-search";
|
||||
import userSearch from "discourse/lib/user-search";
|
||||
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
|
||||
|
||||
const CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi;
|
||||
const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi;
|
||||
|
@ -18,7 +19,7 @@ const searchData = {};
|
|||
|
||||
export function initSearchData() {
|
||||
searchData.loading = false;
|
||||
searchData.results = [];
|
||||
searchData.results = {};
|
||||
searchData.noResults = false;
|
||||
searchData.term = undefined;
|
||||
searchData.typeFilter = null;
|
||||
|
@ -52,8 +53,9 @@ const SearchHelper = {
|
|||
|
||||
if (matchSuggestions) {
|
||||
searchData.noResults = true;
|
||||
searchData.results = [];
|
||||
searchData.results = {};
|
||||
searchData.loading = false;
|
||||
searchData.suggestionResults = [];
|
||||
|
||||
if (matchSuggestions.type === "category") {
|
||||
const categorySearchTerm = matchSuggestions.categoriesMatch[0].replace(
|
||||
|
@ -66,8 +68,10 @@ const SearchHelper = {
|
|||
widget.siteSettings
|
||||
);
|
||||
Promise.resolve(categoryTagSearch).then((results) => {
|
||||
if (results !== CANCELLED_STATUS) {
|
||||
searchData.suggestionResults = results;
|
||||
searchData.suggestionKeyword = "#";
|
||||
}
|
||||
widget.scheduleRerender();
|
||||
});
|
||||
} else if (matchSuggestions.type === "username") {
|
||||
|
|
Loading…
Reference in New Issue
Block a user