Make app data loading safe under StrictMode
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
b470a34b2a
commit
99d916f6db
6 changed files with 207 additions and 32 deletions
|
|
@ -21,12 +21,12 @@ export const INITIAL_DIABLO4_STATE = {
|
|||
filterOptionKeys: { affixes: "" }
|
||||
};
|
||||
|
||||
export async function loadMhwildsData() {
|
||||
export async function loadMhwildsData(signal) {
|
||||
const [monstersResponse, endemicResponse, listIndexResponse, translationsResponse] = await Promise.all([
|
||||
fetch("/data/mhwilds/monsters.json"),
|
||||
fetch("/data/mhwilds/endemic_life.json"),
|
||||
fetch("/data/mhwilds/lists/index.json"),
|
||||
fetch("/data/mhwilds/i18n/fr.json")
|
||||
fetch("/data/mhwilds/monsters.json", { signal }),
|
||||
fetch("/data/mhwilds/endemic_life.json", { signal }),
|
||||
fetch("/data/mhwilds/lists/index.json", { signal }),
|
||||
fetch("/data/mhwilds/i18n/fr.json", { signal })
|
||||
]);
|
||||
|
||||
if (!monstersResponse.ok || !endemicResponse.ok || !listIndexResponse.ok || !translationsResponse.ok) {
|
||||
|
|
@ -39,7 +39,7 @@ export async function loadMhwildsData() {
|
|||
listIndexResponse.json(),
|
||||
translationsResponse.json()
|
||||
]);
|
||||
const lists = await loadGameLists("mhwilds", listIndexJson);
|
||||
const lists = await loadGameLists("mhwilds", listIndexJson, signal);
|
||||
const monsterFilterKey = Object.keys(monstersJson).find((key) => key !== "monsters") || "";
|
||||
const endemicFilterKey = Object.keys(endemicJson).find((key) => key !== "endemicLife" && key !== "aquaticLife") || "";
|
||||
|
||||
|
|
@ -62,10 +62,10 @@ export async function loadMhwildsData() {
|
|||
};
|
||||
}
|
||||
|
||||
async function loadGameLists(gameId, indexPayload) {
|
||||
async function loadGameLists(gameId, indexPayload, signal) {
|
||||
const entries = Array.isArray(indexPayload?.lists) ? indexPayload.lists : [];
|
||||
const results = await Promise.all(entries.map(async (entry) => {
|
||||
const response = await fetch(`/data/${gameId}/lists/${entry.file}`);
|
||||
const response = await fetch(`/data/${gameId}/lists/${entry.file}`, { signal });
|
||||
if (!response.ok) throw new Error(`Impossible de charger la liste ${entry.file}.`);
|
||||
const payload = await response.json();
|
||||
return normalizeGameListFile(entry, payload);
|
||||
|
|
@ -107,8 +107,8 @@ function formatListTitle(value) {
|
|||
.replace(/\b\p{L}/gu, (letter) => letter.toUpperCase());
|
||||
}
|
||||
|
||||
export async function loadDiablo4Data() {
|
||||
const response = await fetch("/data/diablo4/affixes_types.json");
|
||||
export async function loadDiablo4Data(signal) {
|
||||
const response = await fetch("/data/diablo4/affixes_types.json", { signal });
|
||||
if (!response.ok) throw new Error("Impossible de charger les données Diablo IV.");
|
||||
|
||||
const payload = await response.json();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue