feat: Select article list in sight

This commit is contained in:
2025-05-31 06:35:05 +03:00
parent 5ef61bcef4
commit 2e6917406e
21 changed files with 899 additions and 498 deletions

View File

@ -1,4 +1,4 @@
import { authInstance } from "@shared";
import { authInstance, languageInstance, languageStore } from "@shared";
import { makeAutoObservable, runInAction } from "mobx";
export type Language = "ru" | "en" | "zh";
@ -8,7 +8,6 @@ export type MultilingualContent = {
name: string;
description: string;
address: string;
// Add other fields that need to be multilingual
};
};
@ -28,10 +27,22 @@ export type Sight = {
video_preview: string | null;
};
export type CreateSight = {
[key in Language]: {
name: string;
description: string;
address: string;
};
};
class SightsStore {
sights: Sight[] = [];
sight: Sight | null = null;
cachedMultilingualContent: MultilingualContent | null = null;
createSight: CreateSight = {
ru: { name: "", description: "", address: "" },
en: { name: "", description: "", address: "" },
zh: { name: "", description: "", address: "" },
};
constructor() {
makeAutoObservable(this);
@ -52,34 +63,96 @@ class SightsStore {
});
};
setCachedMultilingualContent = (content: MultilingualContent) => {
createSightAction = async (
city: number,
coordinates: { latitude: number; longitude: number }
) => {
const id = (
await authInstance.post("/sight", {
name: this.createSight[languageStore.language].name,
description: this.createSight[languageStore.language].description,
address: this.createSight[languageStore.language].address,
city_id: city,
latitude: coordinates.latitude,
longitude: coordinates.longitude,
})
).data.id;
const anotherLanguages = ["ru", "en", "zh"].filter(
(language) => language !== languageStore.language
);
await languageInstance(anotherLanguages[0] as Language).patch(
`/sight/${id}`,
{
name: this.createSight[anotherLanguages[0] as Language].name,
description:
this.createSight[anotherLanguages[0] as Language].description,
address: this.createSight[anotherLanguages[0] as Language].address,
city_id: city,
latitude: coordinates.latitude,
longitude: coordinates.longitude,
}
);
await languageInstance(anotherLanguages[1] as Language).patch(
`/sight/${id}`,
{
name: this.createSight[anotherLanguages[1] as Language].name,
description:
this.createSight[anotherLanguages[1] as Language].description,
address: this.createSight[anotherLanguages[1] as Language].address,
city_id: city,
latitude: coordinates.latitude,
longitude: coordinates.longitude,
}
);
runInAction(() => {
this.cachedMultilingualContent = content;
this.createSight = {
ru: { name: "", description: "", address: "" },
en: { name: "", description: "", address: "" },
zh: { name: "", description: "", address: "" },
};
});
};
setCreateSight = (content: CreateSight) => {
runInAction(() => {
this.createSight = content;
});
};
updateCachedLanguageContent = (
updateCreateSight = (
language: Language,
content: Partial<MultilingualContent[Language]>
content: Partial<CreateSight[Language]>
) => {
runInAction(() => {
if (!this.cachedMultilingualContent) {
this.cachedMultilingualContent = {
ru: { name: "", description: "", address: "" },
en: { name: "", description: "", address: "" },
zh: { name: "", description: "", address: "" },
};
}
this.cachedMultilingualContent[language] = {
...this.cachedMultilingualContent[language],
this.createSight[language] = {
...this.createSight[language],
...content,
};
});
};
clearCachedMultilingualContent = () => {
clearCreateSight = () => {
runInAction(() => {
this.cachedMultilingualContent = null;
this.createSight = {
ru: {
name: "",
description: "",
address: "",
},
en: {
name: "",
description: "",
address: "",
},
zh: {
name: "",
description: "",
address: "",
},
};
});
};
}