feat: cache delete + empty snapshot + route page
This commit is contained in:
@@ -40,6 +40,7 @@ type SightCommonInfo = {
|
||||
left_article: number;
|
||||
preview_media: string | null;
|
||||
video_preview: string | null;
|
||||
preview_font_size?: number;
|
||||
};
|
||||
|
||||
type SightBaseInfo = SightCommonInfo & {
|
||||
@@ -184,7 +185,7 @@ class CreateSightStore {
|
||||
index: number,
|
||||
language: Language,
|
||||
heading: string,
|
||||
body: string
|
||||
body: string,
|
||||
) => {
|
||||
if (this.sight[language].right[index]) {
|
||||
this.sight[language].right[index].heading = heading;
|
||||
@@ -195,13 +196,13 @@ class CreateSightStore {
|
||||
unlinkRightAritcle = (articleId: number) => {
|
||||
runInAction(() => {
|
||||
this.sight.ru.right = this.sight.ru.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
this.sight.en.right = this.sight.en.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
this.sight.zh.right = this.sight.zh.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -211,13 +212,13 @@ class CreateSightStore {
|
||||
await authInstance.delete(`/article/${articleId}`);
|
||||
runInAction(() => {
|
||||
this.sight.ru.right = this.sight.ru.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
this.sight.en.right = this.sight.en.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
this.sight.zh.right = this.sight.zh.right.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -235,7 +236,7 @@ class CreateSightStore {
|
||||
runInAction(() => {
|
||||
(["ru", "en", "zh"] as Language[]).forEach((lang) => {
|
||||
const article = this.sight[lang].right.find(
|
||||
(a) => a.id === articleId
|
||||
(a) => a.id === articleId,
|
||||
);
|
||||
if (article) {
|
||||
if (!article.media) article.media = [];
|
||||
@@ -257,7 +258,7 @@ class CreateSightStore {
|
||||
runInAction(() => {
|
||||
(["ru", "en", "zh"] as Language[]).forEach((lang) => {
|
||||
const article = this.sight[lang].right.find(
|
||||
(a) => a.id === articleId
|
||||
(a) => a.id === articleId,
|
||||
);
|
||||
if (article && article.media) {
|
||||
article.media = article.media.filter((m) => m.id !== mediaId);
|
||||
@@ -322,13 +323,13 @@ class CreateSightStore {
|
||||
|
||||
runInAction(() => {
|
||||
articlesStore.articles.ru = articlesStore.articles.ru.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
articlesStore.articles.en = articlesStore.articles.en.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
articlesStore.articles.zh = articlesStore.articles.zh.filter(
|
||||
(article) => article.id !== articleId
|
||||
(article) => article.id !== articleId,
|
||||
);
|
||||
});
|
||||
this.unlinkLeftArticle();
|
||||
@@ -431,7 +432,7 @@ class CreateSightStore {
|
||||
|
||||
updateSightInfo = (
|
||||
content: Partial<SightLanguageInfo | SightCommonInfo>,
|
||||
language?: Language
|
||||
language?: Language,
|
||||
) => {
|
||||
this.needLeaveAgree = true;
|
||||
if (language) {
|
||||
@@ -464,15 +465,15 @@ class CreateSightStore {
|
||||
) {
|
||||
await languageInstance("ru").patch(
|
||||
`/article/${this.sight.left_article}`,
|
||||
{ heading: this.sight.ru.left.heading, body: this.sight.ru.left.body }
|
||||
{ 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 }
|
||||
{ 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 }
|
||||
{ heading: this.sight.zh.left.heading, body: this.sight.zh.left.body },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -488,7 +489,7 @@ class CreateSightStore {
|
||||
}
|
||||
}
|
||||
const rightArticleIdsForLink = this.sight[primaryLanguage].right.map(
|
||||
(a) => a.id
|
||||
(a) => a.id,
|
||||
);
|
||||
|
||||
const sightPayload = {
|
||||
@@ -508,16 +509,17 @@ class CreateSightStore {
|
||||
left_article: finalLeftArticleId === 0 ? null : finalLeftArticleId,
|
||||
preview_media: this.sight.preview_media,
|
||||
video_preview: this.sight.video_preview,
|
||||
preview_font_size: this.sight.preview_font_size,
|
||||
};
|
||||
|
||||
const response = await languageInstance(primaryLanguage).post(
|
||||
"/sight",
|
||||
sightPayload
|
||||
sightPayload,
|
||||
);
|
||||
const newSightId = response.data.id;
|
||||
|
||||
const otherLanguages = (["ru", "en", "zh"] as Language[]).filter(
|
||||
(l) => l !== primaryLanguage
|
||||
(l) => l !== primaryLanguage,
|
||||
);
|
||||
for (const lang of otherLanguages) {
|
||||
await languageInstance(lang).patch(`/sight/${newSightId}`, {
|
||||
@@ -547,7 +549,10 @@ class CreateSightStore {
|
||||
});
|
||||
}
|
||||
|
||||
this.needLeaveAgree = false;
|
||||
runInAction(() => {
|
||||
this.needLeaveAgree = false;
|
||||
});
|
||||
|
||||
return newSightId;
|
||||
};
|
||||
|
||||
@@ -555,7 +560,7 @@ class CreateSightStore {
|
||||
filename: string,
|
||||
type: number,
|
||||
file: File,
|
||||
media_name?: string
|
||||
media_name?: string,
|
||||
): Promise<MediaItem> => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
@@ -585,7 +590,7 @@ class CreateSightStore {
|
||||
createLinkWithLeftArticle = async (media: MediaItem) => {
|
||||
if (!this.sight.left_article || this.sight.left_article === 10000000) {
|
||||
console.warn(
|
||||
"Left article not selected or is a placeholder. Cannot link media yet."
|
||||
"Left article not selected or is a placeholder. Cannot link media yet.",
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -618,7 +623,7 @@ class CreateSightStore {
|
||||
(["ru", "en", "zh"] as Language[]).forEach((lang) => {
|
||||
if (this.sight[lang].left.media) {
|
||||
this.sight[lang].left.media = this.sight[lang].left.media.filter(
|
||||
(m) => m.id !== mediaId
|
||||
(m) => m.id !== mediaId,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -634,13 +639,13 @@ class CreateSightStore {
|
||||
|
||||
const sortArticles = (existing: any[]) => {
|
||||
const articleMap = new Map(
|
||||
existing.map((article) => [article.id, article])
|
||||
existing.map((article) => [article.id, article]),
|
||||
);
|
||||
return articlesIds
|
||||
.map((id) => articleMap.get(id))
|
||||
.filter(
|
||||
(article): article is (typeof existing)[number] =>
|
||||
article !== undefined
|
||||
article !== undefined,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user