Merge pull request #627 from Xyphyn/optimize-bundle
perf: optimize bundle size
This commit is contained in:
28 files changed
+671
-757
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { Comment, CommentView } from 'lemmy-js-client'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
|
||||
export interface CommentNodeI {
|
||||
comment_view: CommentView
|
||||
@@ -28,7 +29,7 @@ export function buildCommentsTree(
|
||||
baseDepth: number = 0,
|
||||
filter: (c: CommentView) => boolean = () => true,
|
||||
): CommentNodeI[] {
|
||||
const map = new Map<number, CommentNodeI>()
|
||||
const map = new SvelteMap<number, CommentNodeI>()
|
||||
|
||||
let min_depth = Number.MAX_VALUE
|
||||
for (const comment_view of comments) {
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
@@ -17,23 +19,19 @@
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
target: Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
let { item = $bindable(), target: passedTarget }: Props = $props()
|
||||
|
||||
let locking = $state(false)
|
||||
let pinning = $state(false)
|
||||
|
||||
let acting = $derived(locking || pinning)
|
||||
let acting = $state(false)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
locking = true
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().lockPost({
|
||||
@@ -49,13 +47,13 @@
|
||||
})
|
||||
}
|
||||
|
||||
locking = false
|
||||
acting = false
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
|
||||
pinning = true
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().featurePost({
|
||||
@@ -72,21 +70,13 @@
|
||||
})
|
||||
}
|
||||
|
||||
pinning = false
|
||||
acting = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="hover:text-green-500!"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{@render passedTarget(acting)}
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
@@ -99,8 +89,7 @@
|
||||
<MenuButton
|
||||
color="warning-subtle"
|
||||
onclick={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
loading={acting}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
@@ -112,8 +101,7 @@
|
||||
color="success-subtle"
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
loading={acting}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" mini />
|
||||
<div
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import PostActions from '$lib/components/lemmy/post/actions/PostActions.svelte'
|
||||
import PostMeta, {
|
||||
parseTags,
|
||||
type Tag,
|
||||
|
||||
@@ -1,377 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import {
|
||||
amMod,
|
||||
isAdmin,
|
||||
report,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { site } from '$lib/lemmy.svelte.js'
|
||||
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
|
||||
import { communityLink, userLink } from '$lib/lemmy/generic'
|
||||
import { setSessionStorage } from '$lib/session.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import { feature } from '$lib/version'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import {
|
||||
Button,
|
||||
Menu,
|
||||
MenuButton,
|
||||
MenuDivider,
|
||||
Modal,
|
||||
Spinner,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import {
|
||||
ArrowTopRightOnSquare,
|
||||
Bookmark,
|
||||
BookmarkSlash,
|
||||
BugAnt,
|
||||
ChatBubbleOvalLeft,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
EllipsisHorizontal,
|
||||
Eye,
|
||||
EyeSlash,
|
||||
Flag,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
MapPin,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Share,
|
||||
Trash,
|
||||
UserCircle,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import { hidePost, postLink } from './helpers'
|
||||
import PostVote from './PostVote.svelte'
|
||||
|
||||
let editing = $state(false)
|
||||
let saving = $state(false)
|
||||
|
||||
let localShare = $state(false)
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
onedit?: (post: PostView) => void
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
post = $bindable(),
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
onedit,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Editing post</h1>
|
||||
{/snippet}
|
||||
{#await import('./form/PostForm.svelte')}
|
||||
<div class="mx-auto h-96 flex justify-center items-center">
|
||||
<Spinner width={32} />
|
||||
</div>
|
||||
{:then { default: PostForm }}
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
onsubmit={e => {
|
||||
editing = false
|
||||
post = e
|
||||
onedit?.(e)
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
<!-- Have the title not exist at all -->
|
||||
{/snippet}
|
||||
</PostForm>
|
||||
{/await}
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<footer
|
||||
class="flex flex-row gap-2 items-center shrink-0 {buttonHeight}"
|
||||
class:flex-row-reverse={settings.posts.reverseActions}
|
||||
{style}
|
||||
>
|
||||
<PostVote
|
||||
post={post.post}
|
||||
bind:vote={post.my_vote}
|
||||
bind:score={post.counts.score}
|
||||
bind:upvotes={post.counts.upvotes}
|
||||
bind:downvotes={post.counts.downvotes}
|
||||
showCounts={profile.current?.user?.local_user_view?.local_user
|
||||
?.show_scores ?? true}
|
||||
/>
|
||||
|
||||
<Button
|
||||
size="custom"
|
||||
href="{postLink(post.post)}#comments"
|
||||
class="text-inherit! h-full px-3 relative"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
target={settings.openLinksInNewTab ? '_blank' : ''}
|
||||
title={$t('post.actions.comments')}
|
||||
>
|
||||
{@const newComment =
|
||||
publishedToDate(post.counts.newest_comment_time).getTime() >
|
||||
new Date().getTime() - 5 * 60 * 1000}
|
||||
<Icon
|
||||
src={newComment ? ChatBubbleOvalLeftEllipsis : ChatBubbleOvalLeft}
|
||||
size="18"
|
||||
/>
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<div class="flex-1"></div>
|
||||
{#if settings.debugInfo}
|
||||
{#if debug}
|
||||
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
|
||||
<DebugObject object={post} bind:open={debug} />
|
||||
{/await}
|
||||
{/if}
|
||||
<Button
|
||||
onclick={() => (debug = true)}
|
||||
title="Debug"
|
||||
size="custom"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
<ModerationMenu
|
||||
size="custom"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
bind:item={post}
|
||||
community={post.community}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
onclick={async () => {
|
||||
if (!profile.current?.jwt) return
|
||||
saving = true
|
||||
post.saved = await save(post, !post.saved)
|
||||
saving = false
|
||||
}}
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<Menu placement="bottom-end" class="h-8">
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||
<MenuButton link href={userLink(post.creator)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} size="16" micro class="shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.creator.name}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuButton link href={communityLink(post.community)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro class="shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.community.title}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuDivider>
|
||||
{$t('post.actions.more.actions')}
|
||||
</MenuDivider>
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
if (navigator.share)
|
||||
navigator.share?.({
|
||||
url: localShare
|
||||
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
})
|
||||
else
|
||||
navigator.clipboard.writeText(
|
||||
localShare
|
||||
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="flex-1 py-0!"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
<div class="flex-1"></div>
|
||||
{#if !post.post.local}
|
||||
<div class="flex gap-1">
|
||||
<Button
|
||||
color={!localShare ? 'primary' : 'secondary'}
|
||||
size="square-sm"
|
||||
rounding="pill"
|
||||
onclick={() => (localShare = false)}
|
||||
title={$t('filter.location.global')}
|
||||
>
|
||||
<Icon src={GlobeAmericas} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
color={localShare ? 'primary' : 'secondary'}
|
||||
size="square-sm"
|
||||
rounding="pill"
|
||||
onclick={() => (localShare = true)}
|
||||
title={$t('filter.location.local')}
|
||||
>
|
||||
<Icon src={MapPin} size="16" micro />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
setSessionStorage('postDraft', {
|
||||
body: `${
|
||||
settings.crosspostOriginalLink
|
||||
? `cross-posted from: ${post.post.ap_id}`
|
||||
: ``
|
||||
}\n${
|
||||
post.post.body
|
||||
? '>' + post.post.body.split('\n').join('\n> ')
|
||||
: ''
|
||||
}`,
|
||||
url: post.post.url,
|
||||
title: post.post.name,
|
||||
loading: false,
|
||||
nsfw: post.post.nsfw,
|
||||
community: null,
|
||||
image: null,
|
||||
})
|
||||
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.current?.jwt)
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if feature('hidePosts', site.data?.version)}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (!profile.current?.jwt) return
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
profile.current?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} width={16} micro />
|
||||
{/snippet}
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/if}
|
||||
</Menu>
|
||||
</footer>
|
||||
@@ -6,7 +6,7 @@
|
||||
post: PostView
|
||||
}
|
||||
|
||||
let { post } = $props()
|
||||
let { post }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Post {post} class="py-0!" />
|
||||
@@ -64,12 +64,11 @@
|
||||
Megaphone,
|
||||
PaperAirplane,
|
||||
Pencil,
|
||||
ShieldCheck,
|
||||
Tag,
|
||||
Trash,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
|
||||
interface Props {
|
||||
@@ -144,7 +143,7 @@
|
||||
{style}
|
||||
>
|
||||
{#if showCommunity && community}
|
||||
<Popover autoClose={false} popoverClass="backdrop-blur-xl rounded-2xl">
|
||||
<Popover>
|
||||
{#snippet target()}
|
||||
<button
|
||||
class={[
|
||||
@@ -171,15 +170,17 @@
|
||||
{/if}
|
||||
</button>
|
||||
{/snippet}
|
||||
{#snippet popover()}
|
||||
{#if community && subscribed}
|
||||
{#snippet popover(open)}
|
||||
{#if open && community && subscribed}
|
||||
<Material
|
||||
color="uniform"
|
||||
rounding="2xl"
|
||||
elevation="high"
|
||||
class="max-w-2xl w-full max-h-128 overflow-auto"
|
||||
>
|
||||
<CommunityHeader {community} {subscribed} />
|
||||
{#await import('../community/CommunityHeader.svelte') then { default: CommunityHeader }}
|
||||
<CommunityHeader {community} {subscribed} />
|
||||
{/await}
|
||||
</Material>
|
||||
{/if}
|
||||
{/snippet}
|
||||
@@ -197,9 +198,7 @@
|
||||
{/if}
|
||||
<div
|
||||
class="flex flex-row gap-1.5 items-center
|
||||
no-list-margin {view == 'compact' && showCommunity
|
||||
? 'min-[480px]:mx-2'
|
||||
: ''}"
|
||||
no-list-margin {view == 'compact' && showCommunity ? 'min-sm:mx-2' : ''}"
|
||||
style="grid-area: stats;"
|
||||
>
|
||||
{#if user}
|
||||
@@ -209,21 +208,16 @@
|
||||
src={PaperAirplane}
|
||||
size="12"
|
||||
micro
|
||||
class="rotate-180 text-slate-400 dark:text-zinc-600 max-[480px]:hidden"
|
||||
class="rotate-180 text-slate-400 dark:text-zinc-600 max-sm:hidden"
|
||||
/>
|
||||
{/if}
|
||||
<UserLink
|
||||
avatarSize={20}
|
||||
{user}
|
||||
avatar={!showCommunity}
|
||||
class="shrink "
|
||||
>
|
||||
<UserLink avatarSize={20} {user} avatar={!showCommunity} class="shrink">
|
||||
{#snippet extraBadges()}
|
||||
{#if badges.moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
<Icon src={ShieldCheck} size="14" mini class="text-green-500" />
|
||||
{/if}
|
||||
{#if badges.admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
<Icon src={ShieldCheck} size="14" mini class="text-red-500" />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
@@ -245,8 +239,8 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div
|
||||
class="flex flex-row min-[480px]:justify-end items-center self-center
|
||||
flex-wrap gap-2 *:shrink-0 badges min-[480px]:ml-2"
|
||||
class="flex flex-row min-sm:justify-end items-center self-center
|
||||
flex-wrap gap-2 *:shrink-0 badges min-sm:ml-2"
|
||||
style="grid-area: badges;"
|
||||
>
|
||||
{#if tags}
|
||||
@@ -341,7 +335,7 @@
|
||||
? '_blank'
|
||||
: undefined}
|
||||
class={[
|
||||
'inline max-[480px]:mt-0!',
|
||||
'inline max-sm:mt-0!',
|
||||
'hover:underline hover:text-primary-900 dark:hover:text-primary-100 transition-colors',
|
||||
'font-medium',
|
||||
titleClass,
|
||||
@@ -379,7 +373,7 @@
|
||||
grid-template-columns: 0fr;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
@media screen and (max-width: 40rem) {
|
||||
.meta.compact {
|
||||
grid-template-areas:
|
||||
'avatar community'
|
||||
@@ -393,7 +387,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 480px) {
|
||||
@media screen and (min-width: 40rem) {
|
||||
.meta.compact {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import {
|
||||
amMod,
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { save } from '$lib/lemmy/contentview.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Button, Menu, Modal, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
BookmarkSlash,
|
||||
BugAnt,
|
||||
ChatBubbleOvalLeft,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
ShieldCheck,
|
||||
} from 'svelte-hero-icons'
|
||||
import { postLink } from '../helpers'
|
||||
import PostVote from '../PostVote.svelte'
|
||||
|
||||
let saving = $state(false)
|
||||
let editing = $state(false)
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
onedit?: (post: PostView) => void
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
post = $bindable(),
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
onedit,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Editing post</h1>
|
||||
{/snippet}
|
||||
{#await import('../form/PostForm.svelte')}
|
||||
<div class="mx-auto h-96 flex justify-center items-center">
|
||||
<Spinner width={32} />
|
||||
</div>
|
||||
{:then { default: PostForm }}
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
onsubmit={e => {
|
||||
editing = false
|
||||
post = e
|
||||
onedit?.(e)
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
<!-- Have the title not exist at all -->
|
||||
{/snippet}
|
||||
</PostForm>
|
||||
{/await}
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<footer
|
||||
class="flex flex-row gap-2 items-center shrink-0 {buttonHeight}"
|
||||
class:flex-row-reverse={settings.posts.reverseActions}
|
||||
{style}
|
||||
>
|
||||
<PostVote
|
||||
post={post.post}
|
||||
bind:vote={post.my_vote}
|
||||
bind:score={post.counts.score}
|
||||
bind:upvotes={post.counts.upvotes}
|
||||
bind:downvotes={post.counts.downvotes}
|
||||
showCounts={profile.current?.user?.local_user_view?.local_user
|
||||
?.show_scores ?? true}
|
||||
/>
|
||||
|
||||
<Button
|
||||
size="custom"
|
||||
href="{postLink(post.post)}#comments"
|
||||
class="text-inherit! h-full px-3 relative"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
target={settings.openLinksInNewTab ? '_blank' : ''}
|
||||
title={$t('post.actions.comments')}
|
||||
>
|
||||
{@const newComment =
|
||||
publishedToDate(post.counts.newest_comment_time).getTime() >
|
||||
new Date().getTime() - 5 * 60 * 1000}
|
||||
<Icon
|
||||
src={newComment ? ChatBubbleOvalLeftEllipsis : ChatBubbleOvalLeft}
|
||||
size="18"
|
||||
/>
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<div class="flex-1"></div>
|
||||
{#if settings.debugInfo}
|
||||
{#if debug}
|
||||
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
|
||||
<DebugObject object={post} bind:open={debug} />
|
||||
{/await}
|
||||
{/if}
|
||||
<Button
|
||||
onclick={() => (debug = true)}
|
||||
title="Debug"
|
||||
size="custom"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||
<ModerationMenu bind:item={post}>
|
||||
{#snippet target(acting)}
|
||||
<Button
|
||||
size="custom"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
loading={acting}
|
||||
class={buttonSquare}
|
||||
>
|
||||
<Icon src={ShieldCheck} size="18" mini />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</ModerationMenu>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
onclick={async () => {
|
||||
if (!profile.current?.jwt) return
|
||||
saving = true
|
||||
post.saved = await save(post, !post.saved)
|
||||
saving = false
|
||||
}}
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#snippet children(open)}
|
||||
{#if open}
|
||||
{#await import('./PostActionsMenu.svelte') then { default: PostActionsMenu }}
|
||||
<PostActionsMenu {post} {onhide} bind:editing />
|
||||
{/await}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Menu>
|
||||
</footer>
|
||||
@@ -0,0 +1,202 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { deleteItem, markAsRead } from '$lib/lemmy/contentview'
|
||||
import { communityLink, userLink } from '$lib/lemmy/generic'
|
||||
import { setSessionStorage } from '$lib/session'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Button, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import {
|
||||
ArrowTopRightOnSquare,
|
||||
Eye,
|
||||
EyeSlash,
|
||||
Flag,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
MapPin,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Share,
|
||||
Trash,
|
||||
UserCircle,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import { report } from '../../moderation/moderation'
|
||||
import { hidePost } from '../helpers'
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
onhide?: (hide: boolean) => void
|
||||
editing: boolean
|
||||
}
|
||||
|
||||
let localShare = $state(false)
|
||||
|
||||
let { post, onhide, editing = $bindable() }: Props = $props()
|
||||
</script>
|
||||
|
||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||
<MenuButton link href={userLink(post.creator)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} size="16" micro class="shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.creator.name}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuButton link href={communityLink(post.community)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro class="shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.community.title}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuDivider>
|
||||
{$t('post.actions.more.actions')}
|
||||
</MenuDivider>
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
if (navigator.share)
|
||||
navigator.share?.({
|
||||
url: localShare
|
||||
? `${instanceToURL(profile.current.instance)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
})
|
||||
else
|
||||
navigator.clipboard.writeText(
|
||||
localShare
|
||||
? `${instanceToURL(profile.current.instance)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="flex-1 py-0!"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
<div class="flex-1"></div>
|
||||
{#if !post.post.local}
|
||||
<div class="flex gap-1">
|
||||
<Button
|
||||
color={!localShare ? 'primary' : 'secondary'}
|
||||
size="square-sm"
|
||||
rounding="pill"
|
||||
onclick={() => (localShare = false)}
|
||||
title={$t('filter.location.global')}
|
||||
>
|
||||
<Icon src={GlobeAmericas} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
color={localShare ? 'primary' : 'secondary'}
|
||||
size="square-sm"
|
||||
rounding="pill"
|
||||
onclick={() => (localShare = true)}
|
||||
title={$t('filter.location.local')}
|
||||
>
|
||||
<Icon src={MapPin} size="16" micro />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
setSessionStorage('postDraft', {
|
||||
body: `${
|
||||
settings.crosspostOriginalLink
|
||||
? `cross-posted from: ${post.post.ap_id}`
|
||||
: ``
|
||||
}\n${
|
||||
post.post.body ? '>' + post.post.body.split('\n').join('\n> ') : ''
|
||||
}`,
|
||||
url: post.post.url,
|
||||
title: post.post.name,
|
||||
loading: false,
|
||||
nsfw: post.post.nsfw,
|
||||
community: null,
|
||||
image: null,
|
||||
})
|
||||
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.current?.jwt)
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current.user?.local_user_view.person.id != post.creator.id}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (!profile.current?.jwt) return
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
profile.current?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { SvelteMap, SvelteSet } from 'svelte/reactivity'
|
||||
|
||||
export type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
@@ -10,12 +11,12 @@ export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
||||
export const combineCrossposts = (
|
||||
posts: PostView[],
|
||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
||||
const urlMap = new Map<
|
||||
const urlMap = new SvelteMap<
|
||||
string,
|
||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||
>()
|
||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
||||
const seenUrls = new Set<string>()
|
||||
const seenUrls = new SvelteSet<string>()
|
||||
|
||||
posts?.forEach(post => {
|
||||
if (
|
||||
|
||||
@@ -60,9 +60,7 @@
|
||||
this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
onclick={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, -1))
|
||||
}
|
||||
if (type == 'image') showImage(bestImageURL(post, false, -1))
|
||||
}}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@@ -109,7 +107,7 @@
|
||||
<div
|
||||
class={[
|
||||
'absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200',
|
||||
'bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700',
|
||||
'bg-slate-25 dark:bg-zinc-900',
|
||||
'grid place-items-center',
|
||||
]}
|
||||
>
|
||||
@@ -138,8 +136,8 @@
|
||||
<div
|
||||
class={[
|
||||
'object-cover overflow-hidden bg-slate-50 dark:bg-zinc-900 rounded-xl',
|
||||
'border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400',
|
||||
'dark:group-hover/media:border-zinc-600 transition-colors text-slate-400 dark:text-zinc-600 grid',
|
||||
'border border-slate-200 dark:border-zinc-800',
|
||||
'transition-colors text-slate-400 dark:text-zinc-600 grid',
|
||||
'place-items-center',
|
||||
size,
|
||||
]}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { fly } from 'svelte/transition'
|
||||
import { page as pageData } from '$app/state'
|
||||
import { invalidate } from '$app/navigation'
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
page?: number
|
||||
@@ -27,8 +28,8 @@
|
||||
|
||||
let customHref = (href?: string) => {
|
||||
if (href?.startsWith('?')) {
|
||||
const current = new URLSearchParams(pageData.url.searchParams)
|
||||
const newParams = new URLSearchParams(href)
|
||||
const current = new SvelteURLSearchParams(pageData.url.searchParams)
|
||||
const newParams = new SvelteURLSearchParams(href)
|
||||
|
||||
current.delete(Array.from(newParams.keys())[0])
|
||||
current.append(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { site } from '$lib/lemmy.svelte.js'
|
||||
import { Badge, Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
Bars3,
|
||||
Bell,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
@@ -23,9 +24,8 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import Logo from '../Logo.svelte'
|
||||
import NavButton from './NavButton.svelte'
|
||||
import Profile from './Profile.svelte'
|
||||
import CommandsWrapper from './commands/CommandsWrapper.svelte'
|
||||
import NavButton from './NavButton.svelte'
|
||||
|
||||
let promptOpen: boolean = $state(false)
|
||||
interface Props {
|
||||
@@ -197,6 +197,38 @@
|
||||
</span>
|
||||
{/if}
|
||||
</Menu>
|
||||
<Profile placement="top" />
|
||||
<Menu>
|
||||
{#snippet target()}
|
||||
<button
|
||||
class="w-10 h-10 rounded-full border-slate-200 dark:border-zinc-700
|
||||
transition-all bg-slate-50 dark:bg-zinc-900 relative
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700 group cursor-pointer"
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if profile.current?.user}
|
||||
<div
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center group-hover:scale-90 transition-transform group-active:scale-[85%]"
|
||||
>
|
||||
<Avatar
|
||||
url={profile.current.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={profile.current.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
{/snippet}
|
||||
{#snippet children(open)}
|
||||
{#if open}
|
||||
{#await import('./Profile.svelte') then { default: Profile }}
|
||||
<Profile />
|
||||
{/await}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Menu>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -9,7 +9,6 @@
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Menu,
|
||||
MenuButton,
|
||||
MenuDivider,
|
||||
Modal,
|
||||
@@ -18,10 +17,8 @@
|
||||
Spinner,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import type { Placement } from 'svelte-floating-ui/core'
|
||||
import {
|
||||
ArrowLeftOnRectangle,
|
||||
Bars3,
|
||||
Bookmark,
|
||||
BugAnt,
|
||||
CodeBracketSquare,
|
||||
@@ -37,16 +34,8 @@
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import Avatar from '../Avatar.svelte'
|
||||
|
||||
let showInstance = $state(false)
|
||||
|
||||
interface Props {
|
||||
buttonClass?: string
|
||||
placement?: Placement
|
||||
}
|
||||
|
||||
let { buttonClass = '', ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if showInstance}
|
||||
@@ -64,158 +53,128 @@
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<Menu {...rest}>
|
||||
{#snippet target()}
|
||||
<button
|
||||
class="w-10 h-10 rounded-full border-slate-200 dark:border-zinc-700
|
||||
transition-all bg-slate-50 dark:bg-zinc-900 relative
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700 group cursor-pointer {buttonClass}"
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if profile.current?.user}
|
||||
<div
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center group-hover:scale-90 transition-transform group-active:scale-[85%]"
|
||||
>
|
||||
<Avatar
|
||||
url={profile.current.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={profile.current.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/profile">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.profile')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/inbox">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Inbox} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold py-0.5!">
|
||||
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
<MenuButton href="/saved">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Bookmark} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.saved')}
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<MenuButton href="/accounts/login">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowLeftOnRectangle} mini size="16" />
|
||||
{/snippet}
|
||||
{$t('account.login')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/signup">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Identification} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('account.signup')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton href="/accounts">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserGroup} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/profile">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.profile')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/inbox">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Inbox} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold py-0.5!">
|
||||
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
<MenuButton href="/saved">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Bookmark} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('profile.saved')}
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<MenuButton href="/accounts/login">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowLeftOnRectangle} mini size="16" />
|
||||
{/snippet}
|
||||
{$t('account.login')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/signup">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Identification} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('account.signup')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton href="/accounts">
|
||||
{$t('account.accounts')}
|
||||
</MenuButton>
|
||||
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
|
||||
<MenuButton href="/settings">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('nav.menu.settings')}
|
||||
</MenuButton>
|
||||
<MenuButton class="py-0!" onclick={e => e.stopPropagation()}>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: theme.colorScheme == 'light'
|
||||
? Sun
|
||||
: theme.colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
<span>{$t('nav.menu.colorscheme.label')}</span>
|
||||
<Select bind:value={theme.colorScheme} class="ml-auto my-auto w-24" size="sm">
|
||||
<Option value="system" icon={ComputerDesktop}>
|
||||
{$t('nav.menu.colorscheme.system')}
|
||||
</Option>
|
||||
<Option value="light" icon={Sun}>
|
||||
{$t('nav.menu.colorscheme.light')}
|
||||
</Option>
|
||||
<Option value="dark" icon={Moon}>
|
||||
{$t('nav.menu.colorscheme.dark')}
|
||||
</Option>
|
||||
</Select>
|
||||
</MenuButton>
|
||||
<MenuButton href="/theme">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Swatch} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.menu.theme')}
|
||||
</MenuButton>
|
||||
{#if settings.debugInfo}
|
||||
<MenuButton href="/util">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserGroup} micro size="16" />
|
||||
<Icon src={BugAnt} mini size="16" />
|
||||
{/snippet}
|
||||
{$t('account.accounts')}
|
||||
Debug
|
||||
</MenuButton>
|
||||
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
|
||||
<MenuButton href="/settings">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} micro size="16" />
|
||||
{/snippet}
|
||||
{$t('nav.menu.settings')}
|
||||
</MenuButton>
|
||||
<MenuButton class="py-0!" onclick={e => e.stopPropagation()}>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: theme.colorScheme == 'light'
|
||||
? Sun
|
||||
: theme.colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
<span>{$t('nav.menu.colorscheme.label')}</span>
|
||||
<Select
|
||||
bind:value={theme.colorScheme}
|
||||
class="ml-auto my-auto w-24"
|
||||
size="sm"
|
||||
>
|
||||
<Option value="system" icon={ComputerDesktop}>
|
||||
{$t('nav.menu.colorscheme.system')}
|
||||
</Option>
|
||||
<Option value="light" icon={Sun}>
|
||||
{$t('nav.menu.colorscheme.light')}
|
||||
</Option>
|
||||
<Option value="dark" icon={Moon}>
|
||||
{$t('nav.menu.colorscheme.dark')}
|
||||
</Option>
|
||||
</Select>
|
||||
</MenuButton>
|
||||
<MenuButton href="/theme">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Swatch} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.menu.theme')}
|
||||
</MenuButton>
|
||||
{#if settings.debugInfo}
|
||||
<MenuButton href="/util">
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} mini size="16" />
|
||||
{/snippet}
|
||||
Debug
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuDivider />
|
||||
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
|
||||
<div class="flex flex-row gap-2 w-full items-center">
|
||||
<div class="flex-1">
|
||||
<button
|
||||
class="hover:brightness-110 transition-all"
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText(__VERSION__)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Badge color="blue-subtle">{__VERSION__}</Badge>
|
||||
</button>
|
||||
</div>
|
||||
<Button
|
||||
onclick={() => (showInstance = !showInstance)}
|
||||
color="tertiary"
|
||||
title={$t('nav.menu.instance')}
|
||||
size="square-md"
|
||||
{/if}
|
||||
<MenuDivider />
|
||||
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
|
||||
<div class="flex flex-row gap-2 w-full items-center">
|
||||
<div class="flex-1">
|
||||
<button
|
||||
class="hover:brightness-110 transition-all"
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText(__VERSION__)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Icon src={ServerStack} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
color="tertiary"
|
||||
href="https://github.com/Xyphyn/Photon"
|
||||
title={$t('nav.menu.source')}
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracketSquare} size="16" micro />
|
||||
</Button>
|
||||
<Badge color="blue-subtle">{__VERSION__}</Badge>
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</Menu>
|
||||
<Button
|
||||
onclick={() => (showInstance = !showInstance)}
|
||||
color="tertiary"
|
||||
title={$t('nav.menu.instance')}
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ServerStack} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
color="tertiary"
|
||||
href="https://github.com/Xyphyn/Photon"
|
||||
title={$t('nav.menu.source')}
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracketSquare} size="16" micro />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
ViewColumns,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
export interface Group {
|
||||
name: string
|
||||
@@ -411,7 +412,7 @@ export function getGroups(
|
||||
f.community.name,
|
||||
f.community.actor_id,
|
||||
)}`,
|
||||
detail: new URL(f.community.actor_id).hostname,
|
||||
detail: new SvelteURL(f.community.actor_id).hostname,
|
||||
})) ?? [],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
interface Props extends ButtonProps {
|
||||
href?: string | undefined
|
||||
icon?: IconSource | undefined
|
||||
selected?: boolean
|
||||
class?: string
|
||||
customIcon?: import('svelte').Snippet<[{ selected: boolean }]>
|
||||
children?: import('svelte').Snippet
|
||||
@@ -17,7 +16,6 @@
|
||||
let {
|
||||
href = undefined,
|
||||
icon = undefined,
|
||||
selected = $bindable(false),
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
@@ -25,11 +23,7 @@
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (href != undefined) {
|
||||
selected = page.url.pathname == href
|
||||
}
|
||||
})
|
||||
let selected = $derived(page.url.pathname == href)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
strategy?: Strategy
|
||||
class?: string
|
||||
target?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -57,7 +57,7 @@
|
||||
rounded-2xl
|
||||
border border-slate-300 dark:border-zinc-800 border-opacity-50"
|
||||
>
|
||||
{@render children?.()}
|
||||
{@render children?.(open)}
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
popoverClass?: string
|
||||
class?: string
|
||||
target?: import('svelte').Snippet
|
||||
popover?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
popover?: import('svelte').Snippet<[boolean]>
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -140,9 +140,9 @@
|
||||
use:focusTrap
|
||||
bind:this={popoverEl}
|
||||
>
|
||||
{#if popover}{@render popover()}{:else}
|
||||
{#if popover}{@render popover(open)}{:else}
|
||||
<Material elevation="high" color="distinct" class="flex flex-col">
|
||||
{@render children?.()}
|
||||
{@render children?.(open)}
|
||||
</Material>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
+9
-36
@@ -1,12 +1,11 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { feature } from '$lib/version.js'
|
||||
import type { SubscribedType } from 'lemmy-js-client'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { t } from './i18n/translations'
|
||||
import { site } from './lemmy.svelte'
|
||||
import { errorMessage } from './lemmy/error'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
// Despite the name, this will round up
|
||||
// Example: findClosestNumber([8, 16, 32, 64, 128], 76) will return 128
|
||||
@@ -29,7 +28,7 @@ export const searchParam = (
|
||||
}
|
||||
|
||||
export const fullCommunityName = (name: string, actorId: string) =>
|
||||
`${name}@${new URL(actorId).hostname}`
|
||||
`${name}@${new SvelteURL(actorId).hostname}`
|
||||
|
||||
export const placeholders = {
|
||||
url: ['https://example.com'],
|
||||
@@ -126,38 +125,12 @@ export async function uploadImage(
|
||||
const formData = new FormData()
|
||||
formData.append('images[]', image)
|
||||
|
||||
if (feature('unproxiedImageUpload', site.data?.version)) {
|
||||
const res = await client({ auth: jwt, instanceURL: instance }).uploadImage({
|
||||
image: image,
|
||||
})
|
||||
const res = await client({ auth: jwt, instanceURL: instance }).uploadImage({
|
||||
image: image,
|
||||
})
|
||||
|
||||
if (res.url) return res.url
|
||||
else throw new Error(`Failed to upload image. ${res.msg}`)
|
||||
} else {
|
||||
const response = await fetch(
|
||||
`${
|
||||
window.location.origin
|
||||
}/cors/${instance}/pictrs/image?${new URLSearchParams({
|
||||
auth: jwt,
|
||||
})}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
},
|
||||
)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
if (json.msg == 'ok') {
|
||||
return `https://${instance}/pictrs/image/${json.files?.[0]?.file}`
|
||||
}
|
||||
throw new Error(
|
||||
`${
|
||||
(await response.text().catch(() => undefined)) ??
|
||||
'Failed to upload image'
|
||||
}: ${response.status}: ${response.statusText}`,
|
||||
)
|
||||
}
|
||||
if (res.url) return res.url
|
||||
else throw new Error(`Failed to upload image. ${res.msg}`)
|
||||
}
|
||||
|
||||
export const instanceToURL = (input: string) =>
|
||||
@@ -167,7 +140,7 @@ export const instanceToURL = (input: string) =>
|
||||
|
||||
export function canParseUrl(url: string): boolean {
|
||||
try {
|
||||
new URL(url)
|
||||
new SvelteURL(url)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
@@ -175,7 +148,7 @@ export function canParseUrl(url: string): boolean {
|
||||
}
|
||||
|
||||
export function instanceId(actorId: string) {
|
||||
return new URL(actorId).hostname
|
||||
return new SvelteURL(actorId).hostname
|
||||
}
|
||||
|
||||
export function escapeHtml(input: string): string {
|
||||
|
||||
Reference in new issue
Block a user