migrate: convert most components to svelte 5

This commit is contained in:
Xylight committed 2024-10-25 19:33:27 -07:00
1 parent d670f39f0a
commit 10ef4123da
225 files changed
+5441 -3341

No files matched your search

+8 -4
View File
@@ -25,9 +25,9 @@
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
import { expoOut } from 'svelte/easing'
export let data
let { data } = $props();
let markingAsRead = false
let markingAsRead = $state(false)
async function markAllAsRead() {
if (!$profile?.user) {
@@ -141,7 +141,9 @@ items-center px-2 w-max"
rounding="xl"
title={$t('common.refresh')}
>
<Icon src={ArrowPath} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={ArrowPath} size="16" mini />
{/snippet}
</Button>
<Button
on:click={markAllAsRead}
@@ -150,7 +152,9 @@ items-center px-2 w-max"
size="lg"
class="h-10"
>
<Icon src={Check} width={16} mini slot="prefix" />
{#snippet prefix()}
<Icon src={Check} width={16} mini />
{/snippet}
{$t('routes.inbox.markAsRead')}
</Button>
</div>
+107 -93
View File
@@ -28,11 +28,15 @@
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
export let item: InboxItem
interface Props {
item: InboxItem;
}
let replying = false
let { item = $bindable() }: Props = $props();
let replying = $state(false)
let reply = ''
let loading = false
let loading = $state(false)
async function markAsRead(isRead: boolean) {
if (!$profile?.jwt) return
@@ -74,55 +78,90 @@
{/if}
<Expandable open icon={false}>
<div class="flex flex-row gap-2 items-center w-full" slot="title">
<Avatar
url={item.creator.avatar}
circle={false}
width={28}
alt={item.creator.name}
/>
<!-- <div class="rounded-full p-1 border border-slate-200 dark:border-zinc-800">
<Icon
src={item.type == 'comment_reply'
? ChatBubbleOvalLeft
: item.type == 'private_message'
? Envelope
: item.type == 'person_mention'
? AtSymbol
: AtSymbol}
size="20"
mini
class="text-slate-600 dark:text-zinc-400"
{#snippet title()}
<div class="flex flex-row gap-2 items-center w-full" >
<Avatar
url={item.creator.avatar}
circle={false}
width={28}
alt={item.creator.name}
/>
</div> -->
<div class="flex flex-col">
<div class="text-sm font-normal">
{#if item.type == 'comment_reply'}
{@html $t('routes.inbox.item.reply', {
// @ts-ignore
user: `<span class="font-medium">${item.creator.name}</span>`,
post: `<span class="font-medium">${item.item.post.name}</span>`,
})}
{:else if item.type == 'person_mention'}
{@html $t('routes.inbox.item.mention', {
// @ts-ignore
user: `<span class="font-medium">${item.creator.name}</span>`,
post: `<span class="font-medium">${item.item.post.name}</span>`,
})}
{:else if item.type == 'private_message'}
{@html $t('routes.inbox.item.message', {
// @ts-ignore
user: `<span class="font-medium">${item.item.creator.name}</span>`,
recipient: `<span class="font-medium">${item.item.recipient.name}</span>`,
})}
<!-- <div class="rounded-full p-1 border border-slate-200 dark:border-zinc-800">
<Icon
src={item.type == 'comment_reply'
? ChatBubbleOvalLeft
: item.type == 'private_message'
? Envelope
: item.type == 'person_mention'
? AtSymbol
: AtSymbol}
size="20"
mini
class="text-slate-600 dark:text-zinc-400"
/>
</div> -->
<div class="flex flex-col">
<div class="text-sm font-normal">
{#if item.type == 'comment_reply'}
{@html $t('routes.inbox.item.reply', {
// @ts-ignore
user: `<span class="font-medium">${item.creator.name}</span>`,
post: `<span class="font-medium">${item.item.post.name}</span>`,
})}
{:else if item.type == 'person_mention'}
{@html $t('routes.inbox.item.mention', {
// @ts-ignore
user: `<span class="font-medium">${item.creator.name}</span>`,
post: `<span class="font-medium">${item.item.post.name}</span>`,
})}
{:else if item.type == 'private_message'}
{@html $t('routes.inbox.item.message', {
// @ts-ignore
user: `<span class="font-medium">${item.item.creator.name}</span>`,
recipient: `<span class="font-medium">${item.item.recipient.name}</span>`,
})}
{/if}
</div>
<div class="text-xs text-slate-600 dark:text-zinc-400">
<RelativeDate date={publishedToDate(item.published)} />
</div>
</div>
<div class="flex-1"></div>
<div class="flex gap-2 max-md:hidden flex-shrink-0">
<Button
color={item.read ? 'secondary' : 'primary'}
{loading}
disabled={loading}
on:click={(e) => {
e.stopPropagation()
markAsRead(!item.read)
}}
size="sm"
rounding="pill"
class="flex-shrink-0"
>
{#snippet prefix()}
<Icon src={item.read ? EyeSlash : Eye} size="16" micro />
{/snippet}
{item.read
? $t('post.actions.more.markUnread')
: $t('post.actions.more.markRead')}
</Button>
{#if item.type == 'comment_reply' || item.type == 'person_mention'}
<Button
href="/comment/{item.item.comment.id}"
size="sm"
rounding="pill"
class="flex-shrink-0"
>
{$t('common.jump')}
</Button>
{/if}
</div>
<div class="text-xs text-slate-600 dark:text-zinc-400">
<RelativeDate date={publishedToDate(item.published)} />
</div>
</div>
<div class="flex-1" />
<div class="flex gap-2 max-md:hidden flex-shrink-0">
{/snippet}
{#snippet extended()}
<div class="flex gap-2 w-full md:hidden mt-1">
<Button
color={item.read ? 'secondary' : 'primary'}
{loading}
@@ -133,61 +172,36 @@
}}
size="sm"
rounding="pill"
class="flex-shrink-0"
>
<Icon src={item.read ? EyeSlash : Eye} size="16" micro slot="prefix" />
{#snippet prefix()}
<Icon src={item.read ? EyeSlash : Eye} size="16" micro />
{/snippet}
{item.read
? $t('post.actions.more.markUnread')
: $t('post.actions.more.markRead')}
</Button>
{#if item.type == 'comment_reply' || item.type == 'person_mention'}
<Button
href="/comment/{item.item.comment.id}"
size="sm"
rounding="pill"
class="flex-shrink-0"
>
<Button href="/comment/{item.item.comment.id}" size="sm" rounding="pill">
{$t('common.jump')}
</Button>
{/if}
</div>
</div>
<div slot="extended" class="flex gap-2 w-full md:hidden mt-1">
<Button
color={item.read ? 'secondary' : 'primary'}
{loading}
disabled={loading}
on:click={(e) => {
e.stopPropagation()
markAsRead(!item.read)
}}
size="sm"
rounding="pill"
>
<Icon src={item.read ? EyeSlash : Eye} size="16" micro slot="prefix" />
{item.read
? $t('post.actions.more.markUnread')
: $t('post.actions.more.markRead')}
</Button>
{#if item.type == 'comment_reply' || item.type == 'person_mention'}
<Button href="/comment/{item.item.comment.id}" size="sm" rounding="pill">
{$t('common.jump')}
</Button>
{/if}
</div>
<svelte:fragment slot="content">
{#if item.type == 'comment_reply' || item.type == 'person_mention'}
<CommentItem
comment={item.item}
community={false}
view="cozy"
meta={false}
class="pt-0 pb-0"
/>
{:else}
<PrivateMessage message={item.item} meta={false} />
{/if}
</svelte:fragment>
{/snippet}
{#snippet content()}
{#if item.type == 'comment_reply' || item.type == 'person_mention'}
<CommentItem
comment={item.item}
community={false}
view="cozy"
meta={false}
class="pt-0 pb-0"
/>
{:else}
<PrivateMessage message={item.item} meta={false} />
{/if}
{/snippet}
</Expandable>
<style>
+1 -1
View File
@@ -51,7 +51,7 @@
}))
}
export let data
let { data } = $props();
</script>
<Header pageHeader>
@@ -1,4 +1,6 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy';
import { Button, Material, Spinner, TextInput, toast } from 'mono-svelte'
import Message from './Message.svelte'
import { t } from '$lib/translations'
@@ -15,14 +17,14 @@
import { report } from '$lib/components/lemmy/moderation/moderation'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
export let data
let { data = $bindable() } = $props();
let textbox = {
let textbox = $state({
message: '',
loading: false,
}
})
let chatWindow: HTMLDivElement
let chatWindow: HTMLDivElement = $state()
async function sendMessage(
message: string
@@ -50,11 +52,13 @@
textbox.loading = false
}
$: if (browser && data.message && chatWindow) {
tick().then(() =>
chatWindow.scrollTo({ top: chatWindow.scrollHeight, behavior: 'smooth' })
)
}
run(() => {
if (browser && data.message && chatWindow) {
tick().then(() =>
chatWindow.scrollTo({ top: chatWindow.scrollHeight, behavior: 'smooth' })
)
}
});
async function deleteMessage(id: number) {
const res = await client().deletePrivateMessage({
@@ -85,7 +89,7 @@
>
<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" />
<div class="mt-auto"></div>
{#each data.message.private_messages.toReversed() as private_message, index (private_message.private_message.id)}
<div
class={private_message.creator.id == data.creator
@@ -117,7 +121,7 @@
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 () => {
onsubmit={preventDefault(async () => {
const res = await sendMessage(textbox.message)
if (!res) return
@@ -129,7 +133,7 @@
}
textbox.message = ''
}}
})}
>
<TextInput
bind:value={textbox.message}
@@ -146,7 +150,9 @@
loading={textbox.loading}
disabled={textbox.loading}
>
<Icon src={PaperAirplane} size="18" micro slot="prefix" />
{#snippet prefix()}
<Icon src={PaperAirplane} size="18" micro />
{/snippet}
</Button>
</form>
</div>
@@ -7,8 +7,12 @@
import { createEventDispatcher } from 'svelte'
import { EllipsisVertical, Flag, Icon, Trash } from 'svelte-hero-icons'
export let message: PrivateMessageView
export let primary: boolean = false
interface Props {
message: PrivateMessageView;
primary?: boolean;
}
let { message, primary = false }: Props = $props();
const dispatch = createEventDispatcher<{ delete: boolean; report: boolean }>()
</script>
@@ -28,23 +32,27 @@
<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>
{#snippet target()}
<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"
title={$t('post.actions.more.actions')}
>
<Icon src={EllipsisVertical} size="16" micro />
</Button>
{/snippet}
<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" />
{#snippet prefix()}
<Icon src={Trash} size="16" micro />
{/snippet}
{$t('post.actions.more.delete')}
</MenuButton>
{:else}
@@ -52,7 +60,9 @@
color="danger-subtle"
on:click={() => dispatch('report', true)}
>
<Icon src={Flag} size="16" micro slot="prefix" />
{#snippet prefix()}
<Icon src={Flag} size="16" micro />
{/snippet}
{$t('moderation.report')}
</MenuButton>
{/if}