Commit 7efd4870 authored by timel's avatar timel

optimize: chat

parent 6bffabe4
...@@ -16,10 +16,8 @@ ...@@ -16,10 +16,8 @@
} }
.dialogs { .dialogs {
position: absolute;
padding: 8px 0; padding: 8px 0;
overflow-y: scroll;
scroll-behavior: smooth;
max-height: 85vh;
.item { .item {
vertical-align: baseline; vertical-align: baseline;
.name { .name {
......
...@@ -20,9 +20,8 @@ export const Chat: React.FC = () => { ...@@ -20,9 +20,8 @@ export const Chat: React.FC = () => {
const chat = useSnapshot(chatStore); const chat = useSnapshot(chatStore);
useEffect(() => { useEffect(() => {
if (chatStore.sender >= 0 && chatStore.message.length != 0) { if (chatStore.sender >= 0 && chatStore.message.length !== 0) {
const now = new Date(); const { sender } = chatStore;
const sender = chatStore.sender;
const name = const name =
sender < roomStore.players.length sender < roomStore.players.length
? roomStore.players[sender]?.name ?? "?" ? roomStore.players[sender]?.name ?? "?"
...@@ -33,7 +32,7 @@ export const Chat: React.FC = () => { ...@@ -33,7 +32,7 @@ export const Chat: React.FC = () => {
...prev, ...prev,
{ {
name: name, name: name,
time: `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`, time: formatTimeToHHMMSS(),
content: chatStore.message, content: chatStore.message,
}, },
]); ]);
...@@ -81,3 +80,11 @@ const DialogItem: React.FC<ChatItem> = ({ name, time, content }) => { ...@@ -81,3 +80,11 @@ const DialogItem: React.FC<ChatItem> = ({ name, time, content }) => {
</div> </div>
); );
}; };
function formatTimeToHHMMSS() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, "0");
const minutes = String(now.getMinutes()).padStart(2, "0");
const seconds = String(now.getSeconds()).padStart(2, "0");
return `${hours}:${minutes}:${seconds}`;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment