Add State.createServer

This commit is contained in:
Simon Ser 2021-06-10 10:54:33 +02:00
parent 5fcbfa446c
commit bf76eaa669
2 changed files with 18 additions and 12 deletions

View file

@ -118,8 +118,6 @@ export default class App extends Component {
receipts = new Map();
buffer = createRef();
composer = createRef();
lastServerID = 0;
lastBufferID = 0;
switchToChannel = null;
constructor(props) {
@ -413,22 +411,17 @@ export default class App extends Component {
}
connect(params) {
this.lastServerID++;
var serverID = this.lastServerID;
var serverID = null;
this.setState((state) => {
var servers = new Map(state.servers);
servers.set(serverID, {
id: serverID,
status: ServerStatus.CONNECTING,
isupport: new Map(),
});
return { servers };
var update;
[serverID, update] = State.createServer(state);
return update;
});
this.setState({ connectParams: params });
var client = new Client(fillConnectParams(params));
this.clients.set(serverID, client);
this.setServerState(serverID, { status: client.status });
client.addEventListener("status", () => {
this.setServerState(serverID, { status: client.status });

View file

@ -134,6 +134,7 @@ function insertMessage(list, msg) {
return list;
}
var lastServerID = 0;
var lastBufferID = 0;
export const State = {
@ -208,6 +209,18 @@ export const State = {
throw new Error("Invalid buffer ID type: " + (typeof id));
}
},
createServer(state) {
lastServerID++;
var id = lastServerID;
var servers = new Map(state.servers);
servers.set(id, {
id,
status: ServerStatus.DISCONNECTED,
isupport: new Map(),
});
return [id, { servers }];
},
createBuffer(state, name, serverID, client) {
var buf = State.getBuffer(state, { server: serverID, name });
if (buf) {