feat: Sight Page update
This commit is contained in:
@ -17,6 +17,8 @@ class CityStore {
|
||||
}
|
||||
|
||||
getCities = async () => {
|
||||
if (this.cities.length !== 0) return;
|
||||
|
||||
const response = await authInstance.get("/city");
|
||||
runInAction(() => {
|
||||
this.cities = response.data;
|
||||
|
449
src/shared/store/CreateSightStore/index.tsx
Normal file
449
src/shared/store/CreateSightStore/index.tsx
Normal file
@ -0,0 +1,449 @@
|
||||
// @shared/stores/createSightStore.ts
|
||||
import {
|
||||
Language,
|
||||
authInstance,
|
||||
languageInstance,
|
||||
articlesStore,
|
||||
languageStore,
|
||||
mediaStore,
|
||||
} from "@shared";
|
||||
import { makeAutoObservable } from "mobx";
|
||||
|
||||
type SightLanguageInfo = {
|
||||
name: string;
|
||||
address: string;
|
||||
left: {
|
||||
heading: string;
|
||||
body: string;
|
||||
media: {
|
||||
id: string;
|
||||
filename: string;
|
||||
media_name?: string;
|
||||
media_type: number;
|
||||
}[];
|
||||
};
|
||||
right: { heading: string; body: string }[];
|
||||
};
|
||||
|
||||
type SightCommonInfo = {
|
||||
id: number;
|
||||
city_id: number;
|
||||
city: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
thumbnail: string | null;
|
||||
watermark_lu: string | null;
|
||||
watermark_rd: string | null;
|
||||
left_article: number;
|
||||
preview_media: string | null;
|
||||
video_preview: string | null;
|
||||
};
|
||||
|
||||
type SightBaseInfo = SightCommonInfo & {
|
||||
[key in Language]: SightLanguageInfo;
|
||||
};
|
||||
|
||||
class CreateSightStore {
|
||||
sight: SightBaseInfo = {
|
||||
id: 0,
|
||||
city_id: 0,
|
||||
city: "",
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
thumbnail: null,
|
||||
watermark_lu: null,
|
||||
watermark_rd: null,
|
||||
left_article: 0,
|
||||
preview_media: null,
|
||||
video_preview: null,
|
||||
|
||||
ru: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
en: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
zh: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
};
|
||||
|
||||
uploadMediaOpen = false;
|
||||
setUploadMediaOpen = (open: boolean) => {
|
||||
this.uploadMediaOpen = open;
|
||||
};
|
||||
fileToUpload: File | null = null;
|
||||
setFileToUpload = (file: File | null) => {
|
||||
this.fileToUpload = file;
|
||||
};
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
createNewRightArticle = () => {
|
||||
this.sight.ru.right.push({
|
||||
heading: "Введите русский заголовок",
|
||||
body: "Введите русский текст",
|
||||
});
|
||||
this.sight.en.right.push({
|
||||
heading: "Enter the English heading",
|
||||
body: "Enter the English text",
|
||||
});
|
||||
this.sight.zh.right.push({
|
||||
heading: "Введите китайский заголовок",
|
||||
body: "Введите китайский текст",
|
||||
});
|
||||
};
|
||||
|
||||
updateLeftInfo = (language: Language, heading: string, body: string) => {
|
||||
this.sight[language].left.heading = heading;
|
||||
this.sight[language].left.body = body;
|
||||
};
|
||||
|
||||
clearCreateSight = () => {
|
||||
this.sight = {
|
||||
id: 0,
|
||||
city_id: 0,
|
||||
city: "",
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
thumbnail: null,
|
||||
watermark_lu: null,
|
||||
watermark_rd: null,
|
||||
left_article: 0,
|
||||
preview_media: null,
|
||||
video_preview: null,
|
||||
|
||||
ru: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
|
||||
en: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
|
||||
zh: {
|
||||
name: "",
|
||||
address: "",
|
||||
left: { heading: "", body: "", media: [] },
|
||||
right: [],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
updateSightInfo = (
|
||||
content: Partial<SightLanguageInfo | SightCommonInfo>,
|
||||
language?: Language
|
||||
) => {
|
||||
if (language) {
|
||||
this.sight[language] = {
|
||||
...this.sight[language],
|
||||
...content,
|
||||
};
|
||||
} else {
|
||||
this.sight = {
|
||||
...this.sight,
|
||||
...content,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
unlinkLeftArticle = () => {
|
||||
this.sight.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 = "";
|
||||
};
|
||||
|
||||
updateLeftArticle = async (articleId: number) => {
|
||||
this.sight.left_article = articleId;
|
||||
|
||||
if (articleId) {
|
||||
const ruArticleData = await languageInstance("ru").get(
|
||||
`/article/${articleId}`
|
||||
);
|
||||
const enArticleData = await languageInstance("en").get(
|
||||
`/article/${articleId}`
|
||||
);
|
||||
const zhArticleData = await languageInstance("zh").get(
|
||||
`/article/${articleId}`
|
||||
);
|
||||
|
||||
this.sight.ru.left.heading = ruArticleData.data.heading;
|
||||
this.sight.en.left.heading = enArticleData.data.heading;
|
||||
this.sight.zh.left.heading = zhArticleData.data.heading;
|
||||
|
||||
this.sight.ru.left.body = ruArticleData.data.body;
|
||||
this.sight.en.left.body = enArticleData.data.body;
|
||||
this.sight.zh.left.body = zhArticleData.data.body;
|
||||
} else {
|
||||
this.sight.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 = "";
|
||||
}
|
||||
};
|
||||
|
||||
deleteLeftArticle = async (articleId: number) => {
|
||||
await authInstance.delete(`/article/${articleId}`);
|
||||
articlesStore.getArticles(languageStore.language);
|
||||
this.sight.left_article = 0;
|
||||
this.sight.ru.left.heading = "";
|
||||
this.sight.en.left.heading = "";
|
||||
this.sight.zh.left.heading = "";
|
||||
this.sight.ru.left.body = "";
|
||||
};
|
||||
|
||||
createLeftArticle = async () => {
|
||||
const response = await languageInstance("ru").post("/article", {
|
||||
heading: "Новая статья",
|
||||
body: "Заполните статью контентом",
|
||||
});
|
||||
|
||||
this.sight.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 = "";
|
||||
};
|
||||
|
||||
createSight = async (language: Language) => {
|
||||
const rightArticles: number[] = [];
|
||||
|
||||
if (this.sight.left_article !== 0) {
|
||||
if (this.sight.left_article == 10000000) {
|
||||
const response = await languageInstance("ru").post("/article", {
|
||||
heading: this.sight.ru.left.heading,
|
||||
body: this.sight.ru.left.body,
|
||||
});
|
||||
const { id } = response.data;
|
||||
await languageInstance("en").patch(`/article/${id}`, {
|
||||
heading: this.sight.en.left.heading,
|
||||
body: this.sight.en.left.body,
|
||||
});
|
||||
|
||||
await languageInstance("zh").patch(`/article/${id}`, {
|
||||
heading: this.sight.zh.left.heading,
|
||||
body: this.sight.zh.left.body,
|
||||
});
|
||||
this.sight.left_article = id;
|
||||
} else {
|
||||
await languageInstance("ru").patch(
|
||||
`/article/${this.sight.left_article}`,
|
||||
{
|
||||
heading: this.sight.ru.left.heading,
|
||||
body: this.sight.ru.left.body,
|
||||
}
|
||||
);
|
||||
|
||||
await languageInstance("en").patch(
|
||||
`/article/${this.sight.left_article}`,
|
||||
{
|
||||
heading: this.sight.en.left.heading,
|
||||
body: this.sight.en.left.body,
|
||||
}
|
||||
);
|
||||
|
||||
await languageInstance("zh").patch(
|
||||
`/article/${this.sight.left_article}`,
|
||||
{
|
||||
heading: this.sight.zh.left.heading,
|
||||
body: this.sight.zh.left.body,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.sight[language].right.map(async (article, index) => {
|
||||
try {
|
||||
const response = await languageInstance(language).post("/article", {
|
||||
heading: article.heading,
|
||||
body: article.body,
|
||||
});
|
||||
const { id } = response.data;
|
||||
const anotherLanguages = ["en", "zh", "ru"].filter(
|
||||
(lang) => lang !== language
|
||||
);
|
||||
await languageInstance(anotherLanguages[0] as Language).patch(
|
||||
`/article/${id}`,
|
||||
{
|
||||
heading:
|
||||
this.sight[anotherLanguages[0] as Language].right[index].heading,
|
||||
body: this.sight[anotherLanguages[0] as Language].right[index].body,
|
||||
}
|
||||
);
|
||||
await languageInstance(anotherLanguages[1] as Language).patch(
|
||||
`/article/${id}`,
|
||||
{
|
||||
heading:
|
||||
this.sight[anotherLanguages[1] as Language].right[index].heading,
|
||||
body: this.sight[anotherLanguages[1] as Language].right[index].body,
|
||||
}
|
||||
);
|
||||
rightArticles.push(id);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
const response = await languageInstance(language).post("/sight", {
|
||||
city_id: this.sight.city_id,
|
||||
city: this.sight.city,
|
||||
latitude: this.sight.latitude,
|
||||
longitude: this.sight.longitude,
|
||||
name: this.sight[language].name,
|
||||
address: this.sight[language].address,
|
||||
thumbnail: this.sight.thumbnail ?? null,
|
||||
watermark_lu: this.sight.watermark_lu,
|
||||
watermark_rd: this.sight.watermark_rd,
|
||||
left_article: this.sight.left_article,
|
||||
preview_media: this.sight.preview_media,
|
||||
video_preview: this.sight.video_preview,
|
||||
});
|
||||
|
||||
const { id } = response.data;
|
||||
const anotherLanguages = ["en", "zh", "ru"].filter(
|
||||
(lang) => lang !== language
|
||||
);
|
||||
|
||||
await languageInstance(anotherLanguages[0] as Language).patch(
|
||||
`/sight/${id}`,
|
||||
{
|
||||
city_id: this.sight.city_id,
|
||||
city: this.sight.city,
|
||||
latitude: this.sight.latitude,
|
||||
longitude: this.sight.longitude,
|
||||
name: this.sight[anotherLanguages[0] as Language as Language].name,
|
||||
address:
|
||||
this.sight[anotherLanguages[0] as Language as Language].address,
|
||||
thumbnail: this.sight.thumbnail ?? null,
|
||||
watermark_lu: this.sight.watermark_lu,
|
||||
watermark_rd: this.sight.watermark_rd,
|
||||
left_article: this.sight.left_article,
|
||||
preview_media: this.sight.preview_media,
|
||||
video_preview: this.sight.video_preview,
|
||||
}
|
||||
);
|
||||
await languageInstance(anotherLanguages[1] as Language).patch(
|
||||
`/sight/${id}`,
|
||||
{
|
||||
city_id: this.sight.city_id,
|
||||
city: this.sight.city,
|
||||
latitude: this.sight.latitude,
|
||||
longitude: this.sight.longitude,
|
||||
name: this.sight[anotherLanguages[1] as Language].name,
|
||||
address: this.sight[anotherLanguages[1] as Language].address,
|
||||
thumbnail: this.sight.thumbnail ?? null,
|
||||
watermark_lu: this.sight.watermark_lu,
|
||||
watermark_rd: this.sight.watermark_rd,
|
||||
left_article: this.sight.left_article,
|
||||
preview_media: this.sight.preview_media,
|
||||
video_preview: this.sight.video_preview,
|
||||
}
|
||||
);
|
||||
|
||||
rightArticles.map(async (article, index) => {
|
||||
await authInstance.post(`/sight/${id}/article`, {
|
||||
article_id: article,
|
||||
page_num: index + 1,
|
||||
});
|
||||
});
|
||||
console.log("created");
|
||||
};
|
||||
|
||||
updateRightArticleInfo = (
|
||||
index: number,
|
||||
language: Language,
|
||||
heading: string,
|
||||
body: string
|
||||
) => {
|
||||
this.sight[language].right[index].heading = heading;
|
||||
this.sight[language].right[index].body = body;
|
||||
};
|
||||
|
||||
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);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
createLinkWithArticle = async (media: {
|
||||
id: string;
|
||||
filename: string;
|
||||
media_name?: string;
|
||||
media_type: number;
|
||||
}) => {
|
||||
await authInstance.post(`/article/${this.sight.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 createSightStore = new CreateSightStore();
|
@ -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();
|
||||
|
@ -8,3 +8,4 @@ export * from "./CityStore";
|
||||
export * from "./ArticlesStore";
|
||||
export * from "./EditSightStore";
|
||||
export * from "./MediaStore";
|
||||
export * from "./CreateSightStore";
|
||||
|
Reference in New Issue
Block a user