fix: Update map with tables fixes

This commit is contained in:
2025-07-09 18:56:18 +03:00
parent 78800ee2ae
commit e2547cb571
87 changed files with 5392 additions and 1410 deletions

View File

@@ -109,7 +109,8 @@ class ArticlesStore {
getArticles = async (language: Language) => {
this.articleLoading = true;
const response = await authInstance.get("/article");
const response = await languageInstance(language).get("/article");
runInAction(() => {
this.articles[language] = response.data;
@@ -119,8 +120,9 @@ class ArticlesStore {
getArticle = async (id: number, language?: Language) => {
this.articleLoading = true;
let response: any;
if (language) {
const response = await languageInstance(language).get(`/article/${id}`);
response = await languageInstance(language).get(`/article/${id}`);
runInAction(() => {
if (!this.articleData) {
this.articleData = { id, heading: "", body: "", service_name: "" };
@@ -131,11 +133,12 @@ class ArticlesStore {
};
});
} else {
const response = await authInstance.get(`/article/${id}`);
response = await authInstance.get(`/article/${id}`);
runInAction(() => {
this.articleData = response.data;
});
}
return response;
this.articleLoading = false;
};

View File

@@ -55,7 +55,11 @@ class AuthStore {
runInAction(() => {
this.setAuthToken(data.token);
this.payload = response.data;
this.payload = {
...response.data.user,
// @ts-ignore
user_id: response.data.user.id,
};
this.error = null;
});
} catch (error) {

View File

@@ -187,7 +187,7 @@ class CarrierStore {
: {}),
};
await languageInstance(lang as Language).patch(
const response = await languageInstance(lang as Language).patch(
`/carrier/${carrierId}`,
patchPayload
);
@@ -196,6 +196,26 @@ class CarrierStore {
this.carriers[lang as keyof Carriers].data.push(response.data);
});
}
this.createCarrierData = {
city_id: 0,
logo: "",
ru: {
full_name: "",
short_name: "",
slogan: "",
},
en: {
full_name: "",
short_name: "",
slogan: "",
},
zh: {
full_name: "",
short_name: "",
slogan: "",
},
};
};
editCarrierData = {
@@ -265,7 +285,9 @@ class CarrierStore {
...this.editCarrierData[lang],
city: cityName,
city_id: this.editCarrierData.city_id,
logo: this.editCarrierData.logo,
...(this.editCarrierData.logo
? { logo: this.editCarrierData.logo }
: {}),
});
runInAction(() => {

View File

@@ -284,41 +284,39 @@ class CityStore {
(country) => country.code === country_code
);
if (name) {
await languageInstance(language as Language).patch(`/city/${code}`, {
name,
country: country?.name || "",
country_code: country_code,
arms,
});
await languageInstance(language as Language).patch(`/city/${code}`, {
name,
country: country?.name || "",
country_code: country_code,
arms,
});
runInAction(() => {
if (this.city[code]) {
this.city[code][language as keyof CashedCities] = {
name,
country: country?.name || "",
country_code: country_code,
arms,
};
}
runInAction(() => {
if (this.city[code]) {
this.city[code][language as keyof CashedCities] = {
name,
country: country?.name || "",
country_code: country_code,
arms,
};
}
if (this.cities[language as keyof CashedCities]) {
this.cities[language as keyof CashedCities].data = this.cities[
language as keyof CashedCities
].data.map((city) =>
city.id === Number(code)
? {
id: city.id,
name,
country: country?.name || "",
country_code: country_code,
arms,
}
: city
);
}
});
}
if (this.cities[language as keyof CashedCities]) {
this.cities[language as keyof CashedCities].data = this.cities[
language as keyof CashedCities
].data.map((city) =>
city.id === Number(code)
? {
id: city.id,
name,
country: country?.name || "",
country_code: country_code,
arms,
}
: city
);
}
});
}
};
}

View File

@@ -68,14 +68,7 @@ class CountryStore {
};
getCountry = async (code: string, language: keyof CashedCountries) => {
if (
this.country[code]?.[language] &&
this.country[code][language] !== null
) {
return;
}
const response = await authInstance.get(`/country/${code}`);
const response = await languageInstance(language).get(`/country/${code}`);
runInAction(() => {
if (!this.country[code]) {

View File

@@ -1,5 +1,11 @@
// @shared/stores/createSightStore.ts
import { Language, authInstance, languageInstance, mediaStore } from "@shared";
import {
articlesStore,
Language,
authInstance,
languageInstance,
mediaStore,
} from "@shared";
import { makeAutoObservable, runInAction } from "mobx";
type MediaItem = {
@@ -162,6 +168,8 @@ class CreateSightStore {
media: mediaData,
});
});
return articleId; // Return the linked article ID
} catch (error) {
console.error("Error linking existing right article:", error);
throw error;
@@ -315,7 +323,18 @@ class CreateSightStore {
deleteLeftArticle = async (articleId: number) => {
/* ... your existing logic ... */
await authInstance.delete(`/article/${articleId}`);
// articlesStore.getArticles(languageStore.language); // If still needed
// articlesStore.getArticles(languageStore.language); // If still neede
runInAction(() => {
articlesStore.articles.ru = articlesStore.articles.ru.filter(
(article) => article.id !== articleId
);
articlesStore.articles.en = articlesStore.articles.en.filter(
(article) => article.id !== articleId
);
articlesStore.articles.zh = articlesStore.articles.zh.filter(
(article) => article.id !== articleId
);
});
this.unlinkLeftArticle();
};
@@ -352,6 +371,25 @@ class CreateSightStore {
body: "填写内容",
media: [],
};
articlesStore.articles.ru.push({
id: newLeftArticleId,
heading: "Новая левая статья",
body: "Заполните контентом",
service_name: "Новая левая статья",
});
articlesStore.articles.en.push({
id: newLeftArticleId,
heading: "New Left Article",
body: "Fill with content",
service_name: "New Left Article",
});
articlesStore.articles.zh.push({
id: newLeftArticleId,
heading: "新的左侧文章",
body: "填写内容",
service_name: "新的左侧文章",
});
});
return newLeftArticleId;
};

View File

@@ -1,5 +1,11 @@
// @shared/stores/editSightStore.ts
import { authInstance, Language, languageInstance, mediaStore } from "@shared";
import {
articlesStore,
authInstance,
Language,
languageInstance,
mediaStore,
} from "@shared";
import { makeAutoObservable, runInAction } from "mobx";
export type SightLanguageInfo = {
@@ -82,11 +88,7 @@ class EditSightStore {
hasLoadedCommon = false;
getSightInfo = async (id: number, language: Language) => {
if (this.sight[language].id === id) {
return;
}
const response = await authInstance.get(`/sight/${id}`);
const response = await languageInstance(language).get(`/sight/${id}`);
const data = response.data;
if (data.left_article != 0 && data.left_article != null) {
@@ -376,6 +378,18 @@ class EditSightStore {
deleteLeftArticle = async (id: number) => {
await authInstance.delete(`/article/${id}`);
runInAction(() => {
articlesStore.articles.ru = articlesStore.articles.ru.filter(
(article) => article.id !== id
);
articlesStore.articles.en = articlesStore.articles.en.filter(
(article) => article.id !== id
);
articlesStore.articles.zh = articlesStore.articles.zh.filter(
(article) => article.id !== id
);
});
this.sight.common.left_article = 0;
this.sight.ru.left.heading = "";
this.sight.en.left.heading = "";
@@ -556,6 +570,8 @@ class EditSightStore {
media: mediaIds.data,
});
});
return article_id; // Return the linked article ID
};
deleteRightArticleMedia = async (article_id: number, media_id: string) => {
@@ -639,6 +655,29 @@ class EditSightStore {
body: articleZhData.body,
media: [],
});
runInAction(() => {
articlesStore.articles.ru.push({
id: id,
heading: articleRuData.heading,
body: articleRuData.body,
service_name: articleRuData.heading,
});
articlesStore.articles.en.push({
id: id,
heading: articleEnData.heading,
body: articleEnData.body,
service_name: articleEnData.heading,
});
articlesStore.articles.zh.push({
id: id,
heading: articleZhData.heading,
body: articleZhData.body,
service_name: articleZhData.heading,
});
});
return id; // Return the ID of the newly created article
};
createLinkWithRightArticle = async (

View File

@@ -66,17 +66,41 @@ class RouteStore {
});
};
routeStations: Record<string, any[]> = {};
getRoute = async (id: number) => {
if (this.route[id]) return this.route[id];
const response = await authInstance.get(`/route/${id}`);
const stations = await authInstance.get(`/route/${id}/station`);
runInAction(() => {
this.route[id] = response.data;
this.routeStations[id] = stations.data;
});
return response.data;
};
setRouteStations = (routeId: number, stationId: number, data: any) => {
console.log(
this.routeStations[routeId],
stationId,
this.routeStations[routeId].find((station) => station.id === stationId)
);
this.routeStations[routeId] = this.routeStations[routeId]?.map((station) =>
station.id === stationId ? { ...station, ...data } : station
);
};
saveRouteStations = async (routeId: number, stationId: number) => {
await authInstance.patch(`/route/${routeId}/station`, {
...this.routeStations[routeId]?.find(
(station) => station.id === stationId
),
station_id: stationId,
});
};
editRouteData = {
carrier: "",
carrier_id: 0,
@@ -112,6 +136,21 @@ class RouteStore {
);
});
};
copyRouteAction = async (id: number) => {
const response = await authInstance.post(`/route/${id}/copy`);
console.log(response);
runInAction(() => {
this.routes.data = [...this.routes.data, response.data];
});
};
selectedStationId = 0;
setSelectedStationId = (id: number) => {
this.selectedStationId = id;
};
}
export const routeStore = new RouteStore();

