From 7c4100d67da166312f7396b03e80842833c2e7ec Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Fri, 12 Jul 2024 20:22:18 +0200 Subject: [PATCH] fix default selection of previous connection input --- dist/index.js | 10 ++++++++-- src/Model/model.ts | 5 ++++- src/Views/Overview/connectionSection.tsx | 11 +++++++++-- src/index.tsx | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2e22ed1e..4a3d8bd8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1154,7 +1154,6 @@ function connect() { if (cannotConnect.value == true) return; currentAddress.value = serverAddressInput.value; - previousAddresses.add(currentAddress.value); isConnected.value = false; didRequestConnection.value = true; UDN.connect(serverAddressInput.value); @@ -1175,6 +1174,9 @@ } UDN.onconnect = () => { isConnected.value = true; + if (!previousAddresses.value.has(currentAddress.value)) { + previousAddresses.add(currentAddress.value); + } subscribeChannels(); if (mailboxId.value != "") UDN.connectMailbox(mailboxId.value); }; @@ -2181,6 +2183,10 @@ // src/Views/Overview/connectionSection.tsx function ConnectionSection() { + const stringToPreviouAddressOption = (value) => { + const isSelected = value == serverAddressInput.value; + return /* @__PURE__ */ createElement("option", { "toggle:selected": isSelected }, value); + }; return /* @__PURE__ */ createElement("div", { class: "flex-column" }, /* @__PURE__ */ createElement("h2", null, translation.connection), /* @__PURE__ */ createElement("label", { class: "tile" }, /* @__PURE__ */ createElement("span", { class: "icon" }, "cell_tower"), /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("span", null, translation.serverAddress), /* @__PURE__ */ createElement( "input", { @@ -2200,7 +2206,7 @@ "select", { "bind:value": serverAddressInput, - "children:append": [previousAddresses, stringToOptionTag] + "children:append": [previousAddresses, stringToPreviouAddressOption] } ), /* @__PURE__ */ createElement("span", { class: "icon" }, "arrow_drop_down"))), /* @__PURE__ */ createElement("div", { class: "flex-row width-input justify-end" }, /* @__PURE__ */ createElement( "button", diff --git a/src/Model/model.ts b/src/Model/model.ts index 86a19f87..76090321 100644 --- a/src/Model/model.ts +++ b/src/Model/model.ts @@ -42,7 +42,6 @@ export function connect(): void { if (cannotConnect.value == true) return; currentAddress.value = serverAddressInput.value; - previousAddresses.add(currentAddress.value); isConnected.value = false; didRequestConnection.value = true; @@ -71,6 +70,10 @@ export function subscribeChannels() { // listeners UDN.onconnect = () => { isConnected.value = true; + if (!previousAddresses.value.has(currentAddress.value)) { + previousAddresses.add(currentAddress.value); + } + subscribeChannels(); if (mailboxId.value != "") UDN.connectMailbox(mailboxId.value); }; diff --git a/src/Views/Overview/connectionSection.tsx b/src/Views/Overview/connectionSection.tsx index 67b38db1..22009e8d 100644 --- a/src/Views/Overview/connectionSection.tsx +++ b/src/Views/Overview/connectionSection.tsx @@ -21,6 +21,13 @@ import { stringToOptionTag } from "../../utility"; import { translation } from "../../translations"; export function ConnectionSection() { + const stringToPreviouAddressOption: React.StateItemConverter = ( + value + ) => { + const isSelected = value == serverAddressInput.value; + return ; + }; + return (

{translation.connection}

@@ -45,10 +52,10 @@ export function ConnectionSection() {