Skip to content

Commit

Permalink
Bug fix #169 materials are not sorted properly (#544)
Browse files Browse the repository at this point in the history
* change reducer for ExpertMaterialsContainer.tsx

* edit selector for materials at ExpertMaterialsContainer.tsx

* edit selector for materials at ExpertMaterialsContainer.tsx
  • Loading branch information
0shar0 authored Aug 25, 2021
1 parent a9e88e5 commit 18821ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/models/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export const selectPostsByIds = (ids: number[]): IPost[] => {
export const selectExpertsByIds = (ids: number[]): IExpert[] => {
return ids.map((id) => store.getState().experts.data.experts[id]);
};

export const selectExpertPostsByIds = (ids: number[]): IPost[] => {
return ids.map((id) => store.getState().expertMaterials.data.posts[id]);
};
10 changes: 2 additions & 8 deletions src/old/modules/experts/components/ExpertMaterialsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
selectExpertsData,
} from '../../../../models/expertMaterials';
import { updatePostTypes, updateDir } from '../../utilities/utilityFunctions';
import { selectExpertPostsByIds } from '../../../../models/helpers/selectors';

export interface IExpertMaterialsContainerProps {
expertId: number;
Expand All @@ -68,7 +69,6 @@ const ExpertMaterialsContainer: React.FC<IExpertMaterialsContainerProps> = ({
expert,
}) => {
const {
posts,
postIds,
meta: { isLastPage, pageNumber, totalElements, totalPages },
} = useSelector(selectExpertsData);
Expand Down Expand Up @@ -109,13 +109,7 @@ const ExpertMaterialsContainer: React.FC<IExpertMaterialsContainerProps> = ({
};
}, []);

const allMaterials = Object.values(posts);
const materials = [...allMaterials].filter((el) => {
if (postIds.find((elem) => elem === el.id)) {
return true;
}
return false;
});
const materials = selectExpertPostsByIds(postIds);

const postTypes = useSelector(selectPostTypes);

Expand Down

0 comments on commit 18821ff

Please sign in to comment.