View File

@@ -6,7 +6,6 @@ type Language = "ru" | "en" | "zh";
type StationLanguageData = {
name: string;
system_name: string;
description: string;
address: string;
loaded: boolean; // Indicates if this language's data has been loaded/modified
};
@@ -14,6 +13,7 @@ type StationLanguageData = {
type StationCommonData = {
city_id: number;
direction: boolean;
description: string;
icon: string;
latitude: number;
longitude: number;
@@ -102,21 +102,21 @@ class StationsStore {
ru: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
en: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
zh: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
@@ -124,6 +124,7 @@ class StationsStore {
city: "",
city_id: 0,
direction: false,
description: "",
icon: "",
latitude: 0,
longitude: 0,
@@ -147,21 +148,21 @@ class StationsStore {
ru: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
en: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
zh: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
@@ -169,6 +170,7 @@ class StationsStore {
city: "",
city_id: 0,
direction: false,
description: "",
icon: "",
latitude: 0,
longitude: 0,
@@ -229,21 +231,21 @@ class StationsStore {
ru: {
name: ruResponse.data.name,
system_name: ruResponse.data.system_name,
description: ruResponse.data.description,
address: ruResponse.data.address,
loaded: true,
},
en: {
name: enResponse.data.name,
system_name: enResponse.data.system_name,
description: enResponse.data.description,
address: enResponse.data.address,
loaded: true,
},
zh: {
name: zhResponse.data.name,
system_name: zhResponse.data.system_name,
description: zhResponse.data.description,
address: zhResponse.data.address,
loaded: true,
},
@@ -251,6 +253,7 @@ class StationsStore {
city: ruResponse.data.city,
city_id: ruResponse.data.city_id,
direction: ruResponse.data.direction,
description: ruResponse.data.description,
icon: ruResponse.data.icon,
latitude: ruResponse.data.latitude,
longitude: ruResponse.data.longitude,
@@ -286,7 +289,8 @@ class StationsStore {
};
for (const language of ["ru", "en", "zh"] as const) {
const { name, description, address } = this.editStationData[language];
const { name, address } = this.editStationData[language];
const description = this.editStationData.common.description;
const response = await languageInstance(language).patch(
`/station/${id}`,
{
@@ -323,7 +327,7 @@ class StationsStore {
...station,
name: response.data.name,
system_name: response.data.system_name,
description: response.data.description,
description: description || "",
address: response.data.address,
...commonDataPayload,
} as Station)
@@ -418,7 +422,8 @@ class StationsStore {
}
// First create station in Russian
const { name, description, address } = this.createStationData[language];
const { name, address } = this.createStationData[language];
const description = this.createStationData.common.description;
const response = await languageInstance(language).post("/station", {
name: name || "",
system_name: name || "", // system_name is often derived from name
@@ -437,7 +442,8 @@ class StationsStore {
for (const lang of ["ru", "en", "zh"].filter(
(lang) => lang !== language
) as Language[]) {
const { name, description, address } = this.createStationData[lang];
const { name, address } = this.createStationData[lang];
const description = this.createStationData.common.description;
const response = await languageInstance(lang).patch(
`/station/${stationId}`,
{
@@ -459,21 +465,18 @@ class StationsStore {
ru: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
en: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
zh: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
@@ -483,6 +486,7 @@ class StationsStore {
direction: false,
icon: "",
latitude: 0,
description: "",
longitude: 0,
offset_x: 0,
offset_y: 0,
@@ -509,21 +513,18 @@ class StationsStore {
ru: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
en: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
zh: {
name: "",
system_name: "",
description: "",
address: "",
loaded: false,
},
@@ -531,6 +532,7 @@ class StationsStore {
city: "",
city_id: 0,
direction: false,
description: "",
icon: "",
latitude: 0,
longitude: 0,

View File

@@ -24,8 +24,6 @@ class UserStore {
}
getUsers = async () => {
if (this.users.loaded) return;
const response = await authInstance.get("/user");
runInAction(() => {
@@ -35,7 +33,7 @@ class UserStore {
};
getUser = async (id: number) => {
if (this.user[id]) return;
if (this.user[id]) return this.user[id];
const response = await authInstance.get(`/user/${id}`);
runInAction(() => {

View File

@@ -35,8 +35,6 @@ class VehicleStore {
}
getVehicles = async () => {
if (this.vehicles.loaded) return;
const response = await languageInstance("ru").get(`/vehicle`);
runInAction(() => {