apply PR review

Signed-off-by: Ky <virginie.ky@gmail.com>
This commit is contained in:
Ky 2020-05-05 14:46:17 +02:00
parent c02abe90fc
commit def471ef5f
4 changed files with 23 additions and 20 deletions

View File

@ -1,11 +1,11 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { PageFooter, useQuery } from 'strapi-helper-plugin'; import { PageFooter, useQuery } from 'strapi-helper-plugin';
import { generatePageFromStart, generateStartFromPage } from '../../utils'; import { generatePageFromStart, generateStartFromPage } from '../../../utils';
import List from '../List'; import List from '../../../components/List';
import ListEmpty from '../ListEmpty'; import ListEmpty from '../../../components/ListEmpty';
import Padded from '../Padded'; import Padded from '../../../components/Padded';
const HomePageList = ({ const HomePageList = ({
areResultsEmptyWithSettings, areResultsEmptyWithSettings,

View File

@ -2,13 +2,13 @@ import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useDebounce } from '@buffetjs/hooks'; import { useDebounce } from '@buffetjs/hooks';
import { HeaderSearch, useGlobalContext, useQuery } from 'strapi-helper-plugin'; import { HeaderSearch, useGlobalContext, useQuery } from 'strapi-helper-plugin';
import { getTrad, getFileModelTimestamps } from '../../utils'; import { getTrad, getFileModelTimestamps } from '../../../utils';
import ControlsWrapper from '../ControlsWrapper'; import ControlsWrapper from '../../../components/ControlsWrapper';
import Filters from '../Filters'; import Filters from '../../../components/Filters';
import Padded from '../Padded'; import Padded from '../../../components/Padded';
import SelectAll from '../SelectAll'; import SelectAll from '../../../components/SelectAll';
import SortPicker from '../SortPicker'; import SortPicker from '../../../components/SortPicker';
const HomePageSettings = ({ const HomePageSettings = ({
areAllCheckboxesSelected, areAllCheckboxesSelected,

View File

@ -4,8 +4,8 @@ import { isEmpty } from 'lodash';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { generateFiltersFromSearch, useQuery } from 'strapi-helper-plugin'; import { generateFiltersFromSearch, useQuery } from 'strapi-helper-plugin';
import HomePageSettings from '../HomePageSettings'; import HomePageSettings from './HomePageSettings';
import HomePageList from '../HomePageList'; import HomePageList from './HomePageList';
const HomePageContent = ({ const HomePageContent = ({
data, data,

View File

@ -1,7 +1,6 @@
import React, { useReducer, useState, useEffect } from 'react'; import React, { useReducer, useRef, useState, useEffect } from 'react';
import { includes, toString, isEqual, intersectionWith } from 'lodash'; import { includes, toString, isEqual, intersectionWith } from 'lodash';
import { useHistory, useLocation } from 'react-router-dom'; import { useHistory, useLocation } from 'react-router-dom';
import { useIsMounted } from '@buffetjs/hooks';
import { Header } from '@buffetjs/custom'; import { Header } from '@buffetjs/custom';
import { import {
PopUpWarning, PopUpWarning,
@ -14,7 +13,7 @@ import {
} from 'strapi-helper-plugin'; } from 'strapi-helper-plugin';
import { formatFileForEditing, getRequestUrl, getTrad, getFileModelTimestamps } from '../../utils'; import { formatFileForEditing, getRequestUrl, getTrad, getFileModelTimestamps } from '../../utils';
import Container from '../../components/Container'; import Container from '../../components/Container';
import HomePageContent from '../../components/HomePageContent'; import HomePageContent from './HomePageContent';
import Padded from '../../components/Padded'; import Padded from '../../components/Padded';
import ModalStepper from '../ModalStepper'; import ModalStepper from '../ModalStepper';
import { generateStringFromParams, getHeaderLabel } from './utils'; import { generateStringFromParams, getHeaderLabel } from './utils';
@ -33,11 +32,15 @@ const HomePage = () => {
const [modalInitialStep, setModalInitialStep] = useState('browse'); const [modalInitialStep, setModalInitialStep] = useState('browse');
const { push } = useHistory(); const { push } = useHistory();
const { search } = useLocation(); const { search } = useLocation();
const isMounted = useIsMounted(); const isMounted = useRef(true);
const { data, dataCount, dataToDelete, isLoading } = reducerState.toJS(); const { data, dataCount, dataToDelete, isLoading } = reducerState.toJS();
const pluginName = formatMessage({ id: getTrad('plugin.name') }); const pluginName = formatMessage({ id: getTrad('plugin.name') });
const paramsKeys = ['_limit', '_start', '_q', '_sort']; const paramsKeys = ['_limit', '_start', '_q', '_sort'];
useEffect(() => {
return () => (isMounted.current = false);
}, []);
useEffect(() => { useEffect(() => {
fetchListData(); fetchListData();
@ -52,7 +55,7 @@ const HomePage = () => {
method: 'DELETE', method: 'DELETE',
}); });
} catch (err) { } catch (err) {
if (isMounted) { if (isMounted.current) {
strapi.notification.error('notification.error'); strapi.notification.error('notification.error');
} }
} }
@ -73,7 +76,7 @@ const HomePage = () => {
return Promise.resolve(data); return Promise.resolve(data);
} catch (err) { } catch (err) {
if (isMounted) { if (isMounted.current) {
dispatch({ type: 'GET_DATA_ERROR' }); dispatch({ type: 'GET_DATA_ERROR' });
strapi.notification.error('notification.error'); strapi.notification.error('notification.error');
} }
@ -93,7 +96,7 @@ const HomePage = () => {
return Promise.resolve(count); return Promise.resolve(count);
} catch (err) { } catch (err) {
if (isMounted) { if (isMounted.current) {
dispatch({ type: 'GET_DATA_ERROR' }); dispatch({ type: 'GET_DATA_ERROR' });
strapi.notification.error('notification.error'); strapi.notification.error('notification.error');
} }
@ -107,7 +110,7 @@ const HomePage = () => {
const [data, count] = await Promise.all([fetchData(), fetchDataCount()]); const [data, count] = await Promise.all([fetchData(), fetchDataCount()]);
if (isMounted) { if (isMounted.current) {
dispatch({ dispatch({
type: 'GET_DATA_SUCCEEDED', type: 'GET_DATA_SUCCEEDED',
data, data,