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:
1 parent
8c6ff77fac
commit
5651ad475d
83 files changed
+395
-469
No files matched your search
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user