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:
seb
2026-08-03 09:17:50 +02:00
parent 78be835388
commit 686a192b1a
2 changed files with 53 additions and 3 deletions

View File

@@ -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 = () => {