From a165e76486270d5a8bdb1cf64ebd0d19eeeba3d8 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 22 Dec 2024 21:56:51 -0700 Subject: [PATCH] refac: styling --- src/lib/components/channel/Channel.svelte | 12 +-- .../components/channel/MessageInput.svelte | 33 ++++++++ src/lib/components/channel/Messages.svelte | 49 ++++++------ .../channel/Messages/Message.svelte | 80 ++++++++++++++++++- 4 files changed, 143 insertions(+), 31 deletions(-) diff --git a/src/lib/components/channel/Channel.svelte b/src/lib/components/channel/Channel.svelte index af337f500..dbcbca29f 100644 --- a/src/lib/components/channel/Channel.svelte +++ b/src/lib/components/channel/Channel.svelte @@ -20,6 +20,10 @@ initHandler(); } + const scrollToBottom = () => { + messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + }; + const initHandler = async () => { top = false; page = 1; @@ -80,13 +84,11 @@
- +
diff --git a/src/lib/components/channel/MessageInput.svelte b/src/lib/components/channel/MessageInput.svelte index be987f1cc..89e32f3ab 100644 --- a/src/lib/components/channel/MessageInput.svelte +++ b/src/lib/components/channel/MessageInput.svelte @@ -18,6 +18,8 @@ let content = ''; export let onSubmit: Function; + export let scrollEnd = true; + export let scrollToBottom: Function; let submitHandler = async () => { if (content === '') { @@ -36,6 +38,37 @@ }; +
+
+
+ {#if scrollEnd === false} +
+ +
+ {/if} +
+
+
+
diff --git a/src/lib/components/channel/Messages.svelte b/src/lib/components/channel/Messages.svelte index 377792b9e..bfcaa586a 100644 --- a/src/lib/components/channel/Messages.svelte +++ b/src/lib/components/channel/Messages.svelte @@ -9,7 +9,6 @@ import Message from './Messages/Message.svelte'; import Loader from '../common/Loader.svelte'; import Spinner from '../common/Spinner.svelte'; - import { getChannelMessages } from '$lib/apis/channels'; const i18n = getContext('i18n'); @@ -35,28 +34,32 @@ {#if messages} -
-
- {#if !top} - { - console.log('visible'); - if (!messagesLoading) { - loadMoreMessages(); - } - }} - > -
- -
Loading...
-
-
- {/if} + {@const messageList = messages.slice().reverse()} +
+ {#if !top} + { + console.log('visible'); + if (!messagesLoading) { + loadMoreMessages(); + } + }} + > +
+ +
Loading...
+
+
+ {/if} - {#each messages.slice().reverse() as message, messageIdx (message.id)} - - {/each} -
+ {#each messageList as message, messageIdx (message.id)} + + {/each} + +
-
{/if} diff --git a/src/lib/components/channel/Messages/Message.svelte b/src/lib/components/channel/Messages/Message.svelte index 3496fc6f3..ec66f6274 100644 --- a/src/lib/components/channel/Messages/Message.svelte +++ b/src/lib/components/channel/Messages/Message.svelte @@ -1,13 +1,87 @@ {#if message} -
-
- +
+
+
+ {#if showUserProfile} + + {:else} +
+ {/if} +
+ +
+ {#if showUserProfile} + + {message?.user?.name} + + {#if message.created_at} + + {/if} + + {/if} + +
+ +
+
{/if}