From 25f1b1d14b355086cd48174d6ead33faec5623b3 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Mon, 8 Jul 2024 02:44:23 +0200 Subject: [PATCH] add button to leave channel --- dist/index.js | 23 +++++++++++++++++++++-- src/Views/communicationSection.tsx | 9 +++++++++ src/model.ts | 21 +++++++++++++++++---- src/translations.ts | 1 + 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index e4585c1d..b8675d22 100644 --- a/dist/index.js +++ b/dist/index.js @@ -362,9 +362,10 @@ communication: "Communication", encryption: "Encryption", serverAddress: "Server Address", - serverAddressPlaceholder: "ws://192.168.0.69:3000", + serverAddressPlaceholder: "wss://192.168.0.69:3000", connectToServer: "Connect", primaryChannel: "Primary channel", + leaveChannel: "Leave", channelPlaceholder: "my-channel", addSecondaryChannel: "Add secondary channel", removeSecondaryChannel: "Remove secondary channel", @@ -426,7 +427,11 @@ var messageBody = restoreState("message", ""); var cannotSetChannel = createProxyState( [primaryChannel, currentPrimaryChannel, isConnected], - () => primaryChannel.value == "" || primaryChannel.value == currentPrimaryChannel.value || isConnected.value == false + () => primaryChannel.value == "" || isConnected.value == false + ); + var cannotLeaveChannel = createProxyState( + [currentPrimaryChannel, isConnected], + () => currentPrimaryChannel.value == "" || isConnected.value == false ); var cannotAddSecondaryChannel = createProxyState( [newSecondaryChannelName], @@ -475,6 +480,10 @@ } UDN.subscribe(primaryChannel.value); } + function leaveChannel() { + if (cannotLeaveChannel.value == true) return; + UDN.unsubscribe(currentPrimaryChannel.value); + } function addSecondaryChannel() { if (cannotAddSecondaryChannel.value == true) return; const channelObject = new Channel(newSecondaryChannelName.value); @@ -501,6 +510,8 @@ function handleSubscriptionConfirmation(channel, isSubscribed) { if (isSubscribed == true) { currentPrimaryChannel.value = channel; + } else { + currentPrimaryChannel.value = ""; } } async function handleMessage(body) { @@ -615,6 +626,14 @@ placeholder: translation.channelPlaceholder } ))), /* @__PURE__ */ createElement("div", { class: "flex-row width-input justify-end" }, /* @__PURE__ */ createElement( + "button", + { + class: "danger width-50", + "on:click": leaveChannel, + "toggle:disabled": cannotLeaveChannel + }, + translation.leaveChannel + ), /* @__PURE__ */ createElement( "button", { class: "primary width-50", diff --git a/src/Views/communicationSection.tsx b/src/Views/communicationSection.tsx index fbd11b56..107adf01 100644 --- a/src/Views/communicationSection.tsx +++ b/src/Views/communicationSection.tsx @@ -4,7 +4,9 @@ import { Channel, addSecondaryChannel, cannotAddSecondaryChannel, + cannotLeaveChannel, cannotSetChannel, + leaveChannel, newSecondaryChannelName, primaryChannel, removeSecondaryChannel, @@ -69,6 +71,13 @@ export function CommunicationSection() {
+