add buttons to resend and clear all objects

This commit is contained in:
marlon-erler
2024-07-11 02:29:00 +02:00
parent cf935b400a
commit 687d378eb4
6 changed files with 85 additions and 25 deletions
+21 -6
View File
@@ -57,6 +57,7 @@ export class Chat {
cannotSetChannel: React.State<boolean>;
cannotUndoChannel: React.State<boolean>;
cannotClearMessages: React.State<boolean>;
cannotClearObjects: React.State<boolean>;
// init
constructor(id: string = React.UUID()) {
@@ -124,6 +125,10 @@ export class Chat {
[this.messages],
() => this.messages.value.size == 0
);
this.cannotClearObjects = React.createProxyState(
[this.objects],
() => this.objects.value.size == 0
);
}
// general
@@ -272,20 +277,30 @@ export class Chat {
};
// objects
addObjectAndSend(object: MessageObject): void {
addObjectAndSend = (object: MessageObject): void => {
this.objects.set(object.id, object);
this.sendObject(object);
}
};
sendObject(object: MessageObject): void {
sendObject = (object: MessageObject): void => {
this.objectOutbox.set(object.id, object);
this.sendMessagesInOutbox();
}
};
deleteObject(object: MessageObject): void {
deleteObject = (object: MessageObject): void => {
this.objects.remove(object.id);
this.objectOutbox.remove(object.id);
}
};
resendObjects = (): void => {
this.objects.value.forEach((object) => {
this.sendObject(object);
});
};
clearObjects = (): void => {
this.objects.clear();
};
// channel
setChannel = (): void => {
+21 -3
View File
@@ -131,19 +131,37 @@ export function ChatOptionModal(chat: Chat, isPresented: React.State<boolean>) {
<hr></hr>
<div class="flex-column gap">
<div class="flex-column gap width-input">
<button on:click={chat.resendObjects}>
{translation.resendObjects}
<span class="icon">replay</span>
</button>
</div>
<hr></hr>
<div class="flex-column gap width-input">
<button
class="danger"
on:click={chat.clearObjects}
toggle:disabled={chat.cannotClearObjects}
>
{translation.clearObjects}
<span class="icon">delete_sweep</span>
</button>
<button
class="danger"
on:click={chat.clearMessages}
toggle:disabled={chat.cannotClearMessages}
>
{translation.clearChatMessages}
<span class="icon">delete_sweep</span>
<span class="icon">chat_error</span>
</button>
<button class="danger" on:click={deleteChat}>
{translation.removeChat}
<span class="icon">delete</span>
<span class="icon">delete_forever</span>
</button>
</div>
</main>
+5 -2
View File
@@ -36,7 +36,7 @@ const englishTranslations = {
primaryChannelPlaceholder: "my-channel",
addChat: "Add",
// messages
// chat
showChatOptions: "show chat options",
configureChatTitle: "Configure Chat",
@@ -49,8 +49,9 @@ const englishTranslations = {
encryptionKeyPlaceholder: "n10d2482dg283hg",
showKey: "Show key",
removeChat: "Remove chat",
clearObjects: "Delete all objects",
clearChatMessages: "Clear chat messages",
removeChat: "Remove chat",
messageInOutbox: "Pending",
@@ -59,6 +60,7 @@ const englishTranslations = {
composerPlaceholder: "Type a message...",
sendMessage: "Send",
// messages
resendMessage: "Resend message",
decryptMessage: "Decrypt message",
copyMessage: "Copy message",
@@ -70,6 +72,7 @@ const englishTranslations = {
objectTitle: "Object title",
objectTitlePlaceholder: "My object",
resendObjects: "Resend all objects",
deleteObject: "Delete object",
};