Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed counter & posts loading in Materials page #506

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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