fix: Fix Map page

This commit is contained in:
2025-06-12 22:50:43 +03:00
parent 27cb644242
commit 300ff262ce
41 changed files with 2216 additions and 1055 deletions

View File

@ -12,9 +12,18 @@ export type Country = {
};
export type CashedCountries = {
ru: Country[];
en: Country[];
zh: Country[];
ru: {
data: Country[];
loaded: boolean;
};
en: {
data: Country[];
loaded: boolean;
};
zh: {
data: Country[];
loaded: boolean;
};
};
export type CashedCountry = {
@ -25,9 +34,18 @@ export type CashedCountry = {
class CountryStore {
countries: CashedCountries = {
ru: [],
en: [],
zh: [],
ru: {
data: [],
loaded: false,
},
en: {
data: [],
loaded: false,
},
zh: {
data: [],
loaded: false,
},
};
country: Record<string, CashedCountry> = {};
@ -37,14 +55,15 @@ class CountryStore {
}
getCountries = async (language: keyof CashedCountries) => {
if (this.countries[language] && this.countries[language].length > 0) {
if (this.countries[language].loaded) {
return;
}
const response = await authInstance.get(`/country`);
const response = await languageInstance(language).get(`/country`);
runInAction(() => {
this.countries[language] = response.data;
this.countries[language].data = response.data;
this.countries[language].loaded = true;
});
};
@ -76,10 +95,15 @@ class CountryStore {
await authInstance.delete(`/country/${code}`);
runInAction(() => {
this.countries[language] = this.countries[language].filter(
this.countries[language].data = this.countries[language].data.filter(
(country) => country.code !== code
);
this.country[code][language] = null;
this.countries[language].loaded = true;
this.country[code] = {
ru: null,
en: null,
zh: null,
};
});
};
@ -121,8 +145,8 @@ class CountryStore {
});
runInAction(() => {
this.countries[language as keyof CashedCountries] = [
...this.countries[language as keyof CashedCountries],
this.countries[language as keyof CashedCountries].data = [
...this.countries[language as keyof CashedCountries].data,
{ code: code, name: name },
];
});
@ -142,8 +166,8 @@ class CountryStore {
);
}
runInAction(() => {
this.countries[secondaryLanguage as keyof CashedCountries] = [
...this.countries[secondaryLanguage as keyof CashedCountries],
this.countries[secondaryLanguage as keyof CashedCountries].data = [
...this.countries[secondaryLanguage as keyof CashedCountries].data,
{ code: code, name: name },
];
});
@ -204,11 +228,10 @@ class CountryStore {
};
}
if (this.countries[language as keyof CashedCountries]) {
this.countries[language as keyof CashedCountries] = this.countries[
language as keyof CashedCountries
].map((country) =>
country.code === code ? { code, name } : country
);
this.countries[language as keyof CashedCountries].data =
this.countries[language as keyof CashedCountries].data.map(
(country) => (country.code === code ? { code, name } : country)
);
}
});
}