add button to leave channel

This commit is contained in:
marlon-erler
2024-07-08 02:44:23 +02:00
parent a27e5cb728
commit 25f1b1d14b
4 changed files with 48 additions and 6 deletions
+21 -2
View File
@@ -362,9 +362,10 @@
communication: "Communication", communication: "Communication",
encryption: "Encryption", encryption: "Encryption",
serverAddress: "Server Address", serverAddress: "Server Address",
serverAddressPlaceholder: "ws://192.168.0.69:3000", serverAddressPlaceholder: "wss://192.168.0.69:3000",
connectToServer: "Connect", connectToServer: "Connect",
primaryChannel: "Primary channel", primaryChannel: "Primary channel",
leaveChannel: "Leave",
channelPlaceholder: "my-channel", channelPlaceholder: "my-channel",
addSecondaryChannel: "Add secondary channel", addSecondaryChannel: "Add secondary channel",
removeSecondaryChannel: "Remove secondary channel", removeSecondaryChannel: "Remove secondary channel",
@@ -426,7 +427,11 @@
var messageBody = restoreState("message", ""); var messageBody = restoreState("message", "");
var cannotSetChannel = createProxyState( var cannotSetChannel = createProxyState(
[primaryChannel, currentPrimaryChannel, isConnected], [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( var cannotAddSecondaryChannel = createProxyState(
[newSecondaryChannelName], [newSecondaryChannelName],
@@ -475,6 +480,10 @@
} }
UDN.subscribe(primaryChannel.value); UDN.subscribe(primaryChannel.value);
} }
function leaveChannel() {
if (cannotLeaveChannel.value == true) return;
UDN.unsubscribe(currentPrimaryChannel.value);
}
function addSecondaryChannel() { function addSecondaryChannel() {
if (cannotAddSecondaryChannel.value == true) return; if (cannotAddSecondaryChannel.value == true) return;
const channelObject = new Channel(newSecondaryChannelName.value); const channelObject = new Channel(newSecondaryChannelName.value);
@@ -501,6 +510,8 @@
function handleSubscriptionConfirmation(channel, isSubscribed) { function handleSubscriptionConfirmation(channel, isSubscribed) {
if (isSubscribed == true) { if (isSubscribed == true) {
currentPrimaryChannel.value = channel; currentPrimaryChannel.value = channel;
} else {
currentPrimaryChannel.value = "";
} }
} }
async function handleMessage(body) { async function handleMessage(body) {
@@ -615,6 +626,14 @@
placeholder: translation.channelPlaceholder placeholder: translation.channelPlaceholder
} }
))), /* @__PURE__ */ createElement("div", { class: "flex-row width-input justify-end" }, /* @__PURE__ */ createElement( ))), /* @__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", "button",
{ {
class: "primary width-50", class: "primary width-50",
+9
View File
@@ -4,7 +4,9 @@ import {
Channel, Channel,
addSecondaryChannel, addSecondaryChannel,
cannotAddSecondaryChannel, cannotAddSecondaryChannel,
cannotLeaveChannel,
cannotSetChannel, cannotSetChannel,
leaveChannel,
newSecondaryChannelName, newSecondaryChannelName,
primaryChannel, primaryChannel,
removeSecondaryChannel, removeSecondaryChannel,
@@ -69,6 +71,13 @@ export function CommunicationSection() {
</div> </div>
</label> </label>
<div class="flex-row width-input justify-end"> <div class="flex-row width-input justify-end">
<button
class="danger width-50"
on:click={leaveChannel}
toggle:disabled={cannotLeaveChannel}
>
{translation.leaveChannel}
</button>
<button <button
class="primary width-50" class="primary width-50"
on:click={setChannel} on:click={setChannel}
+17 -4
View File
@@ -63,18 +63,23 @@ export const isEncryptionUnavailable = window.crypto.subtle == undefined;
// sending // sending
export const currentPrimaryChannel = new React.State(""); export const currentPrimaryChannel = new React.State("");
export const primaryChannel = React.restoreState("primary-channel", ""); export const primaryChannel = React.restoreState("primary-channel", "");
export const newSecondaryChannelName = new React.State(""); export const newSecondaryChannelName = new React.State("");
export const secondaryChannels = export const secondaryChannels =
React.restoreListState<Channel>("secondary-channels"); React.restoreListState<Channel>("secondary-channels");
export const senderName = React.restoreState("sender-name", ""); export const senderName = React.restoreState("sender-name", "");
export const messageBody = React.restoreState("message", ""); export const messageBody = React.restoreState("message", "");
export const cannotSetChannel = React.createProxyState( export const cannotSetChannel = React.createProxyState(
[primaryChannel, currentPrimaryChannel, isConnected], [primaryChannel, currentPrimaryChannel, isConnected],
() => () => primaryChannel.value == "" || isConnected.value == false
primaryChannel.value == "" || );
primaryChannel.value == currentPrimaryChannel.value ||
isConnected.value == false export const cannotLeaveChannel = React.createProxyState(
[currentPrimaryChannel, isConnected],
() => currentPrimaryChannel.value == "" || isConnected.value == false
); );
export const cannotAddSecondaryChannel = React.createProxyState( export const cannotAddSecondaryChannel = React.createProxyState(
@@ -147,6 +152,12 @@ export function setChannel(): void {
UDN.subscribe(primaryChannel.value); UDN.subscribe(primaryChannel.value);
} }
export function leaveChannel(): void {
if (cannotLeaveChannel.value == true) return;
UDN.unsubscribe(currentPrimaryChannel.value);
}
export function addSecondaryChannel(): void { export function addSecondaryChannel(): void {
if (cannotAddSecondaryChannel.value == true) return; if (cannotAddSecondaryChannel.value == true) return;
@@ -184,6 +195,8 @@ function handleSubscriptionConfirmation(
): void { ): void {
if (isSubscribed == true) { if (isSubscribed == true) {
currentPrimaryChannel.value = channel; currentPrimaryChannel.value = channel;
} else {
currentPrimaryChannel.value = "";
} }
} }
+1
View File
@@ -18,6 +18,7 @@ const englishTranslations = {
serverAddressPlaceholder: "wss://192.168.0.69:3000", serverAddressPlaceholder: "wss://192.168.0.69:3000",
connectToServer: "Connect", connectToServer: "Connect",
primaryChannel: "Primary channel", primaryChannel: "Primary channel",
leaveChannel: "Leave",
channelPlaceholder: "my-channel", channelPlaceholder: "my-channel",
addSecondaryChannel: "Add secondary channel", addSecondaryChannel: "Add secondary channel",
removeSecondaryChannel: "Remove secondary channel", removeSecondaryChannel: "Remove secondary channel",