waffle/frontend/src/components/Message.svelte

123 lines
3 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 {
2022-11-12 21:39:21 +02:00
position: relative;
2022-08-31 16:12:54 +03:00
overflow-x: hidden;
2022-10-30 21:44:46 +02:00
word-wrap: break-word;
2022-11-12 21:39:21 +02:00
padding: 3px 3px 3px var(--space-normplus);
margin-top: 16px;
}
2022-11-12 21:39:21 +02:00
.message:hover, .message.pinged {
background-color: var(--background-color-2);
}
.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 {
2022-11-12 21:39:21 +02:00
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-weight: bold;
2022-11-12 21:39:21 +02:00
color: var(--foreground-color-2);
}
2022-04-26 23:15:49 +03:00
.author-more {
margin-right: 0;
}
2022-10-30 21:44:46 +02:00
.author-group {
2022-11-12 21:39:21 +02:00
display: flex;
2022-10-30 21:44:46 +02:00
align-items: center;
flex-shrink: 0;
}
2022-11-12 21:39:21 +02:00
.message-author-date {
color: var(--foreground-color-3);
font-size: 0.7rem;
margin-left: var(--space-sm);
2022-04-26 23:15:49 +03:00
}
2022-09-03 20:46:27 +03:00
2022-11-12 21:39:21 +02:00
.message.clumped {
margin-top: 0;
2022-09-03 20:46:27 +03:00
}
2022-11-12 21:39:21 +02:00
.via-badge {
background-color: var(--background-color-3);
margin-left: var(--space-xs);
cursor: default;
flex-shrink: 0;
2022-09-06 20:52:44 +03:00
}
2022-11-12 21:39:21 +02:00
.message-actions {
display: flex;
position: absolute;
top: 3px;
right: 12px;
z-index: 1;
2022-09-03 20:46:27 +03:00
}
2022-11-12 21:39:21 +02:00
.message-actions .icon-button {
margin: 0;
padding: 0;
}
2022-11-12 21:39:21 +02:00
.message .message-actions {
display: none;
}
2022-11-12 21:39:21 +02:00
.message:hover .message-actions {
display: flex;
}
</style>
2022-11-12 21:39:21 +02:00
<div class="message" class:clumped={ message._clumped } class:has-children={ message._hasChildren } class:pinged={ message._mentions }>
{#if !message._clumped}
<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}
<span class="message-author-date">{ message._createdAtTimeString }</span>
</div>
{/if}
<span class="message-content" class:pending={ message._isPending }>{ message.content }</span>
2022-09-03 20:46:27 +03:00
2022-11-12 21:39:21 +02:00
<div class="message-actions">
<button class="icon-button material-icons-outlined" on:click="{ reply }" aria-label="Reply to Message">
reply
</button>
2022-11-12 21:39:21 +02:00
{#if message._editable}
<button class="icon-button material-icons-outlined" on:click="{ () => overlayStore.push(OverlayType.EditMessage, { message }) }" aria-label="Edit Message">
edit
</button>
{/if}
</div>
</div>