Skip to content

Commit 002d118

Browse files
committed
Save custom aggregator source in local storage
1 parent 686ada7 commit 002d118

File tree

1 file changed

+19
-3
lines changed
  • mithril-explorer/components/AggregatorSetter

1 file changed

+19
-3
lines changed

mithril-explorer/components/AggregatorSetter/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import {Button, Col, Form, InputGroup, OverlayTrigger, Tooltip} from "react-boot
33
import AddAggregatorModal from "./AddAggregatorModal";
44

55
export default function AggregatorSetter(props) {
6+
const CUSTOM_AGGREGATORS_KEY = "CUSTOM_AGGREGATORS";
67
const [availableAggregators, setAvailableAggregators] = useState([]);
78
const [showAddModal, toggleAddModal] = useState(false);
89
const [canRemoveSelected, setCanRemoveSelected] = useState(false);
910

1011
useEffect(() => {
1112
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+
1319
setAvailableAggregators(aggregators);
1420
}, [props.defaultAvailableAggregators]);
1521

@@ -40,17 +46,27 @@ export default function AggregatorSetter(props) {
4046
return;
4147
}
4248

43-
setAvailableAggregators([...availableAggregators, aggregator]);
49+
const aggregators = [...availableAggregators, aggregator];
50+
setAvailableAggregators(aggregators);
4451
handleChange(aggregator);
52+
saveCustomAggregatorSources(aggregators);
4553
}
4654

4755
function deleteSelectedAggregatorSource() {
4856
if (!canRemoveSelected) {
4957
return;
5058
}
5159

52-
setAvailableAggregators(availableAggregators.filter(a => a !== props.aggregator));
60+
const aggregators = availableAggregators.filter(a => a !== props.aggregator);
61+
setAvailableAggregators(aggregators);
5362
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));
5470
}
5571

5672
return (

0 commit comments

Comments
 (0)