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'