1- import React , { useCallback , useEffect , useState } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import Spinner from '@/components/elements/Spinner' ;
33import useFlash from '@/plugins/useFlash' ;
44import ServerContentBlock from '@/components/elements/ServerContentBlock' ;
55import { ServerContext } from '@/state/server' ;
6- import { useDeepMemoize } from '@/plugins/useDeepMemoize' ;
76import AllocationRow from '@/components/server/network/AllocationRow' ;
8- import setPrimaryServerAllocation from '@/api/server/network/setPrimaryServerAllocation' ;
97import Button from '@/components/elements/Button' ;
108import createServerAllocation from '@/api/server/network/createServerAllocation' ;
119import tw from 'twin.macro' ;
1210import Can from '@/components/elements/Can' ;
1311import SpinnerOverlay from '@/components/elements/SpinnerOverlay' ;
1412import getServerAllocations from '@/api/swr/getServerAllocations' ;
13+ import isEqual from 'react-fast-compare' ;
14+ import { Allocation } from '@/api/server/getServer' ;
1515
1616const NetworkContainer = ( ) => {
1717 const [ loading , setLoading ] = useState ( false ) ;
1818 const uuid = ServerContext . useStoreState ( state => state . server . data ! . uuid ) ;
1919 const allocationLimit = ServerContext . useStoreState ( state => state . server . data ! . featureLimits . allocations ) ;
20- const allocations = useDeepMemoize ( ServerContext . useStoreState ( state => state . server . data ! . allocations ) ) ;
20+ // @ts -ignore
21+ const allocations : Allocation [ ] = ServerContext . useStoreState ( state => state . server . data ! . allocations , isEqual ) ;
2122
2223 const { clearFlashes, clearAndAddHttpError } = useFlash ( ) ;
23- const { data, error, mutate } = getServerAllocations ( allocations ) ;
24+ const { data, error, mutate } = getServerAllocations ( ) ;
25+
26+ useEffect ( ( ) => {
27+ mutate ( allocations , false ) ;
28+ } , [ ] ) ;
2429
2530 useEffect ( ( ) => {
2631 if ( error ) {
2732 clearAndAddHttpError ( { key : 'server:network' , error } ) ;
2833 }
2934 } , [ error ] ) ;
3035
31- const setPrimaryAllocation = ( id : number ) => {
32- clearFlashes ( 'server:network' ) ;
33-
34- const initial = data ;
35- mutate ( data ?. map ( a => a . id === id ? { ...a , isDefault : true } : { ...a , isDefault : false } ) , false ) ;
36-
37- setPrimaryServerAllocation ( uuid , id )
38- . catch ( error => {
39- clearAndAddHttpError ( { key : 'server:network' , error } ) ;
40- mutate ( initial , false ) ;
41- } ) ;
42- } ;
43-
4436 const onCreateAllocation = ( ) => {
4537 clearFlashes ( 'server:network' ) ;
4638
@@ -51,10 +43,6 @@ const NetworkContainer = () => {
5143 . then ( ( ) => setLoading ( false ) ) ;
5244 } ;
5345
54- const onNotesAdded = useCallback ( ( id : number , notes : string ) => {
55- mutate ( data ?. map ( a => a . id === id ? { ...a , notes } : a ) , false ) ;
56- } , [ ] ) ;
57-
5846 return (
5947 < ServerContentBlock showFlashKey = { 'server:network' } title = { 'Network' } >
6048 { ! data ?
@@ -66,8 +54,6 @@ const NetworkContainer = () => {
6654 < AllocationRow
6755 key = { `${ allocation . ip } :${ allocation . port } ` }
6856 allocation = { allocation }
69- onSetPrimary = { setPrimaryAllocation }
70- onNotesChanged = { onNotesAdded }
7157 />
7258 ) )
7359 }
0 commit comments