mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-26 15:54:35 +08:00
impr: remove usage of jQuery getJSON (fehmer) (#5109)
* impr: remove usage of jQuery getJSON * use generic * throwing if nothing found --------- Co-authored-by: Miodec <jack@monkeytype.com>
This commit is contained in:
parent
fd4f1e51e4
commit
81b388af4a
3 changed files with 14 additions and 18 deletions
|
@ -1,11 +1,11 @@
|
|||
import {
|
||||
cachedFetchJson,
|
||||
randomElementFromArray,
|
||||
removeLanguageSize,
|
||||
shuffle,
|
||||
} from "../utils/misc";
|
||||
import { subscribe } from "../observables/config-event";
|
||||
import * as DB from "../db";
|
||||
import $ from "jquery";
|
||||
|
||||
type JsonQuote = {
|
||||
text: string;
|
||||
|
@ -48,8 +48,7 @@ class QuotesController {
|
|||
const normalizedLanguage = removeLanguageSize(language);
|
||||
|
||||
if (this.quoteCollection.language !== normalizedLanguage) {
|
||||
// try {
|
||||
const data: QuoteData = await $.getJSON(
|
||||
const data = await cachedFetchJson<QuoteData>(
|
||||
`quotes/${normalizedLanguage}.json`
|
||||
);
|
||||
|
||||
|
@ -96,11 +95,6 @@ class QuotesController {
|
|||
if (quoteLengths !== undefined) {
|
||||
this.updateQuoteQueue(quoteLengths);
|
||||
}
|
||||
// } catch (e) {
|
||||
// console.error(e);
|
||||
// throw new Error("Failed to parse quotes: " + e.message);
|
||||
// return defaultQuoteCollection;
|
||||
// }
|
||||
}
|
||||
|
||||
return this.quoteCollection;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import Config from "../config";
|
||||
import { capitalizeFirstLetterOfEachWord } from "../utils/misc";
|
||||
import {
|
||||
cachedFetchJson,
|
||||
capitalizeFirstLetterOfEachWord,
|
||||
} from "../utils/misc";
|
||||
import * as CustomText from "../test/custom-text";
|
||||
import $ from "jquery";
|
||||
|
||||
type BritishEnglishReplacement = {
|
||||
0: string;
|
||||
|
@ -13,13 +15,9 @@ let list: BritishEnglishReplacement[] = [];
|
|||
|
||||
export async function getList(): Promise<BritishEnglishReplacement[]> {
|
||||
if (list.length === 0) {
|
||||
return $.getJSON("languages/britishenglish.json", function (data) {
|
||||
list = data;
|
||||
return list;
|
||||
});
|
||||
} else {
|
||||
return list;
|
||||
list = await cachedFetchJson("languages/britishenglish.json");
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
export async function replace(
|
||||
|
|
|
@ -429,16 +429,20 @@ export function median(arr: number[]): number {
|
|||
}
|
||||
|
||||
export async function getLatestReleaseFromGitHub(): Promise<string> {
|
||||
const releases = await $.getJSON(
|
||||
type releaseType = { name: string };
|
||||
const releases = await cachedFetchJson<releaseType[]>(
|
||||
"https://api.github.com/repos/monkeytypegame/monkeytype/releases?per_page=1"
|
||||
);
|
||||
if (releases[0] === undefined || releases[0].name === undefined) {
|
||||
throw new Error("No release found");
|
||||
}
|
||||
return releases[0].name;
|
||||
}
|
||||
|
||||
export async function getReleasesFromGitHub(): Promise<
|
||||
MonkeyTypes.GithubRelease[]
|
||||
> {
|
||||
return $.getJSON(
|
||||
return cachedFetchJson(
|
||||
"https://api.github.com/repos/monkeytypegame/monkeytype/releases?per_page=5"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue