Files
CT/src/Views/threadView.tsx
T

79 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-07-07 22:11:18 +02:00
import * as React from "bloatless-react";
2024-07-09 14:11:20 +02:00
import { Chat, ChatMessage } from "../Model/chatModel";
2024-07-08 12:34:37 +02:00
2024-07-09 14:11:20 +02:00
import { selectedChat } from "../Model/model";
2024-07-08 12:34:37 +02:00
import { translation } from "../translations";
2024-07-07 22:11:18 +02:00
2024-07-09 14:11:20 +02:00
export function ThreadView() {
const threadViewContent = React.createProxyState([selectedChat], () => {
if (selectedChat.value == undefined)
return <div>{translation.noChatSelected}</div>;
2024-07-08 12:50:54 +02:00
2024-07-09 14:11:20 +02:00
const chat = selectedChat.value;
2024-07-08 12:34:37 +02:00
2024-07-09 14:11:20 +02:00
const messageConverter: React.ListItemConverter<ChatMessage> = (
message
) => {
function copyMessage() {
navigator.clipboard.writeText(message.body);
}
2024-07-08 12:50:54 +02:00
2024-07-09 14:11:20 +02:00
function decrypt() {
chat.decryptReceivedMessage(message);
}
2024-07-08 12:34:37 +02:00
2024-07-09 14:11:20 +02:00
function remove() {
chat.deleteMessage(message);
}
return (
<div class="tile width-100 flex-no padding-0">
<div class="flex-column">
<div class="flex-row justify-apart align-center secondary">
<span class="padding-h ellipsis">
<b class="info">{message.sender}</b> - {message.channel}
</span>
<span class="flex-row">
<button
aria-label={translation.copyMessage}
on:click={copyMessage}
>
<span class="icon">content_copy</span>
</button>
<button
aria-label={translation.decryptMessage}
on:click={decrypt}
>
<span class="icon">key</span>
</button>
<button
aria-label={translation.deleteMessage}
on:click={remove}
>
<span class="icon">delete</span>
</button>
</span>
</div>
<div class="flex-column padding-h padding-bottom">
<b class="break-word" subscribe:innerText={message.body}></b>
<span class="secondary">
{new Date(message.isoDate).toLocaleString()}
</span>
</div>
</div>
2024-07-08 12:34:37 +02:00
</div>
2024-07-09 14:11:20 +02:00
);
};
2024-07-07 22:11:18 +02:00
2024-07-09 14:11:20 +02:00
return (
<div
class="flex-column gap"
children:append={[chat.messages, messageConverter]}
></div>
);
});
return <div children:set={threadViewContent}></div>;
2024-07-07 22:11:18 +02:00
}