Ensure allocations are persisted across page navigation correctly; closes #2729

This commit is contained in:
Dane Everitt 2021-04-20 20:48:40 -07:00
parent d2955b9361
commit 38a5f2dbbf
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -11,6 +11,7 @@ import Can from '@/components/elements/Can';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import getServerAllocations from '@/api/swr/getServerAllocations'; import getServerAllocations from '@/api/swr/getServerAllocations';
import isEqual from 'react-fast-compare'; import isEqual from 'react-fast-compare';
import { useDeepCompareEffect } from '@/plugins/useDeepCompareEffect';
const NetworkContainer = () => { const NetworkContainer = () => {
const [ loading, setLoading ] = useState(false); const [ loading, setLoading ] = useState(false);
@ -23,7 +24,7 @@ const NetworkContainer = () => {
const { data, error, mutate } = getServerAllocations(); const { data, error, mutate } = getServerAllocations();
useEffect(() => { useEffect(() => {
mutate(allocations, false); mutate(allocations);
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -32,6 +33,12 @@ const NetworkContainer = () => {
} }
}, [ error ]); }, [ error ]);
useDeepCompareEffect(() => {
if (!data) return;
setServerFromState(state => ({ ...state, allocations: data }));
}, [ data ]);
const onCreateAllocation = () => { const onCreateAllocation = () => {
clearFlashes('server:network'); clearFlashes('server:network');