waffle/frontend/src/components/Message.svelte

149 lines
3.7 KiB
Svelte
Raw Normal View History

<script>
import { overlayStore, OverlayType, setMessageInputEvent } from "../stores";
2022-04-26 23:15:49 +03:00
export let message;
2022-09-01 19:56:19 +03:00
const reply = () => {
let replyString = "";
const messageLines = message.content.split("\n");
messageLines.forEach(line => {
replyString += `> ${line}\n`;
});
replyString += `@${message.author_username}: `;
2022-09-01 19:56:19 +03:00
setMessageInputEvent.emit(replyString);
2022-09-01 19:56:19 +03:00
};
</script>
<style>
.message {
display: flex;
align-items: flex-start;
2022-08-31 16:12:54 +03:00
overflow-x: hidden;
2022-10-30 21:44:46 +02:00
word-wrap: break-word;
padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-normplus);
}
.message.pinged {
background-color: var(--background-color-2);
}
2022-04-26 23:15:49 +03:00
.message .edit-message {
visibility: hidden;
}
.message:hover {
background-color: var(--background-color-3);
2022-04-26 23:15:49 +03:00
}
.message:hover .edit-message {
visibility: visible;
}
.message-content {
color: var(--foreground-color-2);
2022-05-07 16:50:04 +03:00
white-space: pre-wrap;
}
.pending {
color: var(--foreground-color-3);
}
.author {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-weight: bold;
margin-right: var(--space-xs);
}
2022-04-26 23:15:49 +03:00
.author-more {
margin-right: 0;
}
2022-10-30 21:44:46 +02:00
.author-group {
display: inline-flex;
align-items: center;
flex-shrink: 0;
}
2022-04-26 23:15:49 +03:00
.edit-message {
flex-shrink: 0;
2022-04-26 23:15:49 +03:00
float: right;
}
2022-09-03 20:46:27 +03:00
.date {
display: inline-flex;
justify-content: center;
align-items: center;
background-color: var(--background-color-2);
padding-top: 1px;
padding-bottom: 1px;
padding-left: 0.375rem;
padding-right: 0.375rem;
border-radius: 9999px;
font-size: small;
visibility: hidden;
margin-left: auto;
flex-shrink: 0;
2022-09-20 23:36:12 +03:00
user-select: none;
2022-09-03 20:46:27 +03:00
}
2022-10-30 21:44:46 +02:00
.message.clumped .author-group {
2022-09-06 20:52:44 +03:00
visibility: hidden;
}
.message:hover .date,
2022-10-30 21:44:46 +02:00
.message.clumped:hover .author-group {
2022-09-03 20:46:27 +03:00
visibility: visible;
}
@media (max-width: 768px) {
.message {
padding: var(--space-xxs) var(--space-xxs) var(--space-xxs) var(--space-normplus);
}
.message .message-extra {
display: none;
}
.message:hover .message-extra {
display: inline-flex;
}
}
.message.clumped {
padding: 2px 2px 2px var(--space-normplus);
}
.via-badge {
margin-left: var(--space-xs);
margin-right: var(--space-md);
cursor: default;
2022-10-30 21:44:46 +02:00
flex-shrink: 0;
}
</style>
2022-09-06 20:52:44 +03:00
<div class="message" class:clumped={ message._clumped } class:pinged={ message._mentions }>
2022-10-30 21:44:46 +02:00
<div class="author-group">
<span class="author" class:author-more={message._viaBadge}>{ message._effectiveAuthor }</span>
{#if message._viaBadge}
<span class="user-badge via-badge">via { message._viaBadge }</span>
{/if}
</div>
<span class="message-content" class:pending={ message._isPending }>{ message.content }</span>
2022-09-03 20:46:27 +03:00
<span class="date message-extra">{ message._createdAtTimeString }</span>
<button class="icon-button edit-message message-extra material-icons-outlined" on:click="{ reply }" aria-label="Reply to Message">
reply
2022-09-01 19:56:19 +03:00
</button>
2022-09-06 20:52:44 +03:00
{#if message._editable}
<button class="icon-button edit-message message-extra material-icons-outlined" on:click="{ () => overlayStore.push(OverlayType.EditMessage, { message }) }" aria-label="Edit Message">
edit
</button>
{/if}
</div>