@@ -3,13 +3,19 @@ import {Button, Col, Form, InputGroup, OverlayTrigger, Tooltip} from "react-boot
3
3
import AddAggregatorModal from "./AddAggregatorModal" ;
4
4
5
5
export default function AggregatorSetter ( props ) {
6
+ const CUSTOM_AGGREGATORS_KEY = "CUSTOM_AGGREGATORS" ;
6
7
const [ availableAggregators , setAvailableAggregators ] = useState ( [ ] ) ;
7
8
const [ showAddModal , toggleAddModal ] = useState ( false ) ;
8
9
const [ canRemoveSelected , setCanRemoveSelected ] = useState ( false ) ;
9
10
10
11
useEffect ( ( ) => {
11
12
let aggregators = props . defaultAvailableAggregators ;
12
-
13
+
14
+ const storedAggregators = JSON . parse ( localStorage . getItem ( CUSTOM_AGGREGATORS_KEY ) ) ;
15
+ if ( storedAggregators ) {
16
+ aggregators = aggregators . concat ( storedAggregators ) ;
17
+ }
18
+
13
19
setAvailableAggregators ( aggregators ) ;
14
20
} , [ props . defaultAvailableAggregators ] ) ;
15
21
@@ -40,17 +46,27 @@ export default function AggregatorSetter(props) {
40
46
return ;
41
47
}
42
48
43
- setAvailableAggregators ( [ ...availableAggregators , aggregator ] ) ;
49
+ const aggregators = [ ...availableAggregators , aggregator ] ;
50
+ setAvailableAggregators ( aggregators ) ;
44
51
handleChange ( aggregator ) ;
52
+ saveCustomAggregatorSources ( aggregators ) ;
45
53
}
46
54
47
55
function deleteSelectedAggregatorSource ( ) {
48
56
if ( ! canRemoveSelected ) {
49
57
return ;
50
58
}
51
59
52
- setAvailableAggregators ( availableAggregators . filter ( a => a !== props . aggregator ) ) ;
60
+ const aggregators = availableAggregators . filter ( a => a !== props . aggregator ) ;
61
+ setAvailableAggregators ( aggregators ) ;
53
62
handleChange ( availableAggregators . at ( 0 ) ) ;
63
+ saveCustomAggregatorSources ( aggregators ) ;
64
+ }
65
+
66
+ function saveCustomAggregatorSources ( aggregators ) {
67
+ const customAggregators = aggregators . filter ( a => ! props . defaultAvailableAggregators . includes ( a ) ) ;
68
+ console . log ( "save" , customAggregators , aggregators , props . defaultAvailableAggregators ) ;
69
+ localStorage . setItem ( CUSTOM_AGGREGATORS_KEY , JSON . stringify ( customAggregators ) ) ;
54
70
}
55
71
56
72
return (
0 commit comments