1- import React , { useEffect , useRef , useState } from "react" ;
1+ import React , { useEffect , useMemo , useState } from "react" ;
22import "react-day-picker/lib/style.css" ;
33import { Link , useParams } from "react-router-dom" ;
44import CollectionTable from "../Components/CollectionTable" ;
@@ -16,17 +16,17 @@ const empty_title_with_nonzero_width = <> </>;
1616
1717function MemberBoxSpans ( ) {
1818 const { member_id } = useParams ( ) ;
19-
20- const [ , setItems ] = useState ( [ ] ) ;
2119 const [ pendingLabaccessDays , setPendingLabaccessDays ] = useState ( "?" ) ;
2220
23- const collectionRef = useRef (
24- new Collection ( {
25- type : Span ,
26- url : `/membership/member/${ member_id } /spans` ,
27- pageSize : 0 ,
28- includeDeleted : true ,
29- } ) ,
21+ const collection = useMemo (
22+ ( ) =>
23+ new Collection ( {
24+ type : Span ,
25+ url : `/membership/member/${ member_id } /spans` ,
26+ pageSize : 0 ,
27+ includeDeleted : true ,
28+ } ) ,
29+ [ member_id ] ,
3030 ) ;
3131
3232 useEffect ( ( ) => {
@@ -45,20 +45,11 @@ function MemberBoxSpans() {
4545 ) ;
4646 } , [ member_id ] ) ;
4747
48- useEffect ( ( ) => {
49- const unsubscribe = collectionRef . current . subscribe ( ( { items } ) => {
50- setItems ( items ) ;
51- } ) ;
52- return ( ) => {
53- unsubscribe ( ) ;
54- } ;
55- } , [ ] ) ;
56-
5748 const deleteItem = ( item ) =>
5849 confirmModal ( item . deleteConfirmMessage ( ) )
5950 . then ( ( ) => item . del ( ) )
6051 . then (
61- ( ) => collectionRef . current . fetch ( ) ,
52+ ( ) => collection . fetch ( ) ,
6253 ( ) => null ,
6354 ) ;
6455
@@ -70,14 +61,11 @@ function MemberBoxSpans() {
7061 vid en nyckelsynkronisering.
7162 </ p >
7263 < hr />
73- < MembershipPeriodsInput
74- spans = { collectionRef . current }
75- member_id = { member_id }
76- />
64+ < MembershipPeriodsInput spans = { collection } member_id = { member_id } />
7765 < h2 > Spans</ h2 >
7866 < hr />
7967 < CollectionTable
80- collection = { collectionRef . current }
68+ collection = { collection }
8169 columns = { [
8270 { title : "#" , sort : "span_id" } ,
8371 { title : "Typ" , sort : "type" } ,
0 commit comments