fix: properly sync category lists when article categories change
- Update patchArticleInLists reducer to add/remove articles from category lists - Articles are now correctly added to rootArticles and current category's articles - Articles are correctly removed when no longer in a category - Remove unnecessary loadCategoryTree dispatch (reducer handles sync now)
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
patchArticleInLists,
|
||||
removeArticleBySku,
|
||||
selectCategoryRootId,
|
||||
loadCategoryArticles,
|
||||
selectCurrentCategoryId,
|
||||
} from '../../store/categorySlice';
|
||||
|
||||
import ArticleTileTab from './ArticleTileTab';
|
||||
@@ -33,6 +35,7 @@ export default function ArticleView({
|
||||
const dispatch = useDispatch();
|
||||
const categories = useSelector((state) => state.category.categories);
|
||||
const rootCategoryId = useSelector(selectCategoryRootId);
|
||||
const currentCategoryId = useSelector(selectCurrentCategoryId);
|
||||
|
||||
const syncCategoryListPhoto = (next) => {
|
||||
const photo = primaryPhoto(next);
|
||||
@@ -57,6 +60,12 @@ export default function ArticleView({
|
||||
categoryIds: next.categoryIds,
|
||||
}),
|
||||
);
|
||||
|
||||
// Reload articles to reflect the update
|
||||
// The reducer handles removing from lists where article no longer belongs
|
||||
if (currentCategoryId != null && String(currentCategoryId) !== String(rootCategoryId)) {
|
||||
dispatch(loadCategoryArticles(currentCategoryId));
|
||||
}
|
||||
};
|
||||
|
||||
const handleArticleDeleted = () => {
|
||||
|
||||
Reference in New Issue
Block a user