DEV: Use our `ajax` helper consistently (#17304)

Possibly fixes some flakes, but regardless - we need to avoid using `$.ajax` directly in most cases.
This commit is contained in:
Jarek Radosz 2022-07-04 02:24:55 +02:00 committed by GitHub
parent 7caaee27cc
commit 9f83e8e33c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -5,8 +5,8 @@ import { Promise } from "rsvp";
import { SEPARATOR } from "discourse/lib/category-hashtags"; import { SEPARATOR } from "discourse/lib/category-hashtags";
import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags"; import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags";
import discourseDebounce from "discourse-common/lib/debounce"; import discourseDebounce from "discourse-common/lib/debounce";
import getURL from "discourse-common/lib/get-url";
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
import { ajax } from "discourse/lib/ajax";
let cache = {}; let cache = {};
let cacheTime; let cacheTime;
@ -30,8 +30,7 @@ function searchTags(term, categories, limit) {
discourseDebounce( discourseDebounce(
this, this,
function () { function () {
oldSearch = $.ajax(getURL("/tags/filter/search"), { oldSearch = ajax("/tags/filter/search", {
type: "GET",
data: { limit, q }, data: { limit, q },
}); });
@ -50,7 +49,7 @@ function searchTags(term, categories, limit) {
returnVal = cats.concat(tags); returnVal = cats.concat(tags);
}) })
.always(() => { .finally(() => {
oldSearch = null; oldSearch = null;
resultFunc(returnVal); resultFunc(returnVal);
}); });

View File

@ -5,6 +5,7 @@ import discourseDebounce from "discourse-common/lib/debounce";
import { emailValid } from "discourse/lib/utilities"; import { emailValid } from "discourse/lib/utilities";
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
import { userPath } from "discourse/lib/url"; import { userPath } from "discourse/lib/url";
import { ajax } from "discourse/lib/ajax";
let cache = {}, let cache = {},
cacheKey, cacheKey,
@ -75,7 +76,7 @@ function performSearch(
} }
// need to be able to cancel this // need to be able to cancel this
oldSearch = $.ajax(userPath("search/users"), { oldSearch = ajax(userPath("search/users"), {
data, data,
}); });
@ -102,7 +103,7 @@ function performSearch(
returnVal = r; returnVal = r;
} }
}) })
.always(function () { .finally(function () {
oldSearch = null; oldSearch = null;
resultsFn(returnVal); resultsFn(returnVal);
}); });