feat: use state based auth instead of store based (#488)

* misc: switch to state for auth

* fix: class based auth not working
This commit is contained in:
Xylight authored and GitHub committed 2025-02-08 13:49:09 -08:00
1 parent 8c6ff77fac
commit 5651ad475d
83 files changed
+395 -469

No files matched your search

@@ -66,7 +66,7 @@
let editingLoad = $state(false)
async function save() {
if (!$profile?.jwt || newComment.length <= 0) return
if (!profile.data?.jwt || newComment.length <= 0) return
editingLoad = true
@@ -64,7 +64,7 @@
<Icon src={ChatBubbleOvalLeft} size="14" micro />
<span class="text-xs">{$t('comment.reply')}</span>
</Button>
{#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))}
{#if profile.data?.user && (amMod(profile.data?.user, comment.community) || isAdmin(profile.data.user))}
<CommentModerationMenu bind:item={comment} />
{/if}
<Menu placement="bottom">
@@ -92,8 +92,8 @@
<Icon src={Square2Stack} mini size="16" />
<div>{$t('comment.actions.link')}</div>
</MenuButton>
{#if $profile?.jwt}
{#if comment.creator.id == $profile.user?.local_user_view.person.id}
{#if profile.data?.jwt}
{#if comment.creator.id == profile.data.user?.local_user_view.person.id}
<MenuButton onclick={() => onedit?.(comment)}>
<Icon src={PencilSquare} mini size="16" />
<span>{$t('post.actions.more.edit')}</span>
@@ -101,8 +101,12 @@
{/if}
<MenuButton
onclick={async () => {
if ($profile?.jwt)
comment.saved = await save(comment, !comment.saved, $profile.jwt)
if (profile.data?.jwt)
comment.saved = await save(
comment,
!comment.saved,
profile.data.jwt,
)
}}
>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
@@ -110,15 +114,15 @@
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
</span>
</MenuButton>
{#if $profile?.user && $profile.jwt && $profile.user.local_user_view.person.id == comment.creator.id}
{#if profile.data?.user && profile.data.jwt && profile.data.user.local_user_view.person.id == comment.creator.id}
<MenuButton
color="danger-subtle"
onclick={async () => {
if ($profile?.jwt)
if (profile.data?.jwt)
comment.comment.deleted = await deleteItem(
comment,
!comment.comment.deleted,
$profile.jwt,
profile.data.jwt,
)
}}
>
@@ -130,7 +134,7 @@
</span>
</MenuButton>
{/if}
{#if $profile.jwt && $profile.user?.local_user_view.person.id != comment.creator.id}
{#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id}
<MenuButton onclick={() => report(comment)} color="danger-subtle">
<Icon src={Flag} mini size="16" />
<span>{$t('moderation.report')}</span>
@@ -49,7 +49,7 @@
let language: number | undefined = $state()
async function submit() {
if (!$profile?.user || !$profile?.jwt || value == '') return
if (!profile.data?.user || !profile.data?.jwt || value == '') return
loading = true
@@ -107,7 +107,7 @@
size="square-md"
rounding="pill"
color={language != undefined ? 'primary' : 'ghost'}
title={$t('form.profile.languages.title')}
title={$t('form.profile.data.languages.title')}
>
<Icon src={Language} size="16" micro />
</Button>
@@ -2,7 +2,6 @@
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import { getInstance } from '$lib/lemmy.js'
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/translations'
import type { CommentView } from 'lemmy-js-client'
@@ -33,7 +33,7 @@
}: Props = $props()
const castVote = async (newVote: number) => {
if (!$profile?.jwt) {
if (!profile.data?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
}
@@ -117,7 +117,7 @@
})
async function subscribe() {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
loading.subscribing = true
const subscribed =
community_view.subscribed == 'Subscribed' ||
@@ -226,7 +226,7 @@
<div
class="flex flex-row items-center gap-1 sticky bottom-0 drop-shadow-xl w-full"
>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<Button
disabled={loading.subscribing}
loading={loading.subscribing}
@@ -250,7 +250,7 @@
: $t('cards.community.subscribe')}
</Button>
{/if}
{#if $profile?.user && amMod($profile.user, community_view.community)}
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
<Button
href="/c/{fullCommunityName(
community_view.community.name,
@@ -275,7 +275,7 @@
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
color="danger-subtle"
size="lg"
@@ -289,7 +289,7 @@
? $t('cards.community.unblock')
: $t('cards.community.block')}
</MenuButton>
{#if $profile?.user}
{#if profile.data?.user}
<MenuButton
color="danger-subtle"
size="lg"
@@ -301,7 +301,7 @@
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -59,7 +59,7 @@
let formData = $state(passedFormData)
async function submit() {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
if ((!edit && formData.name == '') || formData.displayName == '') return
formData.submitting = true
@@ -94,23 +94,23 @@
type: 'success',
})
if ($profile.user) {
const c = $profile.user.moderates
if (profile.data.user) {
const c = profile.data.user.moderates
.map((m) => m.community.id)
.indexOf(res.community_view.community.id)
if (c != -1) {
$profile.user.moderates[c] = {
profile.data.user.moderates[c] = {
community: res.community_view.community,
moderator: $profile.user.local_user_view.person,
moderator: profile.data.user.local_user_view.person,
}
} else {
$profile.user = {
...$profile.user,
profile.data.user = {
...profile.data.user,
moderates: [
...$profile.user.moderates,
...profile.data.user.moderates,
{
community: res.community_view.community,
moderator: $profile.user.local_user_view.person,
moderator: profile.data.user.local_user_view.person,
},
],
}
@@ -159,7 +159,7 @@
/>
<TextInput
required
label={$t('form.profile.displayName')}
label={$t('form.profile.data.displayName')}
bind:value={formData.displayName}
/>
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
@@ -236,7 +236,7 @@
</Select>
<div class="space-y-1">
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
<SectionTitle>{$t('form.profile.data.languages.title')}</SectionTitle>
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
{#if $site}
<div class="flex gap-2 flex-wrap flex-row">
@@ -112,7 +112,7 @@
</Expandable>
{/if}
<div class="flex items-center gap-2 h-max w-max">
{#if $profile?.jwt}
{#if profile.data?.jwt}
<Subscribe
community={{
community: community,
@@ -151,7 +151,7 @@
</Subscribe>
{/if}
{#if $profile?.user && $profile.user.moderates
{#if profile.data?.user && profile.data.user.moderates
.map((c) => c.community.id)
.includes(community.id)}
<Button
@@ -179,7 +179,7 @@
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
color="danger-subtle"
size="lg"
@@ -192,7 +192,7 @@
? $t('cards.community.unblock')
: $t('cards.community.block')}
</MenuButton>
{#if $profile?.user}
{#if profile.data?.user}
<MenuButton
color="danger-subtle"
size="lg"
@@ -204,7 +204,7 @@
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -104,7 +104,7 @@
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing || !$profile?.jwt}
disabled={subscribing || !profile.data?.jwt}
loading={subscribing}
onclick={async () => {
const res = await subscribe()
@@ -52,14 +52,14 @@
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
<Option
value="Subscribed"
disabled={$profile?.jwt == undefined}
disabled={profile.data?.jwt == undefined}
icon={Newspaper}
>
{$t('filter.location.subscribed')}
</Option>
<Option
value="ModeratorView"
disabled={!$profile?.jwt || !amModOfAny($profile?.user)}
disabled={!profile.data?.jwt || !amModOfAny(profile.data?.user)}
icon={ShieldCheck}
>
{$t('filter.location.moderator')}
@@ -24,7 +24,7 @@
avatar
avatarSize={20}
/>
{#if $profile?.user?.local_user_view.person.id != message.recipient.id}
{#if profile.data?.user?.local_user_view.person.id != message.recipient.id}
to
<UserLink
showInstance={false}
@@ -30,7 +30,7 @@
</script>
<Modal bind:open>
{#snippet title()}
{#snippet customTitle()}
<h1 class="text-2xl font-bold">
{$t('routes.admin.applications.modalTitle')}
</h1>
@@ -32,7 +32,7 @@
)
async function upload() {
if (!$profile?.jwt || image == null) return
if (!profile.data?.jwt || image == null) return
progress = 0
@@ -40,7 +40,7 @@
const uploaded = (
await Promise.all(
Array.from(image).map((i) =>
uploadImage(i, $profile.instance, $profile.jwt!)
uploadImage(i, profile.data.instance, profile.data.jwt!)
.then((uploaded) => {
progress += 1 / (image?.length ?? 0)
return uploaded
@@ -22,7 +22,7 @@
let loading = $state(false)
async function sendMessage() {
if (!$profile?.jwt || message == '') return
if (!profile.data?.jwt || message == '') return
loading = true
@@ -50,7 +50,7 @@
</script>
<Modal bind:open>
{#snippet title()}
{#snippet customTitle()}
<h1 class="text-2xl font-bold">Message</h1>
{/snippet}
<form onsubmit={preventDefault(sendMessage)} class="flex flex-col gap-4">
@@ -43,7 +43,7 @@
})
async function submit() {
if (!item || !$profile?.user || !$profile?.jwt) return
if (!item || !profile.data?.user || !profile.data?.jwt) return
loading = true
@@ -33,9 +33,9 @@
<ShieldIcon filled width={14} />
</Button>
{/snippet}
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
<MenuDivider>
{#if !item.community.local && !amMod($profile.user, item.community)}
{#if !item.community.local && !amMod(profile.data.user, item.community)}
{$t('moderation.labelInstanceOnly')}
{:else}
{$t('moderation.label')}
@@ -53,7 +53,7 @@
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
{/if}
</MenuButton>
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
<!--Comment made by someone else-->
<MenuButton
color="danger-subtle"
@@ -72,12 +72,12 @@
<MenuButton
color="success-subtle"
onclick={async () => {
if (!$profile.jwt) return
if (!profile.data.jwt) return
item.comment = (
await feature(
!item.comment.distinguished,
item.comment,
$profile.jwt,
profile.data.jwt,
)
).comment_view.comment
}}
@@ -92,7 +92,7 @@
{/if}
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuDivider>{$t('admin.label')}</MenuDivider>
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
{#snippet prefix()}
@@ -31,7 +31,7 @@
let acting = $derived(locking || pinning)
async function lock(lock: boolean) {
if (!$profile?.jwt || !isPostView(item)) return
if (!profile.data?.jwt || !isPostView(item)) return
locking = true
try {
@@ -52,7 +52,7 @@
}
async function pin(pinned: boolean, toInstance: boolean = false) {
if (!$profile?.jwt || !isPostView(item)) return
if (!profile.data?.jwt || !isPostView(item)) return
pinning = true
@@ -87,9 +87,9 @@
<ShieldIcon filled width={16} />
</Button>
{/snippet}
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
<MenuDivider>
{#if !item.community.local && !amMod($profile.user, item.community)}
{#if !item.community.local && !amMod(profile.data.user, item.community)}
{$t('moderation.labelInstanceOnly')}
{:else}
{$t('moderation.label')}
@@ -123,7 +123,7 @@
? $t('moderation.unfeature')
: $t('moderation.feature')}
</span>
{#if isAdmin($profile.user)}
{#if isAdmin(profile.data.user)}
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
{/if}
</div>
@@ -138,7 +138,7 @@
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
{/if}
</MenuButton>
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
{#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -151,7 +151,7 @@
</MenuButton>
{/if}
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuDivider>{$t('admin.label')}</MenuDivider>
<MenuButton
color="success-subtle"
@@ -66,7 +66,7 @@
async function remove() {
if (!item) return
if (!$profile?.jwt) throw new Error('Unauthenticated')
if (!profile.data?.jwt) throw new Error('Unauthenticated')
loading = true
@@ -207,7 +207,7 @@
bind:value={reason}
/>
{#if !removed && $profile?.user && (amMod($profile.user, item.community) || (isAdmin($profile.user) && item.community.local))}
{#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))}
<Switch bind:checked={commentReason}>
{$t('moderation.removeSubmission.withReason')}
</Switch>
@@ -41,7 +41,7 @@
let reason = $state('')
async function report() {
if (!item || !$profile?.jwt || reason == '') return
if (!item || !profile.data?.jwt || reason == '') return
loading = true
try {
+3 -11
View File
@@ -1,21 +1,13 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import { isImage, isVideo } from '$lib/ui/image.js'
import { getInstance } from '$lib/lemmy.js'
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import PostMeta, {
parseTags,
type Tag,
} from '$lib/components/lemmy/post/PostMeta.svelte'
import { Badge, Material, toast } from 'mono-svelte'
import {
bestImageURL,
mediaType,
postLink,
} from '$lib/components/lemmy/post/helpers.js'
import Empty from '$lib/components/helper/Empty.svelte'
import { Badge } from 'mono-svelte'
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
import { publishedToDate } from '$lib/components/util/date.js'
import { ArrowUp, ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
@@ -128,7 +120,7 @@
admin: post.creator_is_admin,
moderator: post.creator_is_moderator,
}}
subscribed={$profile?.user?.follows
subscribed={profile.data?.user?.follows
.map((c) => c.community.id)
.includes(post.community.id)
? 'Subscribed'
@@ -1,17 +1,15 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import PostVote from './PostVote.svelte'
import { getInstance, site } from '$lib/lemmy.js'
import { site } from '$lib/lemmy.js'
import {
ArrowsUpDown,
ArrowTopRightOnSquare,
Bookmark,
BookmarkSlash,
BugAnt,
ChatBubbleLeftEllipsis,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
CheckBadge,
Clock,
EllipsisHorizontal,
Eye,
@@ -19,20 +17,16 @@
Flag,
GlobeAmericas,
Icon,
Language,
MapPin,
Newspaper,
Pencil,
PencilSquare,
ServerStack,
Share,
Star,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { createEventDispatcher } from 'svelte'
import {
amMod,
isAdmin,
@@ -101,7 +95,7 @@
<div class="mx-auto h-96 flex justify-center items-center">
<Spinner width={32} />
</div>
{:then {default: PostForm }}
{:then { default: PostForm }}
<PostForm
edit
editingPost={post.post}
@@ -131,7 +125,7 @@
score={post.counts.score}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
showCounts={$profile?.user?.local_user_view?.local_user?.show_scores ??
showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ??
true}
/>
@@ -176,7 +170,7 @@
{/snippet}
</Button>
{/if}
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
{#if profile.data?.user && (amMod(profile.data.user, post.community) || isAdmin(profile.data.user))}
<ModerationMenu
size="custom"
color="ghost"
@@ -187,12 +181,12 @@
/>
{/if}
{#if $profile?.jwt}
{#if profile.data?.jwt}
<Button
onclick={async () => {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
saving = true
post.saved = await save(post, !post.saved, $profile?.jwt)
post.saved = await save(post, !post.saved, profile.data?.jwt)
saving = false
}}
size="custom"
@@ -304,7 +298,7 @@
<MenuDivider>
{$t('post.actions.more.actions')}
</MenuDivider>
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
{#if profile.data?.user && profile.data?.jwt && profile.data.user.local_user_view.person.id == post.creator.id}
<MenuButton onclick={() => (editing = true)}>
{#snippet prefix()}
<Icon src={PencilSquare} size="16" micro />
@@ -312,11 +306,15 @@
{$t('post.actions.more.edit')}
</MenuButton>
{/if}
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
onclick={async () => {
if ($profile?.jwt)
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
if (profile.data?.jwt)
post.read = await markAsRead(
post.post,
!post.read,
profile.data.jwt,
)
}}
>
{#snippet prefix()}
@@ -331,12 +329,12 @@
onclick={() => {
navigator.share?.({
url: localShare
? `${instanceToURL(getInstance())}/post/${post.post.id}`
? `${instanceToURL(profile.data.instance)}/post/${post.post.id}`
: post.post.ap_id,
}) ??
navigator.clipboard.writeText(
localShare
? `${instanceToURL(getInstance())}/post/${post.post.id}`
? `${instanceToURL(profile.data.instance)}/post/${post.post.id}`
: post.post.ap_id,
)
toast({ content: $t('toast.copied') })
@@ -371,7 +369,7 @@
</div>
{/if}
</MenuButton>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
onclick={() => {
setSessionStorage('postDraft', {
@@ -400,14 +398,14 @@
{/snippet}
{$t('post.actions.more.crosspost')}
</MenuButton>
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
{#if profile.data.user && post.creator.id == profile.data.user.local_user_view.person.id}
<MenuButton
onclick={async () => {
if ($profile?.jwt)
if (profile.data?.jwt)
post.post.deleted = await deleteItem(
post,
!post.post.deleted,
$profile.jwt,
profile.data.jwt,
)
}}
color="danger-subtle"
@@ -420,15 +418,15 @@
: $t('post.actions.more.delete')}
</MenuButton>
{/if}
{#if $profile.user?.local_user_view.person.id != post.creator.id}
{#if profile.data.user?.local_user_view.person.id != post.creator.id}
{#if feature('hidePosts', $site?.version)}
<MenuButton
onclick={async () => {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
const hidden = await hidePost(
post.post.id,
!post.hidden,
$profile?.jwt,
profile.data?.jwt,
)
post.hidden = hidden
if (hidden) onhide?.(hidden)
@@ -43,8 +43,6 @@
</script>
<script lang="ts">
import { stopPropagation } from 'svelte/legacy'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { Badge, Popover } from 'mono-svelte'
@@ -63,7 +61,6 @@
Trash,
PaperAirplane,
} from 'svelte-hero-icons'
import { getInstance } from '$lib/lemmy.js'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { settings, type View } from '$lib/settings.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
@@ -71,6 +68,7 @@
import { Pencil, type IconSource } from 'svelte-hero-icons'
import CommunityHeader from '../community/CommunityHeader.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { profile } from '$lib/auth.svelte'
interface Props {
community?: Community | undefined
@@ -287,7 +285,7 @@
</header>
{#if title && id}
<a
href="/post/{getInstance()}/{id}"
href="/post/{profile.data.instance}/{id}"
class="inline hover:underline
hover:text-primary-900 hover:dark:text-primary-100 transition-colors max-[480px]:!mt-0
{settings.font == 'satoshi/nunito'
@@ -54,14 +54,14 @@
let oldScore = score
const castVote = async (newVote: number) => {
if (!$profile?.jwt) {
if (!profile.data?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
}
loading = true
oldScore = score
vote = newVote
const res = await voteItem(post, newVote, $profile.jwt).catch((e) => {
const res = await voteItem(post, newVote, profile.data.jwt).catch((e) => {
toast({ content: errorMessage(e), type: 'error' })
return { upvotes: 0, downvotes: 0, score: 0 }
})
@@ -133,7 +133,7 @@
})
return
}
if (!data.title || !$profile?.jwt) return
if (!data.title || !profile.data?.jwt) return
if (data.url && data.url != '') {
try {
new URL(data.url)
@@ -278,7 +278,7 @@
<ObjectAutocomplete
bind:q={communitySearch}
items={communities}
jwt={$profile?.jwt}
jwt={profile.data?.jwt}
listing_type="All"
label={$t('form.post.community')}
required
+5 -2
View File
@@ -1,8 +1,10 @@
import { client, getInstance } from '$lib/lemmy.js'
import { profile } from '$lib/auth.svelte'
import { client } from '$lib/lemmy.js'
import type { View } from '$lib/settings.svelte'
import { isImage, isVideo } from '$lib/ui/image'
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
me.person.id == comment.creator.id
@@ -57,7 +59,8 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
return url?.match?.(YOUTUBE_REGEX)
}
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
export const postLink = (post: Post) =>
`/post/${profile.data.instance}/${post.id}`
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
export type IframeType = 'youtube' | 'video' | 'none'
+3 -11
View File
@@ -29,7 +29,7 @@
let customHref = (href?: string) => {
if (href?.startsWith('?')) {
const current = pageData.url.searchParams
const current = new URLSearchParams(pageData.url.searchParams)
const newParams = new URLSearchParams(href)
current.delete(newParams.keys().toArray()[0])
@@ -56,11 +56,7 @@
<Button
href={customHref(href?.(cursor?.back ?? page - 1))}
color="ghost"
onclick={() => {
invalidateAll()
if (cursor?.back) onchangecursor?.(cursor.back)
else onchange?.(--page)
}}
onclick={() => invalidateAll()}
title={$t('common.back')}
size="square-md"
rounding="pill"
@@ -91,11 +87,7 @@
<Button
href={customHref(href?.(cursor?.next ?? page + 1))}
color="ghost"
onclick={() => {
invalidateAll()
if (cursor?.next) onchangecursor?.(cursor?.next)
else onchange?.(++page)
}}
onclick={() => invalidateAll()}
title={$t('common.next')}
size="square-md"
rounding="pill"
+7 -7
View File
@@ -77,7 +77,7 @@
style="border-radius: inherit;"
>
<div class="ml-auto"></div>
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<NavButton
href="/admin"
label={$t('nav.admin')}
@@ -92,7 +92,7 @@
{/if}
</NavButton>
{/if}
{#if amModOfAny($profile?.user)}
{#if amModOfAny(profile.data?.user)}
<NavButton
href="/moderation"
label={$t('nav.moderation')}
@@ -124,7 +124,7 @@
/>
{/snippet}
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
<MenuButton link href="/create/post" disabled={!$profile?.jwt}>
<MenuButton link href="/create/post" disabled={!profile.data?.jwt}>
{#snippet prefix()}
<Icon src={PencilSquare} size="16" micro />
{/snippet}
@@ -133,17 +133,17 @@
<MenuButton
link
href="/create/community"
disabled={!$profile?.jwt ||
!$profile?.user ||
disabled={!profile.data?.jwt ||
!profile.data?.user ||
($site?.site_view.local_site.community_creation_admin_only &&
!isAdmin($profile.user))}
!isAdmin(profile.data.user))}
>
{#snippet prefix()}
<Icon src={Newspaper} size="16" micro />
{/snippet}
{$t('nav.create.community')}
</MenuButton>
{#if !$profile?.jwt}
{#if !profile.data?.jwt}
<span class="text-sm mx-4 my-1 py-1">
{$t('nav.create.logingate')}
</span>
+6 -6
View File
@@ -74,14 +74,14 @@
hover:border-primary-900 hover:dark:border-primary-100 active:scale-95 {buttonClass}"
title={$t('profile.profile')}
>
{#if $profile?.user}
{#if profile.data?.user}
<div
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center"
>
<Avatar
url={$profile.user.local_user_view.person.avatar}
url={profile.data.user.local_user_view.person.avatar}
width={36}
alt={$profile.user.local_user_view.person.name}
alt={profile.data.user.local_user_view.person.name}
/>
</div>
{#if $notifications.inbox > 0}
@@ -96,9 +96,9 @@
{/if}
</button>
{/snippet}
{#if $profile?.user}
{#if profile.data?.user}
<UserLink
user={$profile?.user.local_user_view.person}
user={profile.data?.user.local_user_view.person}
showInstance={false}
avatar
avatarSize={24}
@@ -108,7 +108,7 @@
{:else}
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
{/if}
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton link href="/profile">
{#snippet prefix()}
<Icon src={UserCircle} micro width={16} />
@@ -23,7 +23,6 @@
<Button
href={action.href}
onclick
alignment="left"
color="tertiary"
size="lg"
@@ -229,8 +229,8 @@
$effect(() => {
groups = getGroups(
$resumables,
$profile,
$profileData.profiles,
profile.data,
profileData.profiles,
$themeData,
page.data.contextual?.actions,
)
@@ -92,7 +92,7 @@ export function getGroups(
name: t.get('nav.communities'),
icon: GlobeAlt,
},
...(amModOfAny(profile.user)
...(amModOfAny(profile.data.user)
? [
{
href: '/moderation',
@@ -101,7 +101,7 @@ export function getGroups(
},
]
: []),
...(profile.user && isAdmin(profile.user)
...(profile.data.user && isAdmin(profile.data.user)
? [
{
href: '/admin',
@@ -236,23 +236,23 @@ export function getGroups(
],
},
{
name: t.get('profile.profile'),
actions: profile.jwt
name: t.get('profile.data.profile'),
actions: profile.data.jwt
? [
{
href: '/profile/user',
name: t.get('profile.profile'),
name: t.get('profile.data.profile'),
icon: UserCircle,
},
{
href: '/inbox',
name: t.get('profile.inbox'),
name: t.get('profile.data.inbox'),
icon: Inbox,
shortcut: 'i',
},
{
href: '/saved',
name: t.get('profile.saved'),
name: t.get('profile.data.saved'),
icon: Bookmark,
},
{
@@ -311,7 +311,7 @@ export function getGroups(
icon: p.avatar ?? UserCircle,
detail: p.instance,
handle: async () => {
if (profile.id != p.id) {
if (profile.data.id != p.id) {
await setUserID(p.id)
}
@@ -407,9 +407,9 @@ export function getGroups(
],
},
{
name: t.get('profile.subscribed'),
name: t.get('profile.data.subscribed'),
actions:
profile?.user?.follows.map((f) => ({
profile.data?.user?.follows.map((f) => ({
icon: f.community.icon,
name: f.community.title,
href: `/c/${fullCommunityName(
@@ -25,7 +25,7 @@
animate:flip={{ duration: 500, easing: expoOut }}
>
<div class="flex-none grid group">
{#if $profile && !hasFavorite($profile, follow.id)}
{#if profile && !hasFavorite(profile.data, follow.id)}
<Button
rounding="pill"
size="custom"
@@ -36,7 +36,7 @@
>
<Icon src={Star} size="16" mini />
</Button>
{:else if isFavorites && $profile && hasFavorite($profile, follow.id)}
{:else if isFavorites && profile && hasFavorite(profile.data, follow.id)}
<Button
rounding="pill"
size="custom"
@@ -53,7 +53,7 @@
alt={follow.name}
title={follow.title}
width={28}
class={!isFavorites && $profile && hasFavorite($profile, follow.id)
class={!isFavorites && profile && hasFavorite(profile.data, follow.id)
? ''
: 'group-hover:hidden'}
/>
@@ -23,21 +23,22 @@
alignment="left"
loading={switching}
loaderWidth={20}
selected={$profile?.id == prof.id}
selected={profile.data?.id == prof.id}
onclick={async () => {
switching = true
if ($profile?.id != prof.id) {
if (profile.data?.id != prof.id) {
await setUserID(prof.id)
}
await goto(page.url, {
invalidateAll: true,
})
console.log(page.url)
// await goto(page.url, {
// invalidateAll: true,
// })
switching = false
}}
class="w-full font-normal {$profile?.id == prof.id
class="w-full font-normal {profile.data?.id == prof.id
? '!bg-slate-100 dark:!bg-zinc-900'
: ''}"
>
@@ -46,11 +47,11 @@
profile={prof}
{index}
{guest}
selected={$profile?.id == prof.id}
selected={profile.data?.id == prof.id}
/>
{/snippet}
<span
class="inline-flex flex-col gap-0 {$profile?.id == prof.id
class="inline-flex flex-col gap-0 {profile.data?.id == prof.id
? 'font-semibold'
: ''}"
>
+15 -13
View File
@@ -33,7 +33,7 @@
gap-1 h-fit max-h-screen {clazz}"
{style}
>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<SidebarButton icon={UserCircle} href="/profile">
{#snippet label()}
<span>
@@ -90,7 +90,7 @@
{/snippet}
</SidebarButton>
{/if}
{#if $profileData.profiles.length >= 1}
{#if profileData.profiles.length >= 1}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
<Expandable
@@ -103,13 +103,13 @@
{$t('account.accounts')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profileData.profiles.length}
{profileData.profiles.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
{#each [...$profileData.profiles] as prof, index}
{#each [...profileData.profiles] as prof, index}
<div class="w-full">
<ProfileButton {index} {prof} />
</div>
@@ -120,7 +120,7 @@
</Expandable>
{/if}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{#if $profile?.favorites && $profile?.favorites.length > 0}
{#if profile.data?.favorites && profile.data?.favorites.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.favorites}
@@ -135,18 +135,18 @@
{$t('routes.profile.favorites')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.favorites?.length}
{profile.data.favorites?.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList isFavorites items={$profile.favorites} />
<CommunityList isFavorites items={profile.data.favorites} />
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{/if}
{#if $profile?.user}
{#if $profile?.user.moderates.length > 0}
{#if profile.data?.user}
{#if profile.data?.user.moderates.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.moderates}
@@ -161,14 +161,14 @@
{$t('routes.profile.moderates')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.user?.moderates.length}
{profile.data.user?.moderates.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList
items={$profile.user.moderates.map((i) => i.community)}
items={profile.data.user.moderates.map((i) => i.community)}
/>
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
@@ -188,13 +188,15 @@
{$t('profile.subscribed')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.user?.follows.length}
{profile.data.user?.follows.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList items={$profile.user.follows.map((i) => i.community)} />
<CommunityList
items={profile.data.user.follows.map((i) => i.community)}
/>
</Expandable>
{/if}
</nav>
@@ -12,7 +12,7 @@
</script>
<Modal bind:open>
{#snippet title()}
{#snippet customTitle()}
<span>
{#if title}{@render title()}{:else}Debug{/if}
</span>