removed unnecessary local page state

This commit is contained in:
Florian Scholdei
2019-04-17 15:46:49 +02:00
parent 9bc9e133cc
commit 53ce955f66
3 changed files with 21 additions and 70 deletions

View File

@@ -2,7 +2,6 @@
import React from "react";
import { connect } from "react-redux";
import { translate } from "react-i18next";
import { compose } from "redux";
import type { History } from "history";
import queryString from "query-string";
import type { Group, PagedCollection } from "@scm-manager/ui-types";
@@ -46,41 +45,21 @@ type Props = {
fetchGroupsByLink: (link: string) => void
};
type State = {
page: number
};
class Groups extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
page: -1
};
}
class Groups extends React.Component<Props> {
componentDidMount() {
const { fetchGroupsByPage, groupLink, page } = this.props;
fetchGroupsByPage(groupLink, page, this.getQueryString());
this.setState({ page: page });
}
onPageChange = (link: string) => {
this.props.fetchGroupsByLink(link);
};
/**
* reflect page transitions in the uri
*/
componentDidUpdate = (prevProps: Props) => {
const { list, page, location, fetchGroupsByPage, groupLink } = this.props;
if (list && page) {
const { list, page, loading, location, fetchGroupsByPage, groupLink } = this.props;
if (list && page && !loading) {
const statePage: number = list.page + 1;
if (
page !== this.state.page ||
page !== statePage ||
prevProps.location.search !== location.search
) {
fetchGroupsByPage(groupLink, page, this.getQueryString());
this.setState({ page: page });
}
}
};
@@ -192,9 +171,7 @@ const mapDispatchToProps = dispatch => {
};
};
export default compose(
connect(
export default connect(
mapStateToProps,
mapDispatchToProps
)
)(translate("groups")(Groups));

View File

@@ -1,9 +1,11 @@
// @flow
import React from "react";
import type { RepositoryCollection } from "@scm-manager/ui-types";
import { connect } from "react-redux";
import { translate } from "react-i18next";
import type { History } from "history";
import queryString from "query-string";
import { withRouter } from "react-router-dom";
import type { RepositoryCollection } from "@scm-manager/ui-types";
import {
fetchRepos,
fetchReposByLink,
@@ -13,7 +15,6 @@ import {
isAbleToCreateRepos,
isFetchReposPending
} from "../modules/repos";
import { translate } from "react-i18next";
import {
Page,
PageActions,
@@ -24,10 +25,7 @@ import {
getPageFromMatch
} from "@scm-manager/ui-components";
import RepositoryList from "../components/list";
import { withRouter } from "react-router-dom";
import type { History } from "history";
import { getRepositoriesLink } from "../../modules/indexResource";
import queryString from "query-string";
type Props = {
page: number,
@@ -48,40 +46,28 @@ type Props = {
fetchReposByLink: string => void
};
type State = {
page: number
};
class Overview extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
page: -1
};
}
class Overview extends React.Component<Props> {
componentDidMount() {
const { fetchReposByPage, reposLink, page } = this.props;
fetchReposByPage(reposLink, page, this.getQueryString());
this.setState({ page: page });
}
componentDidUpdate = (prevProps: Props) => {
const {
collection,
page,
loading,
location,
fetchReposByPage,
reposLink
} = this.props;
if (collection && page) {
if (collection && page && !loading) {
const statePage: number = collection.page + 1;
if (
page !== this.state.page ||
page !== statePage ||
prevProps.location.search !== location.search
) {
fetchReposByPage(reposLink, page, this.getQueryString());
this.setState({ page: page });
}
}
};

View File

@@ -45,34 +45,22 @@ type Props = {
fetchUsersByLink: (link: string) => void
};
type State = {
page: number
};
class Users extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
page: -1
};
}
class Users extends React.Component<Props> {
componentDidMount() {
const { fetchUsersByPage, usersLink, page } = this.props;
fetchUsersByPage(usersLink, page, this.getQueryString());
this.setState({ page: page });
}
componentDidUpdate = (prevProps: Props) => {
const { list, page, location, fetchUsersByPage, usersLink } = this.props;
if (list && page) {
const { list, page, loading, location, fetchUsersByPage, usersLink } = this.props;
if (list && page && !loading) {
const statePage: number = list.page + 1;
if (
page !== this.state.page ||
page !== statePage ||
prevProps.location.search !== location.search
) {
fetchUsersByPage(usersLink, page, this.getQueryString());
this.setState({ page: page });
}
}
};