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) {
|
function searchTags(term, categories, limit) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const clearPromise = later(
|
let clearPromise = isTesting()
|
||||||
() => {
|
? null
|
||||||
|
: later(() => {
|
||||||
resolve(CANCELLED_STATUS);
|
resolve(CANCELLED_STATUS);
|
||||||
},
|
}, 5000);
|
||||||
isTesting() ? 50 : 5000
|
|
||||||
);
|
|
||||||
|
|
||||||
const debouncedSearch = (q, cats, resultFunc) => {
|
const debouncedSearch = (q, cats, resultFunc) => {
|
||||||
discourseDebounce(
|
discourseDebounce(
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { search as searchCategoryTag } from "discourse/lib/category-tag-search";
|
import { search as searchCategoryTag } from "discourse/lib/category-tag-search";
|
||||||
import userSearch from "discourse/lib/user-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 CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi;
|
||||||
const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi;
|
const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi;
|
||||||
|
@ -18,7 +19,7 @@ const searchData = {};
|
||||||
|
|
||||||
export function initSearchData() {
|
export function initSearchData() {
|
||||||
searchData.loading = false;
|
searchData.loading = false;
|
||||||
searchData.results = [];
|
searchData.results = {};
|
||||||
searchData.noResults = false;
|
searchData.noResults = false;
|
||||||
searchData.term = undefined;
|
searchData.term = undefined;
|
||||||
searchData.typeFilter = null;
|
searchData.typeFilter = null;
|
||||||
|
@ -52,8 +53,9 @@ const SearchHelper = {
|
||||||
|
|
||||||
if (matchSuggestions) {
|
if (matchSuggestions) {
|
||||||
searchData.noResults = true;
|
searchData.noResults = true;
|
||||||
searchData.results = [];
|
searchData.results = {};
|
||||||
searchData.loading = false;
|
searchData.loading = false;
|
||||||
|
searchData.suggestionResults = [];
|
||||||
|
|
||||||
if (matchSuggestions.type === "category") {
|
if (matchSuggestions.type === "category") {
|
||||||
const categorySearchTerm = matchSuggestions.categoriesMatch[0].replace(
|
const categorySearchTerm = matchSuggestions.categoriesMatch[0].replace(
|
||||||
|
@ -66,8 +68,10 @@ const SearchHelper = {
|
||||||
widget.siteSettings
|
widget.siteSettings
|
||||||
);
|
);
|
||||||
Promise.resolve(categoryTagSearch).then((results) => {
|
Promise.resolve(categoryTagSearch).then((results) => {
|
||||||
|
if (results !== CANCELLED_STATUS) {
|
||||||
searchData.suggestionResults = results;
|
searchData.suggestionResults = results;
|
||||||
searchData.suggestionKeyword = "#";
|
searchData.suggestionKeyword = "#";
|
||||||
|
}
|
||||||
widget.scheduleRerender();
|
widget.scheduleRerender();
|
||||||
});
|
});
|
||||||
} else if (matchSuggestions.type === "username") {
|
} else if (matchSuggestions.type === "username") {
|
||||||
|
|
Loading…
Reference in New Issue