frontend: show pending messages in a different color
This commit is contained in:
parent
addfddd3ac
commit
459b1c6703
4 changed files with 20 additions and 4 deletions
|
@ -10,7 +10,8 @@
|
||||||
:root {
|
:root {
|
||||||
--background-color-1: hsl(180, 11%, 7%);
|
--background-color-1: hsl(180, 11%, 7%);
|
||||||
--background-color-2: hsl(180, 11%, 12%);
|
--background-color-2: hsl(180, 11%, 12%);
|
||||||
--foreground-color-1: #FFFFFF;
|
--foreground-color-1: hsl(0, 0%, 100%);
|
||||||
|
--foreground-color-2: hsl(0, 0%, 60%);
|
||||||
|
|
||||||
--space-unit: 1em;
|
--space-unit: 1em;
|
||||||
--space-xxs: calc(0.25 * var(--space-unit));
|
--space-xxs: calc(0.25 * var(--space-unit));
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
channel_id: channel.id,
|
channel_id: channel.id,
|
||||||
author_id: $userInfoStore.id,
|
author_id: $userInfoStore.id,
|
||||||
author_username: $userInfoStore.username,
|
author_username: $userInfoStore.username,
|
||||||
createdAt: Date.now().toString()
|
created_at: Date.now().toString(),
|
||||||
|
_isPending: true
|
||||||
};
|
};
|
||||||
messages.addMessage(optimisticMessage);
|
messages.addMessage(optimisticMessage);
|
||||||
messageInput = "";
|
messageInput = "";
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.success && res.ok) {
|
if (res.success && res.ok) {
|
||||||
messages.updateId(optimisticMessageId, res.json.id);
|
messages.setMessage(optimisticMessageId, res.json);
|
||||||
} else {
|
} else {
|
||||||
messages.deleteMessage({
|
messages.deleteMessage({
|
||||||
id: optimisticMessageId
|
id: optimisticMessageId
|
||||||
|
|
|
@ -41,13 +41,17 @@
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
background-color: var(--background-color-1);
|
background-color: var(--background-color-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pending {
|
||||||
|
color: var(--foreground-color-2);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="messages-container" on:scroll={ onScroll } bind:this={ scrollTarget }>
|
<div class="messages-container" on:scroll={ onScroll } bind:this={ scrollTarget }>
|
||||||
{#each $messages as message (message.id)}
|
{#each $messages as message (message.id)}
|
||||||
<div>
|
<div>
|
||||||
<b>{ message.author_username }</b>
|
<b>{ message.author_username }</b>
|
||||||
<span>{ message.content }</span>
|
<span class:pending={ message._isPending }>{ message.content }</span>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -104,6 +104,16 @@ class MessageStore extends Store {
|
||||||
this.didDoInitialLoad = false;
|
this.didDoInitialLoad = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setMessage(id, message) {
|
||||||
|
const index = this.value.findIndex(e => e.id === id);
|
||||||
|
if (index === -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.value[index] = message;
|
||||||
|
|
||||||
|
this.updated();
|
||||||
|
}
|
||||||
|
|
||||||
addMessage(message) {
|
addMessage(message) {
|
||||||
this.value.push(message);
|
this.value.push(message);
|
||||||
// only dispatch update if collectOldMessages didn't
|
// only dispatch update if collectOldMessages didn't
|
||||||
|
|
Loading…
Reference in a new issue