From 9238895c99c30c442ce8dae41b61f898a79dd89b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 20 Sep 2020 23:03:05 -0700 Subject: Handle list refresh --- modern/src/DeviceList.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modern/src/DeviceList.js') diff --git a/modern/src/DeviceList.js b/modern/src/DeviceList.js index b7c15dc4..c9abce3c 100644 --- a/modern/src/DeviceList.js +++ b/modern/src/DeviceList.js @@ -14,6 +14,7 @@ import MoreVertIcon from '@material-ui/icons/MoreVert'; import { devicesActions } from './store'; import EditCollectionView from './EditCollectionView'; +import { useEffectAsync } from './reactHelper'; const useStyles = makeStyles(() => ({ list: { @@ -22,12 +23,19 @@ const useStyles = makeStyles(() => ({ }, })); -const DeviceView = ({ onMenuClick }) => { +const DeviceView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); const dispatch = useDispatch(); const items = useSelector(state => Object.values(state.devices.items)); + useEffectAsync(async () => { + const response = await fetch('/api/devices'); + if (response.ok) { + dispatch(devicesActions.refresh(await response.json())); + } + }, [updateTimestamp]); + return ( {items.map((item, index, list) => ( -- cgit v1.2.3