Skip to content

Commit

Permalink
fix: jquery being undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 22, 2024
1 parent 0b25148 commit 6dbc737
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
97 changes: 50 additions & 47 deletions frontend/src/ts/controllers/quotes-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "../utils/misc";
import { subscribe } from "../observables/config-event";
import * as DB from "../db";
import $ from "jquery";

type JsonQuote = {
text: string;
Expand Down Expand Up @@ -47,57 +48,59 @@ class QuotesController {
const normalizedLanguage = removeLanguageSize(language);

if (this.quoteCollection.language !== normalizedLanguage) {
try {
const data: QuoteData = await $.getJSON(
`quotes/${normalizedLanguage}.json`
);

if (data.quotes === undefined || data.quotes.length === 0) {
return defaultQuoteCollection;
}

this.quoteCollection = {
quotes: [],
length: data.quotes.length,
groups: [],
// try {
const data: QuoteData = await $.getJSON(
`quotes/${normalizedLanguage}.json`
);

if (data.quotes === undefined || data.quotes.length === 0) {
return defaultQuoteCollection;
}

this.quoteCollection = {
quotes: [],
length: data.quotes.length,
groups: [],
language: data.language,
};

// Transform JSON Quote schema to MonkeyTypes Quote schema
data.quotes.forEach((quote: JsonQuote) => {
const monkeyTypeQuote: MonkeyTypes.Quote = {
text: quote.text,
britishText: quote.britishText,
source: quote.source,
length: quote.length,
id: quote.id,
language: data.language,
group: 0,
};

// Transform JSON Quote schema to MonkeyTypes Quote schema
data.quotes.forEach((quote: JsonQuote) => {
const monkeyTypeQuote: MonkeyTypes.Quote = {
text: quote.text,
britishText: quote.britishText,
source: quote.source,
length: quote.length,
id: quote.id,
language: data.language,
group: 0,
};

this.quoteCollection.quotes.push(monkeyTypeQuote);
});

data.groups.forEach((quoteGroup, groupIndex) => {
const lower = quoteGroup[0];
const upper = quoteGroup[1];

this.quoteCollection.groups[groupIndex] =
this.quoteCollection.quotes.filter((quote) => {
if (quote.length >= lower && quote.length <= upper) {
quote.group = groupIndex;
return true;
}
return false;
});
});

if (quoteLengths !== undefined) {
this.updateQuoteQueue(quoteLengths);
}
} catch {
return defaultQuoteCollection;
this.quoteCollection.quotes.push(monkeyTypeQuote);
});

data.groups.forEach((quoteGroup, groupIndex) => {
const lower = quoteGroup[0];
const upper = quoteGroup[1];

this.quoteCollection.groups[groupIndex] =
this.quoteCollection.quotes.filter((quote) => {
if (quote.length >= lower && quote.length <= upper) {
quote.group = groupIndex;
return true;
}
return false;
});
});

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;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ts/test/british-english.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config from "../config";
import { capitalizeFirstLetterOfEachWord } from "../utils/misc";
import * as CustomText from "../test/custom-text";
import $ from "jquery";

type BritishEnglishReplacement = {
0: string;
Expand Down

0 comments on commit 6dbc737

Please sign in to comment.