Skip to content

Commit

Permalink
Merge pull request #506 from ita-social-projects/Fix-posts-counter-in…
Browse files Browse the repository at this point in the history
…-Materials-page

Fixed counter & posts loading in Materials page
  • Loading branch information
NabokinAlexandr authored Aug 10, 2021
2 parents 74a3fb7 + d6ddbd4 commit 33292e4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/old/modules/materials/components/MaterialsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ const MaterialsView: React.FC = () => {
const history = useHistory();
const query = useQuery();
const classes = useStyles();

const materials = selectPostsByIds(postIds);

const origins = useSelector(selectOrigins);

const originsInPlural: IOrigin[] = [];

if (origins.length) {
Expand All @@ -103,11 +100,8 @@ const MaterialsView: React.FC = () => {

originsInPlural.push(el1, el3, el2);
}

const postTypes = useSelector(selectPostTypes);

const postTypesInPlural: IPostType[] = [];

if (postTypes.length) {
const el1: IPostType = { ...postTypes[0] };
const el2: IPostType = { ...postTypes[1] };
Expand Down Expand Up @@ -139,7 +133,6 @@ const MaterialsView: React.FC = () => {

const propertiesLoaded =
!isEmpty(postTypes) && !isEmpty(directions) && !isEmpty(origins);

const [boundFetchMaterials] = useActions([fetchMaterials]);

const stringOfOrigins = () => {
Expand Down Expand Up @@ -234,15 +227,20 @@ const MaterialsView: React.FC = () => {
const appendPosts = previous && previous.page < page;
if (
!isLastPage &&
Math.ceil(materials.length / LOAD_POSTS_LIMIT) !== page + 1
Math.ceil(materials.length / LOAD_POSTS_LIMIT) !== page + 1 &&
directions.length &&
postTypes.length &&
origins.length
) {
fetchData(appendPosts);
}
}, [page]);
}, [page, directions, postTypes, origins]);

useEffect(() => {
const appendPosts = (previous && previous.page < page) || page !== 0;
fetchData(appendPosts);
if (directions.length && postTypes.length && origins.length) {
fetchData(appendPosts);
}
}, [
query.get(QueryTypeEnum.ORIGINS),
query.get(QueryTypeEnum.POST_TYPES),
Expand Down

0 comments on commit 33292e4

Please sign in to comment.