state: add bouncerNetworks helpers

This commit is contained in:
Simon Ser 2022-02-04 14:22:50 +01:00
parent fab42ba2ee
commit e1bbe34ff2
2 changed files with 17 additions and 8 deletions

View file

@ -160,7 +160,6 @@ export default class App extends Component {
autoconnect: false, autoconnect: false,
autojoin: [], autojoin: [],
}, },
bouncerNetworks: new Map(),
connectForm: true, connectForm: true,
loading: true, loading: true,
dialog: null, dialog: null,
@ -950,16 +949,12 @@ export default class App extends Component {
let isNew = false; let isNew = false;
this.setState((state) => { this.setState((state) => {
let bouncerNetworks = new Map(state.bouncerNetworks);
if (!attrs) { if (!attrs) {
bouncerNetworks.delete(id); return State.deleteBouncerNetwork(state, id);
} else { } else {
let prev = bouncerNetworks.get(id); isNew = !state.bouncerNetworks.has(id);
isNew = prev === undefined; return State.storeBouncerNetwork(state, id, attrs);
attrs = { ...prev, ...attrs };
bouncerNetworks.set(id, attrs);
} }
return { bouncerNetworks };
}, () => { }, () => {
if (!attrs) { if (!attrs) {
let serverID = this.serverFromBouncerNetwork(id); let serverID = this.serverFromBouncerNetwork(id);

View file

@ -172,6 +172,7 @@ export const State = {
servers: new Map(), servers: new Map(),
buffers: new Map(), buffers: new Map(),
activeBuffer: null, activeBuffer: null,
bouncerNetworks: new Map(),
}; };
}, },
updateServer(state, id, updater) { updateServer(state, id, updater) {
@ -302,6 +303,19 @@ export const State = {
let buffers = new Map(bufferList.map((buf) => [buf.id, buf])); let buffers = new Map(bufferList.map((buf) => [buf.id, buf]));
return [id, { buffers }]; return [id, { buffers }];
}, },
storeBouncerNetwork(state, id, attrs) {
let bouncerNetworks = new Map(state.bouncerNetworks);
bouncerNetworks.set(id, {
...bouncerNetworks.get(id),
...attrs,
});
return { bouncerNetworks };
},
deleteBouncerNetwork(state, id) {
let bouncerNetworks = new Map(state.bouncerNetworks);
bouncerNetworks.delete(id);
return { bouncerNetworks };
},
handleMessage(state, msg, serverID, client) { handleMessage(state, msg, serverID, client) {
function updateServer(updater) { function updateServer(updater) {
return State.updateServer(state, serverID, updater); return State.updateServer(state, serverID, updater);