feat: improve messages experience (#572)
* impr: add message paginatin * impr: add message timestamps, close #569 * feat: add start chat button, close #566 * fix: frozen lockfile
This commit is contained in:
1 parent
ed960b969f
commit
7125a22252
7 files changed
+104
-30
No files matched your search
@@ -61,7 +61,7 @@
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit disabled:opacity-20! disabled:bg-transparent!"
|
||||
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
||||
page <= 0}
|
||||
page <= 1}
|
||||
data-sveltekit-preload-data="off"
|
||||
>
|
||||
{#snippet suffix()}
|
||||
|
||||
@@ -309,7 +309,8 @@
|
||||
},
|
||||
"messages": {
|
||||
"conversation": "This is the beginning of your conversation with {{user}}",
|
||||
"indicator": "Messaging {{user}}"
|
||||
"indicator": "Messaging {{user}}",
|
||||
"start": "Start chat"
|
||||
}
|
||||
},
|
||||
"moderation": {
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function load({ url, fetch }) {
|
||||
publishedToDate(a.published).getTime(),
|
||||
)
|
||||
|
||||
const totalNotifs = data.filter(i => !i.read).length
|
||||
const totalNotifs = type == 'all' ? data.filter(i => !i.read).length : 0
|
||||
|
||||
notifications.update(i => ({
|
||||
applications: i.applications,
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { resolveRoute } from '$app/paths'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import UserAutocomplete from '$lib/components/lemmy/user/UserAutocomplete.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import type { Person, PrivateMessageView } from 'lemmy-js-client'
|
||||
import { Spinner } from 'mono-svelte'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { ChatBubbleOvalLeftEllipsis, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
interface ConversationPreview {
|
||||
@@ -59,18 +66,55 @@
|
||||
}))
|
||||
}
|
||||
|
||||
let searchModal = $state<{ open: boolean; user?: number }>({
|
||||
open: false,
|
||||
user: undefined,
|
||||
})
|
||||
|
||||
let { data } = $props()
|
||||
</script>
|
||||
|
||||
<Modal bind:open={searchModal.open} title={$t('routes.inbox.messages.start')}>
|
||||
<UserAutocomplete
|
||||
listing_type="All"
|
||||
onselect={u =>
|
||||
goto(
|
||||
resolveRoute('/inbox/messages/[user_id]', { user_id: u.id.toString() }),
|
||||
)}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
<Header pageHeader>
|
||||
{$t('filter.inbox.messages')}
|
||||
{#snippet extended()}
|
||||
<Button
|
||||
color="primary"
|
||||
size="lg"
|
||||
onclick={() => (searchModal.open = !searchModal.open)}
|
||||
>
|
||||
<Icon src={ChatBubbleOvalLeftEllipsis} size="18" mini />
|
||||
{$t('routes.inbox.messages.start')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Header>
|
||||
{#await data.messages}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Spinner width={24} />
|
||||
<div class="w-full h-full flex flex-col gap-2">
|
||||
{#each new Array(5) as _, index}
|
||||
{_}
|
||||
<div
|
||||
in:fly|global={{
|
||||
duration: 1000,
|
||||
easing: expoOut,
|
||||
y: 12,
|
||||
delay: index * 50,
|
||||
}}
|
||||
>
|
||||
<Skeleton />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:then data}
|
||||
{@const conversations = data.private_messages}
|
||||
{:then res}
|
||||
{@const conversations = res.private_messages}
|
||||
{@const previews = conversationPreviews(conversations)}
|
||||
|
||||
<ul
|
||||
@@ -82,27 +126,43 @@
|
||||
class="flex flex-row gap-2 py-3 -mx-4 sm:-mx-6 px-4 sm:px-6 min-w-0
|
||||
hover:bg-slate-100 dark:hover:bg-zinc-900 transition-colors"
|
||||
in:fly|global={{
|
||||
duration: 700,
|
||||
easing: backOut,
|
||||
duration: 1000,
|
||||
easing: expoOut,
|
||||
y: 12,
|
||||
delay: index * 100,
|
||||
delay: index * 50,
|
||||
}}
|
||||
>
|
||||
<Avatar url={preview.user.avatar} alt={preview.user.name} width={32} />
|
||||
<div class="flex flex-col w-full overflow-hidden">
|
||||
<div class="font-medium">{preview.user.name}</div>
|
||||
<div
|
||||
class="text-sm text-ellipsis whitespace-nowrap
|
||||
<div class="flex w-full">
|
||||
<div
|
||||
class="text-sm text-ellipsis whitespace-nowrap
|
||||
bg-linear-to-r from-slate-700 via-slate-700 to-slate-700/0 dark:from-zinc-300 dark:via-zinc-300 dark:to-zinc-300/0
|
||||
text-transparent bg-clip-text"
|
||||
>
|
||||
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
||||
{profile.data.user?.local_user_view.person.name}:
|
||||
{/if}
|
||||
{preview.message.content}
|
||||
text-transparent bg-clip-text flex-1 overflow-hidden"
|
||||
>
|
||||
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
||||
{profile.data.user?.local_user_view.person.name}:
|
||||
{/if}
|
||||
{preview.message.content}
|
||||
</div>
|
||||
<RelativeDate
|
||||
date={preview.message.date}
|
||||
class="inline-block text-xs text-slate-600 dark:text-zinc-400 shrink-0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
{#if res.private_messages.length == 50 || data.page != 1}
|
||||
<div class="mt-auto pb-4">
|
||||
<Pageination
|
||||
page={data.page}
|
||||
hasMore={res.private_messages.length == 50}
|
||||
href={current => `/inbox/messages?page=${current}`}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/await}
|
||||
@@ -1,13 +1,17 @@
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { awaitIfServer } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
export async function load({ fetch, url }) {
|
||||
const page = Number(url.searchParams.get('page') || '1')
|
||||
|
||||
// TODO probably add proper paging
|
||||
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
||||
limit: 50,
|
||||
page: page,
|
||||
})
|
||||
|
||||
return {
|
||||
messages: (await awaitIfServer(messagePromise)).data,
|
||||
page: page,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
@@ -21,16 +23,23 @@
|
||||
: 'flex-row'}"
|
||||
style="max-width: min(80vw,24rem)"
|
||||
>
|
||||
<div
|
||||
class="{primary
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-75'
|
||||
: 'bg-slate-100 dark:bg-zinc-900 hover:brightness-125'} rounded-2xl w-full p-1.5 px-3
|
||||
<div>
|
||||
<div
|
||||
class="{primary
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-75'
|
||||
: 'bg-slate-100 dark:bg-zinc-900 hover:brightness-125'} rounded-2xl w-full p-1.5 px-3
|
||||
font-medium cursor-pointer transition-all"
|
||||
>
|
||||
<Markdown
|
||||
rendererOptions={{ autoloadImages: false }}
|
||||
source={message.private_message.content}
|
||||
class="w-full"
|
||||
>
|
||||
<Markdown
|
||||
rendererOptions={{ autoloadImages: false }}
|
||||
source={message.private_message.content}
|
||||
class="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<RelativeDate
|
||||
class="text-xs block -mt-0.5 ml-1 text-slate-600 dark:text-zinc-400"
|
||||
date={publishedToDate(message.private_message.published)}
|
||||
/>
|
||||
</div>
|
||||
<Menu>
|
||||
|
||||
Reference in new issue
Block a user