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
+88
-14
No files matched your search
@@ -61,7 +61,7 @@
|
|||||||
rounding="pill"
|
rounding="pill"
|
||||||
class="text-inherit dark:text-inherit disabled:opacity-20! disabled:bg-transparent!"
|
class="text-inherit dark:text-inherit disabled:opacity-20! disabled:bg-transparent!"
|
||||||
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
||||||
page <= 0}
|
page <= 1}
|
||||||
data-sveltekit-preload-data="off"
|
data-sveltekit-preload-data="off"
|
||||||
>
|
>
|
||||||
{#snippet suffix()}
|
{#snippet suffix()}
|
||||||
|
|||||||
@@ -309,7 +309,8 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"conversation": "This is the beginning of your conversation with {{user}}",
|
"conversation": "This is the beginning of your conversation with {{user}}",
|
||||||
"indicator": "Messaging {{user}}"
|
"indicator": "Messaging {{user}}",
|
||||||
|
"start": "Start chat"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moderation": {
|
"moderation": {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export async function load({ url, fetch }) {
|
|||||||
publishedToDate(a.published).getTime(),
|
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 => ({
|
notifications.update(i => ({
|
||||||
applications: i.applications,
|
applications: i.applications,
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { resolveRoute } from '$app/paths'
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
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 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 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 { publishedToDate } from '$lib/components/util/date.js'
|
||||||
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import type { Person, PrivateMessageView } from 'lemmy-js-client'
|
import type { Person, PrivateMessageView } from 'lemmy-js-client'
|
||||||
import { Spinner } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import { backOut } from 'svelte/easing'
|
import { ChatBubbleOvalLeftEllipsis, Icon } from 'svelte-hero-icons'
|
||||||
|
import { expoOut } from 'svelte/easing'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
interface ConversationPreview {
|
interface ConversationPreview {
|
||||||
@@ -59,18 +66,55 @@
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let searchModal = $state<{ open: boolean; user?: number }>({
|
||||||
|
open: false,
|
||||||
|
user: undefined,
|
||||||
|
})
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
</script>
|
</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>
|
<Header pageHeader>
|
||||||
{$t('filter.inbox.messages')}
|
{$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>
|
</Header>
|
||||||
{#await data.messages}
|
{#await data.messages}
|
||||||
<div class="w-full h-full grid place-items-center">
|
<div class="w-full h-full flex flex-col gap-2">
|
||||||
<Spinner width={24} />
|
{#each new Array(5) as _, index}
|
||||||
|
{_}
|
||||||
|
<div
|
||||||
|
in:fly|global={{
|
||||||
|
duration: 1000,
|
||||||
|
easing: expoOut,
|
||||||
|
y: 12,
|
||||||
|
delay: index * 50,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Skeleton />
|
||||||
</div>
|
</div>
|
||||||
{:then data}
|
{/each}
|
||||||
{@const conversations = data.private_messages}
|
</div>
|
||||||
|
{:then res}
|
||||||
|
{@const conversations = res.private_messages}
|
||||||
{@const previews = conversationPreviews(conversations)}
|
{@const previews = conversationPreviews(conversations)}
|
||||||
|
|
||||||
<ul
|
<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
|
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"
|
hover:bg-slate-100 dark:hover:bg-zinc-900 transition-colors"
|
||||||
in:fly|global={{
|
in:fly|global={{
|
||||||
duration: 700,
|
duration: 1000,
|
||||||
easing: backOut,
|
easing: expoOut,
|
||||||
y: 12,
|
y: 12,
|
||||||
delay: index * 100,
|
delay: index * 50,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Avatar url={preview.user.avatar} alt={preview.user.name} width={32} />
|
<Avatar url={preview.user.avatar} alt={preview.user.name} width={32} />
|
||||||
<div class="flex flex-col w-full overflow-hidden">
|
<div class="flex flex-col w-full overflow-hidden">
|
||||||
<div class="font-medium">{preview.user.name}</div>
|
<div class="font-medium">{preview.user.name}</div>
|
||||||
|
<div class="flex w-full">
|
||||||
<div
|
<div
|
||||||
class="text-sm text-ellipsis whitespace-nowrap
|
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
|
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"
|
text-transparent bg-clip-text flex-1 overflow-hidden"
|
||||||
>
|
>
|
||||||
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
||||||
{profile.data.user?.local_user_view.person.name}:
|
{profile.data.user?.local_user_view.person.name}:
|
||||||
{/if}
|
{/if}
|
||||||
{preview.message.content}
|
{preview.message.content}
|
||||||
</div>
|
</div>
|
||||||
|
<RelativeDate
|
||||||
|
date={preview.message.date}
|
||||||
|
class="inline-block text-xs text-slate-600 dark:text-zinc-400 shrink-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</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}
|
{/await}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
import { client } from '$lib/lemmy.svelte.js'
|
import { client } from '$lib/lemmy.svelte.js'
|
||||||
import { awaitIfServer } from '$lib/promise.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
|
// TODO probably add proper paging
|
||||||
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
||||||
limit: 50,
|
limit: 50,
|
||||||
|
page: page,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages: (await awaitIfServer(messagePromise)).data,
|
messages: (await awaitIfServer(messagePromise)).data,
|
||||||
|
page: page,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
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 { t } from '$lib/i18n/translations'
|
||||||
import type { PrivateMessageView } from 'lemmy-js-client'
|
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||||
@@ -21,6 +23,7 @@
|
|||||||
: 'flex-row'}"
|
: 'flex-row'}"
|
||||||
style="max-width: min(80vw,24rem)"
|
style="max-width: min(80vw,24rem)"
|
||||||
>
|
>
|
||||||
|
<div>
|
||||||
<div
|
<div
|
||||||
class="{primary
|
class="{primary
|
||||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-75'
|
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-75'
|
||||||
@@ -33,6 +36,12 @@
|
|||||||
class="w-full"
|
class="w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</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>
|
<Menu>
|
||||||
{#snippet target()}
|
{#snippet target()}
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in new issue
Block a user