From 1202789a4380804d39df30324a34a2e57f3495f0 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Tue, 9 Jul 2024 17:32:51 +0200 Subject: [PATCH] allow deleting chat --- dist/index.js | 16 ++++++++++++++-- src/Model/chatModel.ts | 22 +++++++++++----------- src/Views/chatOptionModal.tsx | 14 +++++++++++++- src/translations.ts | 3 ++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index 621e5d78..d2a24669 100644 --- a/dist/index.js +++ b/dist/index.js @@ -403,6 +403,14 @@ () => this.primaryChannelInput.value == this.primaryChannel.value ); } + // general + deleteSelf = () => { + Object.values(storageKeys).forEach((storageKey) => { + localStorage.removeItem(storageKey(this.id)); + }); + chats.remove(this); + chatIds.remove(this.id); + }; // handlers onmessage = async (data) => { if (data.messageChannel && data.messageChannel != this.primaryChannel.value) @@ -729,7 +737,6 @@ newChatPrimaryChannel: "Primary channel", newChatNamePlaceholder: "my-channel", addChat: "Add", - removeChat: "Remove chat", // messages showChatOptions: "show chat options", configureChatTitle: "Configure Chat", @@ -741,6 +748,7 @@ removeSecondaryChannel: "Remove secondary channel", encryptionKey: "Encryption key", encryptionKeyPlaceholder: "n10d2482dg283hg", + removeChat: "Remove chat", noChatSelected: "No chat selected", composerPlaceholder: "Type a message...", sendMessage: "Send", @@ -759,6 +767,10 @@ function closeModal() { isPresented.value = false; } + function deleteChat() { + chat.deleteSelf(); + closeModal(); + } const secondaryChannelConverter = (secondaryChannel) => { function remove() { chat.removeSecondaryChannel(secondaryChannel); @@ -830,7 +842,7 @@ placeholder: translation.encryptionKeyPlaceholder, "bind:value": chat.encryptionKey } - )))), /* @__PURE__ */ createElement("button", { class: "danger", "on:click": closeModal }, translation.close, /* @__PURE__ */ createElement("span", { class: "icon" }, "close")))); + ))), /* @__PURE__ */ createElement("hr", null), /* @__PURE__ */ createElement("button", { class: "danger", "on:click": deleteChat }, translation.removeChat, /* @__PURE__ */ createElement("span", { class: "icon" }, "delete"))), /* @__PURE__ */ createElement("button", { class: "danger", "on:click": closeModal }, translation.close, /* @__PURE__ */ createElement("span", { class: "icon" }, "close")))); } // src/Views/messageComposer.tsx diff --git a/src/Model/chatModel.ts b/src/Model/chatModel.ts index cdea662b..89890ff5 100644 --- a/src/Model/chatModel.ts +++ b/src/Model/chatModel.ts @@ -86,11 +86,20 @@ export class Chat { ); this.cannotUndoChannel = React.createProxyState( [this.primaryChannelInput, this.primaryChannel], - () => - this.primaryChannelInput.value == this.primaryChannel.value + () => this.primaryChannelInput.value == this.primaryChannel.value ); } + // general + deleteSelf = () => { + Object.values(storageKeys).forEach((storageKey) => { + localStorage.removeItem(storageKey(this.id)); + }); + + chats.remove(this); + chatIds.remove(this.id); + } + // handlers onmessage = async (data: Message): Promise => { if (data.messageChannel && data.messageChannel != this.primaryChannel.value) @@ -201,12 +210,3 @@ export function createChatWithName(name: string): void { UDN.subscribe(name); } - -export function removeChat(chat: Chat): void { - Object.values(storageKeys).forEach((cb) => { - localStorage.removeItem(cb(chat.id)); - }); - - chats.remove(chat); - chatIds.remove(chat.id); -} diff --git a/src/Views/chatOptionModal.tsx b/src/Views/chatOptionModal.tsx index 3ea958c4..a1eec98a 100644 --- a/src/Views/chatOptionModal.tsx +++ b/src/Views/chatOptionModal.tsx @@ -8,6 +8,11 @@ export function ChatOptionModal(chat: Chat, isPresented: React.State) { isPresented.value = false; } + function deleteChat() { + chat.deleteSelf() + closeModal(); + } + const secondaryChannelConverter: React.ListItemConverter = ( secondaryChannel ) => { @@ -108,8 +113,15 @@ export function ChatOptionModal(chat: Chat, isPresented: React.State) { > + +
+ + - diff --git a/src/translations.ts b/src/translations.ts index 0236e060..5c31229d 100644 --- a/src/translations.ts +++ b/src/translations.ts @@ -34,7 +34,6 @@ const englishTranslations = { newChatPrimaryChannel: "Primary channel", newChatNamePlaceholder: "my-channel", addChat: "Add", - removeChat: "Remove chat", // messages showChatOptions: "show chat options", @@ -51,6 +50,8 @@ const englishTranslations = { encryptionKey: "Encryption key", encryptionKeyPlaceholder: "n10d2482dg283hg", + removeChat: "Remove chat", + noChatSelected: "No chat selected", composerPlaceholder: "Type a message...",