| 253 | } |
| 254 | |
| 255 | function add(input: ServerConnection.Http) { |
| 256 | const url_ = normalizeServerUrl(input.http.url) |
| 257 | if (!url_) return |
| 258 | const conn: ServerConnection.Http = { ...input, authToken: undefined, http: { ...input.http, url: url_ } } |
| 259 | return batch(() => { |
| 260 | const existing = store.list.findIndex((x) => url(x) === url_) |
| 261 | if (existing !== -1) { |
| 262 | setStore("list", existing, conn) |
| 263 | } else { |
| 264 | setStore("list", store.list.length, conn) |
| 265 | } |
| 266 | setState("active", ServerConnection.key(conn)) |
| 267 | return conn |
| 268 | }) |
| 269 | } |
| 270 | |
| 271 | function remove(key: ServerConnection.Key) { |
| 272 | const next = nextServerAfterRemoval(allServers(), key, props.defaultServer) |