Skip to content

Commit

Permalink
fix: remove toVerifyCounter which was causing repeated getCount reque…
Browse files Browse the repository at this point in the history
…sts (#188)
  • Loading branch information
gwynndp authored Nov 13, 2021
1 parent f897b5f commit 5cf9697
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
34 changes: 12 additions & 22 deletions src/components/Verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import GrowerDetail from './GrowerDetail';
// import CaptureTags from './CaptureTags';
import SidePanel from './SidePanel';
import CaptureDetailDialog from './CaptureDetailDialog';
import withData from './common/withData';
import OptimizedImage from './OptimizedImage';
import { LocationOn } from '@material-ui/icons';
import { countToLocaleString } from '../common/numbers';
Expand Down Expand Up @@ -145,16 +144,9 @@ const useStyles = makeStyles((theme) => ({
height: theme.spacing(5),
marginLeft: '0.75rem',
backgroundColor: theme.palette.stats.green,
}
},
}));

const ToVerifyCounter = withData(({ data }) => (
<>
{data !== null &&
`${countToLocaleString(data)} capture${data === 1 ? '' : 's'}`}
</>
));

const Verify = (props) => {
const verifyContext = useContext(VerifyContext);
const speciesContext = useContext(SpeciesContext);
Expand Down Expand Up @@ -438,14 +430,11 @@ const Verify = (props) => {
key={1}
>
Filter
{
numFilters > 0 &&
(
<Avatar className={classes.activeFilters}>
{numFilters}
</Avatar>
)
}
{numFilters > 0 && (
<Avatar className={classes.activeFilters}>
{numFilters}
</Avatar>
)}
</Button>,
]}
>
Expand Down Expand Up @@ -483,11 +472,12 @@ const Verify = (props) => {
>
<Grid item>
<Typography variant="h5">
<ToVerifyCounter
needsRefresh={verifyContext.invalidateCaptureCount}
fetch={verifyContext.getCaptureCount}
data={verifyContext.captureCount}
/>
{verifyContext.captureCount !== null &&
`${countToLocaleString(
verifyContext.captureCount,
)} capture${
verifyContext.captureCount === 1 ? '' : 's'
}`}
</Typography>
</Grid>
<Grid item>{imagePagination}</Grid>
Expand Down
6 changes: 5 additions & 1 deletion src/context/VerifyContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, createContext } from 'react';
import React, { useState, useEffect, createContext } from 'react';
import api from '../api/treeTrackerApi';
import FilterModel from '../models/Filter';
import * as loglevel from 'loglevel';
Expand Down Expand Up @@ -60,6 +60,10 @@ export function VerifyProvider(props) {
const [invalidateCaptureCount, setInvalidateCaptureCount] = useState(true);
const [captureCount, setCaptureCount] = useState(null);

useEffect(() => {
if (invalidateCaptureCount) getCaptureCount();
}, [invalidateCaptureCount]);

// STATE HELPER FUNCTIONS

const appendCaptureImages = (images) => {
Expand Down

0 comments on commit 5cf9697

Please sign in to comment.