feat: add new messages ui
This commit is contained in:
1 parent
ffdcac6c79
commit
a77b3b3b78
10 files changed
+409
-23
No files matched your search
@@ -3,22 +3,34 @@
|
|||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type {
|
||||||
|
CommentView,
|
||||||
|
PostView,
|
||||||
|
PrivateMessageView,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||||
|
|
||||||
export let open: boolean
|
export let open: boolean
|
||||||
export let item: PostView | CommentView | undefined = undefined
|
export let item: PostView | CommentView | PrivateMessageView | undefined =
|
||||||
|
undefined
|
||||||
|
|
||||||
const isComment = (item: PostView | CommentView): item is CommentView =>
|
const isComment = (
|
||||||
'comment' in item
|
item: PostView | CommentView | PrivateMessageView
|
||||||
|
): item is CommentView => 'comment' in item
|
||||||
|
|
||||||
const isPost = (item: PostView | CommentView): item is PostView =>
|
const isPost = (
|
||||||
!isComment(item)
|
item: PostView | CommentView | PrivateMessageView
|
||||||
|
): item is PostView => !isComment(item) && 'post' in item
|
||||||
|
|
||||||
|
const isPrivateMessage = (
|
||||||
|
item: PostView | CommentView | PrivateMessageView
|
||||||
|
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||||
|
|
||||||
let loading = false
|
let loading = false
|
||||||
let reason = ''
|
let reason = ''
|
||||||
@@ -38,6 +50,11 @@
|
|||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
|
} else if (isPrivateMessage(item)) {
|
||||||
|
await getClient().createPrivateMessageReport({
|
||||||
|
private_message_id: item.private_message.id,
|
||||||
|
reason: reason,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
open = false
|
open = false
|
||||||
toast({
|
toast({
|
||||||
@@ -77,6 +94,8 @@
|
|||||||
/>
|
/>
|
||||||
{:else if isPost(item)}
|
{:else if isPost(item)}
|
||||||
<Post actions={false} post={item} />
|
<Post actions={false} post={item} />
|
||||||
|
{:else}
|
||||||
|
<PrivateMessage message={item} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import { client } from '$lib/lemmy'
|
import { client } from '$lib/lemmy'
|
||||||
import type { SubmissionView } from '$lib/lemmy/contentview.js'
|
import type { SubmissionView } from '$lib/lemmy/contentview.js'
|
||||||
import type { Comment, Community, MyUserInfo, Person } from 'lemmy-js-client'
|
import type {
|
||||||
|
Comment,
|
||||||
|
CommentView,
|
||||||
|
Community,
|
||||||
|
MyUserInfo,
|
||||||
|
Person,
|
||||||
|
PostView,
|
||||||
|
PrivateMessageView,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
|
||||||
interface Modals {
|
interface Modals {
|
||||||
reporting: {
|
reporting: {
|
||||||
open: boolean
|
open: boolean
|
||||||
item: SubmissionView | undefined
|
item: PostView | CommentView | PrivateMessageView | undefined
|
||||||
}
|
}
|
||||||
removing: {
|
removing: {
|
||||||
open: boolean
|
open: boolean
|
||||||
@@ -39,7 +47,7 @@ export let modals = writable<Modals>({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export function report(item: SubmissionView) {
|
export function report(item: PostView | CommentView | PrivateMessageView) {
|
||||||
modals.update((m) => ({
|
modals.update((m) => ({
|
||||||
...m,
|
...m,
|
||||||
reporting: {
|
reporting: {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { invalidate } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
@@ -6,6 +7,7 @@
|
|||||||
href: string
|
href: string
|
||||||
name: string
|
name: string
|
||||||
}[]
|
}[]
|
||||||
|
export let currentRoute: string | undefined = undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav
|
<nav
|
||||||
@@ -16,12 +18,13 @@
|
|||||||
>
|
>
|
||||||
{#each routes as route}
|
{#each routes as route}
|
||||||
<a
|
<a
|
||||||
|
on:click={() => invalidate(route.href)}
|
||||||
href={route.href}
|
href={route.href}
|
||||||
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
||||||
transition-colors duration-100 relative z-0"
|
transition-colors duration-100 relative z-0"
|
||||||
>
|
>
|
||||||
{route.name}
|
{route.name}
|
||||||
{#if $page.url.pathname == route.href}
|
{#if (currentRoute ?? $page.url.pathname) == route.href}
|
||||||
<div
|
<div
|
||||||
class="rounded-full bg-slate-100/60 dark:bg-zinc-700/60
|
class="rounded-full bg-slate-100/60 dark:bg-zinc-700/60
|
||||||
absolute inset-0 w-full h-full -z-10"
|
absolute inset-0 w-full h-full -z-10"
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export const generalizeCommentReport = (
|
|||||||
saved: false,
|
saved: false,
|
||||||
creator_blocked: false,
|
creator_blocked: false,
|
||||||
creator: report.comment_creator,
|
creator: report.comment_creator,
|
||||||
|
banned_from_community: false,
|
||||||
},
|
},
|
||||||
reason: report.comment_report.reason,
|
reason: report.comment_report.reason,
|
||||||
type: 'comment',
|
type: 'comment',
|
||||||
@@ -65,6 +66,7 @@ export const generalizePostReport = (report: PostReportView): ReportView => ({
|
|||||||
read: false,
|
read: false,
|
||||||
subscribed: 'NotSubscribed',
|
subscribed: 'NotSubscribed',
|
||||||
creator: report.post_creator,
|
creator: report.post_creator,
|
||||||
|
banned_from_community: false,
|
||||||
},
|
},
|
||||||
reason: report.post_report.reason,
|
reason: report.post_report.reason,
|
||||||
type: 'post',
|
type: 'post',
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||||
|
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -78,6 +80,33 @@
|
|||||||
</Header>
|
</Header>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4" />
|
<div class="mt-4" />
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="mt-4 mb-0 sticky z-30 mx-auto"
|
||||||
|
style="top: max(1.5rem, {$contentPadding.top}px);"
|
||||||
|
>
|
||||||
|
<Tabs
|
||||||
|
routes={[
|
||||||
|
{
|
||||||
|
href: '/inbox',
|
||||||
|
name: $t('filter.location.all'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: '/inbox?type=Replies',
|
||||||
|
name: $t('filter.inbox.replies'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: '/inbox?type=Mentions',
|
||||||
|
name: $t('filter.inbox.mentions'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: '/inbox/messages',
|
||||||
|
name: $t('filter.inbox.messages'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
currentRoute="{$page.url.pathname}{$page.url.search}"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="flex flex-row gap-4 flex-wrap items-end">
|
<div class="flex flex-row gap-4 flex-wrap items-end">
|
||||||
<Select
|
<Select
|
||||||
bind:value={data.unreadOnly}
|
bind:value={data.unreadOnly}
|
||||||
@@ -96,19 +125,6 @@
|
|||||||
<option value="false">{$t('filter.location.all')}</option>
|
<option value="false">{$t('filter.location.all')}</option>
|
||||||
<option value="true">{$t('filter.unread')}</option>
|
<option value="true">{$t('filter.unread')}</option>
|
||||||
</Select>
|
</Select>
|
||||||
<Select
|
|
||||||
bind:value={data.type}
|
|
||||||
on:change={() => searchParam($page.url, 'type', data.type ?? 'all', 'page')}
|
|
||||||
>
|
|
||||||
<span slot="label" class="flex items-center gap-1">
|
|
||||||
<Icon src={AdjustmentsHorizontal} size="15" mini />
|
|
||||||
{$t('filter.type')}
|
|
||||||
</span>
|
|
||||||
<option value="all">{$t('filter.location.all')}</option>
|
|
||||||
<option value="mentions">{$t('filter.inbox.mentions')}</option>
|
|
||||||
<option value="replies">{$t('filter.inbox.replies')}</option>
|
|
||||||
<option value="messages">{$t('filter.inbox.messages')}</option>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-4 list-none flex-1 h-full justify-center mt-4">
|
<div class="flex flex-col gap-4 list-none flex-1 h-full justify-center mt-4">
|
||||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth'
|
||||||
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
|
import { t } from '$lib/translations.js'
|
||||||
|
import type {
|
||||||
|
Person,
|
||||||
|
PrivateMessageResponse,
|
||||||
|
PrivateMessageView,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
|
import { Spinner } from 'mono-svelte'
|
||||||
|
import { backOut } from 'svelte/easing'
|
||||||
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
|
interface ConversationPreview {
|
||||||
|
user: Person
|
||||||
|
message: {
|
||||||
|
date: Date
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterDuplicates<T, K>(array: T[], predicate: (item: T) => K): T[] {
|
||||||
|
const seen = new Set()
|
||||||
|
return array.filter((element) => {
|
||||||
|
const value = predicate(element)
|
||||||
|
if (seen.has(value)) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
seen.add(value)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function conversationPreviews(
|
||||||
|
conversations: PrivateMessageView[]
|
||||||
|
): ConversationPreview[] {
|
||||||
|
const deduplicated = filterDuplicates(
|
||||||
|
conversations.toReversed(),
|
||||||
|
(i) => i.creator.id
|
||||||
|
)
|
||||||
|
|
||||||
|
return deduplicated.map((i) => ({
|
||||||
|
user: i.creator,
|
||||||
|
message: {
|
||||||
|
date: publishedToDate(i.private_message.published),
|
||||||
|
content: i.private_message.content,
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
export let data
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header pageHeader>
|
||||||
|
{$t('filter.inbox.messages')}
|
||||||
|
</Header>
|
||||||
|
{#await data.messages}
|
||||||
|
<Spinner width={24} />
|
||||||
|
{:then data}
|
||||||
|
{@const conversations = data.private_messages}
|
||||||
|
{@const previews = conversationPreviews(conversations).filter(
|
||||||
|
(c) => c.user.id != $profile?.user?.local_user_view.person.id
|
||||||
|
)}
|
||||||
|
|
||||||
|
<ul
|
||||||
|
class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-800 w-full mt-6"
|
||||||
|
>
|
||||||
|
{#each previews as preview, index}
|
||||||
|
<a
|
||||||
|
href="/inbox/messages/{preview.user.id}"
|
||||||
|
class="flex flex-row gap-2 py-3 -mx-4 px-4 sm:-mx-6 sm:px-6 w-full min-w-0
|
||||||
|
hover:bg-slate-100 hover:dark:bg-zinc-900 transition-colors"
|
||||||
|
in:fly|global={{
|
||||||
|
duration: 700,
|
||||||
|
easing: backOut,
|
||||||
|
y: 12,
|
||||||
|
delay: index * 100,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Avatar url={preview.user.avatar} alt={preview.user.name} width={32} />
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div class="font-medium">{preview.user.name}</div>
|
||||||
|
<div class="text-slate-700 dark:text-zinc-300 text-sm">
|
||||||
|
{preview.message.content}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/await}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { client } from '$lib/lemmy.js'
|
||||||
|
import { awaitIfServer } from '$lib/promise.js'
|
||||||
|
|
||||||
|
export async function load({ fetch, url }) {
|
||||||
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
|
||||||
|
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
||||||
|
limit: 50,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
messages: (await awaitIfServer(messagePromise)).data,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Button, Material, Spinner, TextInput, toast } from 'mono-svelte'
|
||||||
|
import Message from './Message.svelte'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { Icon, PaperAirplane } from 'svelte-hero-icons'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { fly } from 'svelte/transition'
|
||||||
|
import { backOut, expoOut } from 'svelte/easing'
|
||||||
|
import { client } from '$lib/lemmy'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import type { PrivateMessageResponse } from 'lemmy-js-client'
|
||||||
|
import { flip } from 'svelte/animate'
|
||||||
|
import { browser } from '$app/environment'
|
||||||
|
import { onMount, tick } from 'svelte'
|
||||||
|
import { report } from '$lib/components/lemmy/moderation/moderation'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
|
||||||
|
let textbox = {
|
||||||
|
message: '',
|
||||||
|
loading: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
let chatWindow: HTMLDivElement
|
||||||
|
|
||||||
|
async function sendMessage(
|
||||||
|
message: string
|
||||||
|
): Promise<PrivateMessageResponse | undefined> {
|
||||||
|
if (message == '') return
|
||||||
|
|
||||||
|
textbox.loading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await client().createPrivateMessage({
|
||||||
|
content: message,
|
||||||
|
recipient_id: data.creator,
|
||||||
|
})
|
||||||
|
|
||||||
|
textbox.loading = false
|
||||||
|
|
||||||
|
return res
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: errorMessage(err as any),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
textbox.loading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (browser && data.message && chatWindow) {
|
||||||
|
tick().then(() =>
|
||||||
|
chatWindow.scrollTo({ top: chatWindow.scrollHeight, behavior: 'smooth' })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteMessage(id: number) {
|
||||||
|
const res = await client().deletePrivateMessage({
|
||||||
|
deleted: true,
|
||||||
|
private_message_id: id,
|
||||||
|
})
|
||||||
|
|
||||||
|
data.message = {
|
||||||
|
private_messages: data.message.private_messages.toSpliced(
|
||||||
|
data.message.private_messages.findLastIndex(
|
||||||
|
(i) => i.private_message.id == id
|
||||||
|
),
|
||||||
|
1
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header pageHeader>
|
||||||
|
{$t('filter.inbox.messages')}
|
||||||
|
</Header>
|
||||||
|
<Material
|
||||||
|
color="transparent"
|
||||||
|
rounding="2xl"
|
||||||
|
padding="none"
|
||||||
|
class="bg-white dark:bg-zinc-950 dark:border-t-zinc-900
|
||||||
|
w-full overflow-auto mt-6 relative max-h-[32rem]"
|
||||||
|
>
|
||||||
|
<div class="h-full overflow-auto" bind:this={chatWindow}>
|
||||||
|
<ul id="chat-window" class="flex flex-col gap-1 flex-1 px-4 py-4">
|
||||||
|
<div class="mt-auto" />
|
||||||
|
{#each data.message.private_messages.toReversed() as private_message, index (private_message.private_message.id)}
|
||||||
|
<div
|
||||||
|
class={private_message.creator.id == data.creator
|
||||||
|
? 'self-start'
|
||||||
|
: 'self-end'}
|
||||||
|
in:fly|global={{
|
||||||
|
duration: 700,
|
||||||
|
easing: backOut,
|
||||||
|
delay: data.message.private_messages.length * 50 - index * 50,
|
||||||
|
y: -12,
|
||||||
|
}}
|
||||||
|
animate:flip={{ duration: 500, easing: expoOut }}
|
||||||
|
>
|
||||||
|
<Message
|
||||||
|
on:delete={() => deleteMessage(private_message.private_message.id)}
|
||||||
|
on:report={() => report(private_message)}
|
||||||
|
message={private_message}
|
||||||
|
primary={private_message.creator.id != data.creator}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</Material>
|
||||||
|
{#await data.message then message}
|
||||||
|
<div class="sticky bottom-4 p-4">
|
||||||
|
<form
|
||||||
|
class="flex flex-row h-14 items-center w-full
|
||||||
|
border-slate-200 dark:border-zinc-800
|
||||||
|
p-2 gap-2 backdrop-blur-xl
|
||||||
|
bg-white/50 dark:bg-zinc-950/50 border rounded-2xl"
|
||||||
|
on:submit|preventDefault={async () => {
|
||||||
|
const res = await sendMessage(textbox.message)
|
||||||
|
if (!res) return
|
||||||
|
|
||||||
|
data.message = {
|
||||||
|
private_messages: [
|
||||||
|
res.private_message_view,
|
||||||
|
...message.private_messages,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
textbox.message = ''
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
bind:value={textbox.message}
|
||||||
|
class="!rounded-xl h-full flex-1 dark:!bg-zinc-925"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
title={$t('common.send')}
|
||||||
|
size="custom"
|
||||||
|
rounding="xl"
|
||||||
|
class="aspect-square h-9"
|
||||||
|
color="primary"
|
||||||
|
submit
|
||||||
|
loading={textbox.loading}
|
||||||
|
disabled={textbox.loading}
|
||||||
|
>
|
||||||
|
<Icon src={PaperAirplane} size="18" micro slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{/await}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#chat-window {
|
||||||
|
box-shadow: inset 0px -10px 15px -10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { client } from '$lib/lemmy.js'
|
||||||
|
import { awaitIfServer } from '$lib/promise.js'
|
||||||
|
|
||||||
|
export async function load({ fetch, params }) {
|
||||||
|
return {
|
||||||
|
message: await client().getPrivateMessages({
|
||||||
|
creator_id: Number(params.user_id),
|
||||||
|
limit: 50,
|
||||||
|
page: 1,
|
||||||
|
}),
|
||||||
|
creator: Number(params.user_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
import { client } from '$lib/lemmy'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||||
|
import { Button, Menu, MenuButton, MenuDivider, Popover } from 'mono-svelte'
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
import { EllipsisVertical, Flag, Icon, Trash } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let message: PrivateMessageView
|
||||||
|
export let primary: boolean = false
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher<{ delete: boolean; report: boolean }>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="group relative w-full flex gap-1 items-center {primary
|
||||||
|
? 'flex-row-reverse'
|
||||||
|
: 'flex-row'}"
|
||||||
|
style="max-width: min(70vw,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-max p-1.5 px-3
|
||||||
|
font-medium cursor-pointer transition-all"
|
||||||
|
>
|
||||||
|
<Markdown source={message.private_message.content} inline />
|
||||||
|
</div>
|
||||||
|
<Menu>
|
||||||
|
<Button
|
||||||
|
color="tertiary"
|
||||||
|
class="opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-all flex-shrink-0"
|
||||||
|
size="square-md"
|
||||||
|
rounding="pill"
|
||||||
|
slot="target"
|
||||||
|
title={$t('post.actions.more.actions')}
|
||||||
|
>
|
||||||
|
<Icon src={EllipsisVertical} size="16" micro />
|
||||||
|
</Button>
|
||||||
|
<MenuDivider>{$t('post.actions.more.actions')}</MenuDivider>
|
||||||
|
{#if primary}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => dispatch('delete', true)}
|
||||||
|
>
|
||||||
|
<Icon src={Trash} size="16" micro slot="prefix" />
|
||||||
|
{$t('post.actions.more.delete')}
|
||||||
|
</MenuButton>
|
||||||
|
{:else}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => dispatch('report', true)}
|
||||||
|
>
|
||||||
|
<Icon src={Flag} size="16" micro slot="prefix" />
|
||||||
|
{$t('moderation.report')}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
Reference in new issue
Block a user