feat: DND for Articles
This commit is contained in:
@ -586,6 +586,12 @@ class CreateSightStore {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
updateRightArticles = async (articles: any[], language: Language) => {
|
||||
runInAction(() => {
|
||||
this.sight[language].right = articles;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const createSightStore = new CreateSightStore();
|
||||
|
@ -121,35 +121,32 @@ class EditSightStore {
|
||||
let responseEn = await languageInstance("en").get(`/sight/${id}/article`);
|
||||
let responseZh = await languageInstance("zh").get(`/sight/${id}/article`);
|
||||
|
||||
// Function to fetch media for a given set of articles
|
||||
const fetchMediaForArticles = async (articles: any[]) => {
|
||||
const articlesWithMedia = [];
|
||||
for (const article of articles) {
|
||||
const responseMedia = await authInstance.get(
|
||||
`/article/${article.id}/media`
|
||||
);
|
||||
articlesWithMedia.push({
|
||||
...article,
|
||||
media: responseMedia.data,
|
||||
});
|
||||
}
|
||||
return articlesWithMedia;
|
||||
};
|
||||
// Create a map of article IDs to their media
|
||||
const mediaMap = new Map();
|
||||
for (const article of responseRu.data) {
|
||||
const responseMedia = await authInstance.get(
|
||||
`/article/${article.id}/media`
|
||||
);
|
||||
mediaMap.set(article.id, responseMedia.data);
|
||||
}
|
||||
|
||||
// Fetch media for articles in each language
|
||||
const ruArticlesWithMedia = await fetchMediaForArticles(responseRu.data);
|
||||
const enArticlesWithMedia = await fetchMediaForArticles(responseEn.data);
|
||||
const zhArticlesWithMedia = await fetchMediaForArticles(responseZh.data);
|
||||
// Function to add media to articles
|
||||
const addMediaToArticles = (articles: any[]) => {
|
||||
return articles.map((article) => ({
|
||||
...article,
|
||||
media: mediaMap.get(article.id),
|
||||
}));
|
||||
};
|
||||
|
||||
const data = {
|
||||
ru: {
|
||||
right: ruArticlesWithMedia,
|
||||
right: addMediaToArticles(responseRu.data),
|
||||
},
|
||||
en: {
|
||||
right: enArticlesWithMedia,
|
||||
right: addMediaToArticles(responseEn.data),
|
||||
},
|
||||
zh: {
|
||||
right: zhArticlesWithMedia,
|
||||
right: addMediaToArticles(responseZh.data),
|
||||
},
|
||||
};
|
||||
|
||||
@ -673,6 +670,16 @@ class EditSightStore {
|
||||
this.sight[language].right[index].heading = heading;
|
||||
this.sight[language].right[index].body = body;
|
||||
};
|
||||
|
||||
updateRightArticles = async (articles: any[], language: Language) => {
|
||||
this.sight[language].right = articles;
|
||||
const articleIdsInObject = articles.map((article) => ({
|
||||
id: article.id,
|
||||
}));
|
||||
await authInstance.post(`/sight/${this.sight.common.id}/article/order`, {
|
||||
articles: articleIdsInObject,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const editSightStore = new EditSightStore();
|
||||
|
Reference in New Issue
Block a user