mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-28 18:26:19 -05:00
state: add bouncerNetworks helpers
This commit is contained in:
parent
fab42ba2ee
commit
e1bbe34ff2
2 changed files with 17 additions and 8 deletions
|
@ -160,7 +160,6 @@ export default class App extends Component {
|
|||
autoconnect: false,
|
||||
autojoin: [],
|
||||
},
|
||||
bouncerNetworks: new Map(),
|
||||
connectForm: true,
|
||||
loading: true,
|
||||
dialog: null,
|
||||
|
@ -950,16 +949,12 @@ export default class App extends Component {
|
|||
|
||||
let isNew = false;
|
||||
this.setState((state) => {
|
||||
let bouncerNetworks = new Map(state.bouncerNetworks);
|
||||
if (!attrs) {
|
||||
bouncerNetworks.delete(id);
|
||||
return State.deleteBouncerNetwork(state, id);
|
||||
} else {
|
||||
let prev = bouncerNetworks.get(id);
|
||||
isNew = prev === undefined;
|
||||
attrs = { ...prev, ...attrs };
|
||||
bouncerNetworks.set(id, attrs);
|
||||
isNew = !state.bouncerNetworks.has(id);
|
||||
return State.storeBouncerNetwork(state, id, attrs);
|
||||
}
|
||||
return { bouncerNetworks };
|
||||
}, () => {
|
||||
if (!attrs) {
|
||||
let serverID = this.serverFromBouncerNetwork(id);
|
||||
|
|
14
state.js
14
state.js
|
@ -172,6 +172,7 @@ export const State = {
|
|||
servers: new Map(),
|
||||
buffers: new Map(),
|
||||
activeBuffer: null,
|
||||
bouncerNetworks: new Map(),
|
||||
};
|
||||
},
|
||||
updateServer(state, id, updater) {
|
||||
|
@ -302,6 +303,19 @@ export const State = {
|
|||
let buffers = new Map(bufferList.map((buf) => [buf.id, buf]));
|
||||
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) {
|
||||
function updateServer(updater) {
|
||||
return State.updateServer(state, serverID, updater);
|
||||
|
|
Loading…
Reference in a new issue