feat: Sight Page update

This commit is contained in:
2025-06-01 23:18:21 +03:00
parent 87386c6a73
commit a8777a974a
26 changed files with 3460 additions and 727 deletions

View File

@@ -1,26 +1,31 @@
// @shared/stores/editSightStore.ts
import { authInstance, Language } from "@shared";
import { authInstance, Language, languageInstance, mediaStore } from "@shared";
import { makeAutoObservable, runInAction } from "mobx";
export type SightLanguageInfo = {
id: number;
name: string;
address: string;
left: { heading: string; body: string };
left: {
heading: string;
body: string;
media: { id: string; media_type: number; filename: string }[];
};
right: { heading: string; body: string }[];
};
export type SightCommonInfo = {
id: number;
city_id: number;
city: string;
latitude: number;
longitude: number;
thumbnail: string;
watermark_lu: string;
watermark_rd: string;
thumbnail: string | null;
watermark_lu: string | null;
watermark_rd: string | null;
left_article: number;
preview_media: string;
video_preview: string;
preview_media: string | null;
video_preview: string | null;
};
export type SightBaseInfo = {
@@ -31,36 +36,37 @@ export type SightBaseInfo = {
class EditSightStore {
sight: SightBaseInfo = {
common: {
id: 0,
city_id: 0,
city: "",
latitude: 0,
longitude: 0,
thumbnail: "",
watermark_lu: "",
watermark_rd: "",
thumbnail: null,
watermark_lu: null,
watermark_rd: null,
left_article: 0,
preview_media: "",
video_preview: "",
preview_media: null,
video_preview: null,
},
ru: {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
en: {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
zh: {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
};
@@ -77,6 +83,9 @@ class EditSightStore {
const response = await authInstance.get(`/sight/${id}`);
const data = response.data;
if (data.left_article != 0) {
await this.getLeftArticle(data.left_article);
}
runInAction(() => {
// Обновляем языковую часть
@@ -101,25 +110,62 @@ class EditSightStore {
this.sight[language].left.body = body;
};
getRightArticles = async (id: number) => {
const responseRu = await languageInstance("ru").get(`/sight/${id}/article`);
const responseEn = await languageInstance("en").get(`/sight/${id}/article`);
const responseZh = await languageInstance("zh").get(`/sight/${id}/article`);
const data = {
ru: {
right: responseRu.data,
},
en: {
right: responseEn.data,
},
zh: {
right: responseZh.data,
},
};
runInAction(() => {
this.sight = {
...this.sight,
ru: {
...this.sight.ru,
right: data.ru.right,
},
en: {
...this.sight.en,
right: data.en.right,
},
zh: {
...this.sight.zh,
right: data.zh.right,
},
};
});
};
clearSightInfo = () => {
this.sight = {
common: {
id: 0,
city_id: 0,
city: "",
latitude: 0,
longitude: 0,
thumbnail: "",
watermark_lu: "",
watermark_rd: "",
thumbnail: null,
watermark_lu: null,
watermark_rd: null,
left_article: 0,
preview_media: "",
video_preview: "",
preview_media: null,
video_preview: null,
},
ru: {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
@@ -127,7 +173,7 @@ class EditSightStore {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
@@ -135,7 +181,7 @@ class EditSightStore {
id: 0,
name: "",
address: "",
left: { heading: "", body: "" },
left: { heading: "", body: "", media: [] },
right: [],
},
};
@@ -158,6 +204,244 @@ class EditSightStore {
};
}
};
unlinkLeftArticle = async () => {
this.sight.common.left_article = 0;
this.sight.ru.left.heading = "";
this.sight.en.left.heading = "";
this.sight.zh.left.heading = "";
this.sight.ru.left.body = "";
this.sight.en.left.body = "";
this.sight.zh.left.body = "";
};
updateSight = async () => {
let createdLeftArticleId = this.sight.common.left_article;
if (this.sight.common.left_article == 10000000) {
const response = await languageInstance("ru").post(`/article`, {
heading: this.sight.ru.left.heading,
body: this.sight.ru.left.body,
});
createdLeftArticleId = response.data.id;
await languageInstance("en").patch(`/article/${createdLeftArticleId}`, {
heading: this.sight.en.left.heading,
body: this.sight.en.left.body,
});
await languageInstance("zh").patch(`/article/${createdLeftArticleId}`, {
heading: this.sight.zh.left.heading,
body: this.sight.zh.left.body,
});
this.sight.common.left_article = createdLeftArticleId;
} else if (this.sight.common.left_article != 0) {
await languageInstance("ru").patch(
`/article/${this.sight.common.left_article}`,
{
heading: this.sight.ru.left.heading,
body: this.sight.ru.left.body,
}
);
await languageInstance("en").patch(
`/article/${this.sight.common.left_article}`,
{
heading: this.sight.en.left.heading,
body: this.sight.en.left.body,
}
);
await languageInstance("zh").patch(
`/article/${this.sight.common.left_article}`,
{
heading: this.sight.zh.left.heading,
body: this.sight.zh.left.body,
}
);
}
await languageInstance("ru").patch(`/sight/${this.sight.common.id}`, {
...this.sight.common,
name: this.sight.ru.name,
address: this.sight.ru.address,
left_article: createdLeftArticleId,
});
await languageInstance("en").patch(`/sight/${this.sight.common.id}`, {
...this.sight.common,
name: this.sight.en.name,
address: this.sight.en.address,
left_article: createdLeftArticleId,
});
await languageInstance("zh").patch(`/sight/${this.sight.common.id}`, {
...this.sight.common,
name: this.sight.zh.name,
address: this.sight.zh.address,
left_article: createdLeftArticleId,
});
if (this.sight.common.left_article == 0) {
return;
}
// await languageInstance("ru").patch(
// `/sight/${this.sight.common.left_article}/article`,
// {
// heading: this.sight.ru.left.heading,
// body: this.sight.ru.left.body,
// }
// );
// await languageInstance("en").patch(
// `/sight/${this.sight.common.left_article}/article`,
// {
// heading: this.sight.en.left.heading,
// body: this.sight.en.left.body,
// }
// );
// await languageInstance("zh").patch(
// `/sight/${this.sight.common.left_article}/article`,
// {
// heading: this.sight.zh.left.heading,
// body: this.sight.zh.left.body,
// }
// );
};
getLeftArticle = async (id: number) => {
const response = await languageInstance("ru").get(`/article/${id}`);
const responseEn = await languageInstance("en").get(`/article/${id}`);
const responseZh = await languageInstance("zh").get(`/article/${id}`);
const mediaIds = await authInstance.get(`/article/${id}/media`);
runInAction(() => {
this.sight.ru.left = {
heading: response.data.heading,
body: response.data.body,
media: mediaIds.data,
};
this.sight.en.left = {
heading: responseEn.data.heading,
body: responseEn.data.body,
media: mediaIds.data,
};
this.sight.zh.left = {
heading: responseZh.data.heading,
body: responseZh.data.body,
media: mediaIds.data,
};
});
};
deleteLeftArticle = async (id: number) => {
await authInstance.delete(`/article/${id}`);
this.sight.common.left_article = 0;
this.sight.ru.left.heading = "";
this.sight.en.left.heading = "";
this.sight.zh.left.heading = "";
this.sight.ru.left.body = "";
this.sight.en.left.body = "";
this.sight.zh.left.body = "";
};
createLeftArticle = async () => {
const response = await languageInstance("ru").post(`/article`, {
heading: "",
body: "",
});
this.sight.common.left_article = response.data.id;
this.sight.ru.left.heading = "";
this.sight.en.left.heading = "";
this.sight.zh.left.heading = "";
this.sight.ru.left.body = "";
this.sight.en.left.body = "";
this.sight.zh.left.body = "";
};
deleteMedia = async (article_id: number, media_id: string) => {
await authInstance.delete(`/article/${article_id}/media`, {
data: {
media_id: media_id,
},
});
this.sight.ru.left.media = this.sight.ru.left.media.filter(
(media) => media.id !== media_id
);
this.sight.en.left.media = this.sight.en.left.media.filter(
(media) => media.id !== media_id
);
this.sight.zh.left.media = this.sight.zh.left.media.filter(
(media) => media.id !== media_id
);
};
uploadMediaOpen = false;
setUploadMediaOpen = (open: boolean) => {
this.uploadMediaOpen = open;
};
fileToUpload: File | null = null;
setFileToUpload = (file: File | null) => {
this.fileToUpload = file;
};
uploadMedia = async (
filename: string,
type: number,
file: File,
media_name?: string
) => {
const formData = new FormData();
formData.append("file", file);
formData.append("filename", filename);
if (media_name) {
formData.append("media_name", media_name);
}
formData.append("type", type.toString());
try {
const response = await authInstance.post(`/media`, formData);
this.fileToUpload = null;
this.uploadMediaOpen = false;
mediaStore.getMedia();
return {
id: response.data.id,
filename: filename,
media_name: media_name,
media_type: type,
};
} catch (error) {
console.log(error);
}
};
createLinkWithArticle = async (media: {
id: string;
filename: string;
media_name?: string;
media_type: number;
}) => {
await authInstance.post(
`/article/${this.sight.common.left_article}/media`,
{
media_id: media.id,
media_order: 1,
}
);
this.sight.ru.left.media.unshift({
id: media.id,
media_type: media.media_type,
filename: media.filename,
});
this.sight.en.left.media.unshift({
id: media.id,
media_type: media.media_type,
filename: media.filename,
});
this.sight.zh.left.media.unshift({
id: media.id,
media_type: media.media_type,
filename: media.filename,
});
};
}
export const editSightStore = new EditSightStore();