feat: switch to new account system
This commit is contained in:
1 parent
54ab6fdc82
commit
2da415b670
38 files changed
+222
-362
No files matched your search
@@ -8,10 +8,10 @@
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
import { fly } from 'svelte/transition'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import { authData } from '$lib/lemmy.js'
|
||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
>
|
||||
<MultiSelect
|
||||
options={['Subscribed', 'Local', 'All']}
|
||||
disabled={[$authData?.token == undefined]}
|
||||
disabled={[$profile?.jwt == undefined]}
|
||||
selected={data.listingType}
|
||||
on:select={(e) => {
|
||||
$page.url.searchParams.set('type', e.detail)
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export async function load({ url }) {
|
||||
const page = Number(url.searchParams.get('page') || 1) || 1
|
||||
@@ -24,7 +25,7 @@ export async function load({ url }) {
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: listingType,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
streamed: {
|
||||
site: getClient().getSite({}),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
@@ -18,12 +19,12 @@ export async function load(req: any) {
|
||||
community_name: req.params.name,
|
||||
page: page,
|
||||
sort: sort,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
community: (
|
||||
await getClient().getCommunity({
|
||||
name: req.params.name,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
).community_view,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { ListingType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -15,7 +16,7 @@ export async function load({ url }) {
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
} else {
|
||||
return await getClient().listCommunities({
|
||||
@@ -23,7 +24,7 @@ export async function load({ url }) {
|
||||
page: page,
|
||||
sort: 'TopAll',
|
||||
type_: type,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type {
|
||||
Community,
|
||||
CommunityView,
|
||||
SubscribedType,
|
||||
} from 'lemmy-js-client'
|
||||
import { authData } from '$lib/lemmy.js'
|
||||
import type { CommunityView } from 'lemmy-js-client'
|
||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let community: CommunityView
|
||||
|
||||
let subscribing = false
|
||||
|
||||
async function subscribe() {
|
||||
if (!$authData?.token) return
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
subscribing = true
|
||||
|
||||
try {
|
||||
const res = await getClient().followCommunity({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
community_id: community.community.id,
|
||||
follow: community.subscribed == 'NotSubscribed',
|
||||
})
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { authData } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
onMount(() => {
|
||||
if (!$authData) {
|
||||
if (!$profile?.jwt) {
|
||||
goto('/login')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
import InboxItem from './InboxItem.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import { Check, EnvelopeOpen, Icon } from 'svelte-hero-icons'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { isRead } from '$lib/lemmy/inbox.js'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let data
|
||||
|
||||
let markingAsRead = false
|
||||
|
||||
async function markAllAsRead() {
|
||||
if (!$user) {
|
||||
if (!$profile?.user) {
|
||||
goto('/login')
|
||||
return
|
||||
}
|
||||
@@ -22,10 +23,10 @@
|
||||
markingAsRead = true
|
||||
|
||||
const response = await getClient().markAllAsRead({
|
||||
auth: $authData!.token,
|
||||
auth: $profile.jwt!,
|
||||
})
|
||||
|
||||
$user!.unreads = 0
|
||||
$profile.user.unreads = 0
|
||||
|
||||
goto($page.url, {
|
||||
invalidateAll: true,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url }) {
|
||||
const auth = get(authData)
|
||||
if (!auth) return
|
||||
const auth = get(profile)
|
||||
if (!auth?.jwt) return
|
||||
|
||||
const type: InboxFeedType =
|
||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||
@@ -18,7 +19,7 @@ export async function load({ url }) {
|
||||
const params = {
|
||||
limit: 50,
|
||||
page: page,
|
||||
auth: auth.token,
|
||||
auth: auth.jwt,
|
||||
unread_only: unreadOnly,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import type {
|
||||
CommentReplyView,
|
||||
PersonMentionView,
|
||||
@@ -34,13 +33,13 @@
|
||||
async function replyToMessage(
|
||||
message: PrivateMessageView | CommentReplyView | PersonMentionView
|
||||
) {
|
||||
if (!$authData) return
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
content: reply,
|
||||
recipient_id: message.creator.id,
|
||||
})
|
||||
@@ -105,7 +104,7 @@
|
||||
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
|
||||
>
|
||||
<span class="font-bold flex items-center">
|
||||
{#if item.creator.id == $user?.local_user_view.person.id}
|
||||
{#if item.creator.id == $profile?.user?.local_user_view.person.id}
|
||||
You
|
||||
{:else}
|
||||
<UserLink avatar user={item.creator} />
|
||||
@@ -113,7 +112,7 @@
|
||||
</span>
|
||||
<span>messaged</span>
|
||||
<span class="font-bold flex items-center">
|
||||
{#if item.recipient.id == $user?.local_user_view.person.id}
|
||||
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
|
||||
You
|
||||
{:else}
|
||||
<UserLink avatar user={item.recipient} />
|
||||
@@ -124,7 +123,7 @@
|
||||
<p class="text-sm py-2">
|
||||
<Markdown source={item.private_message.content} />
|
||||
</p>
|
||||
{#if item.recipient.id == $user?.local_user_view.person.id}
|
||||
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
|
||||
<div class="flex flex-row gap-2">
|
||||
<Button color="ghost" on:click={() => (replying = !replying)}>
|
||||
<Icon mini src={ChatBubbleOvalLeft} width={16} />
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
import {
|
||||
DEFAULT_INSTANCE_URL,
|
||||
LINKED_INSTANCE_URL,
|
||||
authData,
|
||||
getClient,
|
||||
user,
|
||||
validateInstance,
|
||||
} from '$lib/lemmy.js'
|
||||
|
||||
@@ -53,7 +51,6 @@
|
||||
content: error as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
user.set(null)
|
||||
}
|
||||
data.loading = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -12,11 +13,11 @@ export async function load({ url }) {
|
||||
const filter: ReportFilter =
|
||||
(url.searchParams.get('filter') as ReportFilter) || 'all'
|
||||
|
||||
const jwt = get(authData)?.token
|
||||
const jwt = get(profile)?.jwt
|
||||
|
||||
if (!jwt) return { type: type, page: page }
|
||||
|
||||
// can they like
|
||||
// can they please
|
||||
// make a sane, consistent, and simple API for once
|
||||
// 3 separate requests? really?
|
||||
// and this time instead of get() it's list(). Why?!
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { isCommentReport, isPostReport } from '$lib/lemmy/item.js'
|
||||
import type {
|
||||
CommentReportView,
|
||||
@@ -11,7 +11,7 @@
|
||||
PrivateMessageReportView,
|
||||
} from 'lemmy-js-client'
|
||||
import { Check, Icon } from 'svelte-hero-icons'
|
||||
import { get } from 'svelte/store'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let item: PostReportView | CommentReportView | PrivateMessageReportView
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
|
||||
let resolving = false
|
||||
async function resolve() {
|
||||
if (!$authData || !$user) return
|
||||
if (!$profile?.jwt || !$profile.user) return
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
if (isCommentReport(item)) {
|
||||
await getClient().resolveCommentReport({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
report_id: item.comment_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
@@ -42,7 +42,7 @@
|
||||
})
|
||||
} else if (isPostReport(item)) {
|
||||
await getClient().resolvePostReport({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
report_id: item.post_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
@@ -55,10 +55,10 @@
|
||||
}
|
||||
|
||||
const reports = await getClient().getReportCount({
|
||||
auth: get(authData)!.token,
|
||||
auth: $profile?.jwt,
|
||||
})
|
||||
|
||||
$user.reports =
|
||||
$profile.user.reports =
|
||||
reports.comment_reports +
|
||||
reports.post_reports +
|
||||
(reports.private_message_reports ?? 0)
|
||||
|
||||
@@ -4,26 +4,15 @@
|
||||
buildCommentsTreeAsync,
|
||||
} from '$lib/components/lemmy/comment/comments.js'
|
||||
import Comments from '$lib/components/lemmy/comment/Comments.svelte'
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import { isImage } from '$lib/ui/image.js'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import Badge from '$lib/components/ui/Badge.svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
@@ -32,6 +21,7 @@
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import type { CommentSortType } from 'lemmy-js-client'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -39,9 +29,9 @@
|
||||
const post = postData.post
|
||||
|
||||
onMount(async () => {
|
||||
if (!postData.read && $authData) {
|
||||
if (!postData.read && $profile?.jwt) {
|
||||
getClient().markPostAsRead({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
read: true,
|
||||
post_id: post.id,
|
||||
})
|
||||
@@ -58,7 +48,7 @@
|
||||
commentsPage = 1
|
||||
|
||||
data.streamed.comments = getClient().getComments({
|
||||
auth: $authData?.token,
|
||||
auth: $profile?.jwt,
|
||||
max_depth: 3,
|
||||
page: commentsPage,
|
||||
limit: 25,
|
||||
@@ -82,7 +72,7 @@
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
{#if $authData && $page.params.instance.toLowerCase() != $authData.instance.toLowerCase()}
|
||||
{#if $profile && $page.params.instance.toLowerCase() != $profile.instance.toLowerCase()}
|
||||
<Card cardColor="warning" class="p-4 flex flex-col gap-1">
|
||||
<Icon
|
||||
src={ExclamationTriangle}
|
||||
@@ -183,7 +173,7 @@
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:then comments}
|
||||
{#if $user}
|
||||
{#if $profile?.user}
|
||||
<CommentForm
|
||||
postId={post.id}
|
||||
on:comment={(comment) =>
|
||||
@@ -211,7 +201,7 @@
|
||||
loading = true
|
||||
|
||||
const loadedComments = await getClient().getComments({
|
||||
auth: $authData?.token,
|
||||
auth: $profile?.jwt,
|
||||
max_depth: 3,
|
||||
page: ++commentsPage,
|
||||
limit: 25,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url }) {
|
||||
const post = await getClient(params.instance.toLowerCase()).getPost({
|
||||
id: Number(params.id),
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
||||
@@ -36,7 +37,7 @@ export async function load({ params, url }) {
|
||||
max_depth: max_depth,
|
||||
saved_only: false,
|
||||
sort: 'Hot',
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
parent_id: parentId,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -11,7 +12,7 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
export async function load({ url }) {
|
||||
if (!get(authData)) return { posts: [] }
|
||||
if (!get(profile)) return { posts: [] }
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
const client = getClient()
|
||||
@@ -19,7 +20,7 @@ export async function load({ url }) {
|
||||
const [posts, comments] = await Promise.all([
|
||||
client.getPosts({
|
||||
saved_only: true,
|
||||
auth: get(authData)!.token,
|
||||
auth: get(profile)!.jwt,
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: 'New',
|
||||
@@ -27,7 +28,7 @@ export async function load({ url }) {
|
||||
|
||||
client.getComments({
|
||||
saved_only: true,
|
||||
auth: get(authData)!.token,
|
||||
auth: get(profile)!.jwt,
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: 'New',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import type {
|
||||
CommentView,
|
||||
@@ -21,7 +22,7 @@ export async function load({ url }) {
|
||||
if (query) {
|
||||
const results = await getClient().search({
|
||||
q: query,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
community_name: community ?? undefined,
|
||||
limit: 40,
|
||||
page: page,
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import {
|
||||
LINKED_INSTANCE_URL,
|
||||
authData,
|
||||
instance,
|
||||
user,
|
||||
validateInstance,
|
||||
} from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
@@ -17,34 +15,8 @@
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
|
||||
let data = {
|
||||
newInstance: $instance,
|
||||
loading: false,
|
||||
}
|
||||
|
||||
async function changeInstance() {
|
||||
data.loading = true
|
||||
try {
|
||||
authData.set(undefined)
|
||||
user.set(undefined)
|
||||
if (typeof localStorage != 'undefined') {
|
||||
localStorage.removeItem('user')
|
||||
}
|
||||
|
||||
if (!(await validateInstance(data.newInstance))) {
|
||||
throw new Error('Failed to contact that instance URL')
|
||||
}
|
||||
|
||||
instance.set(data.newInstance)
|
||||
|
||||
$userSettings.instance = data.newInstance
|
||||
} catch (error) {
|
||||
toast({
|
||||
content: error as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
data.loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -54,31 +26,6 @@
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-3xl font-bold">Settings</h1>
|
||||
<h2 class="uppercase font-bold opacity-80 text-sm mt-4">General</h2>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
<Setting>
|
||||
<span slot="title">Instance</span>
|
||||
<span slot="description">Changing this will log you out.</span>
|
||||
<div class="flex gap-2">
|
||||
<TextInput
|
||||
bind:value={data.newInstance}
|
||||
pattern={'(?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*.[A-Za-z]{2,6}'}
|
||||
class="flex-1"
|
||||
/>
|
||||
<div class="w-24">
|
||||
<Button
|
||||
color="primary"
|
||||
loading={data.loading}
|
||||
disabled={data.loading}
|
||||
on:click={changeInstance}
|
||||
size="lg"
|
||||
class="h-full"
|
||||
>
|
||||
Change
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Setting>
|
||||
{/if}
|
||||
<Setting>
|
||||
<span slot="title">Default sort</span>
|
||||
<span slot="description">The default sort to use for feeds.</span>
|
||||
|
||||
@@ -19,34 +19,37 @@
|
||||
import { page } from '$app/stores'
|
||||
import { goto } from '$app/navigation'
|
||||
import { isComment } from '$lib/lemmy/item.js'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { isBlocked } from '$lib/lemmy/user.js'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
|
||||
export let data
|
||||
|
||||
let blocking = false
|
||||
|
||||
async function blockUser(block: number) {
|
||||
if (!$user || !$authData) throw new Error('Unauthenticated')
|
||||
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
||||
|
||||
blocking = true
|
||||
try {
|
||||
const blocked = isBlocked($user, block)
|
||||
const blocked = isBlocked($profile.user, block)
|
||||
|
||||
await getClient().blockPerson({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
block: !blocked,
|
||||
person_id: block,
|
||||
})
|
||||
|
||||
if (blocked) {
|
||||
const index = $user.person_blocks.map((p) => p.target.id).indexOf(block)
|
||||
$user.person_blocks.splice(index, 1)
|
||||
const index = $profile.user.person_blocks
|
||||
.map((p) => p.target.id)
|
||||
.indexOf(block)
|
||||
$profile.user.person_blocks.splice(index, 1)
|
||||
}
|
||||
|
||||
toast({
|
||||
@@ -71,13 +74,13 @@
|
||||
let message = ''
|
||||
|
||||
async function sendMessage() {
|
||||
if (!$authData || message == '') return
|
||||
if (!$profile?.jwt || message == '') return
|
||||
|
||||
loadingMessage = true
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $authData.token,
|
||||
auth: $profile.jwt,
|
||||
content: message,
|
||||
recipient_id: data.person_view.person.id,
|
||||
})
|
||||
@@ -103,7 +106,7 @@
|
||||
<title>{data.person_view.person.name}</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if $authData}
|
||||
{#if $profile?.user}
|
||||
<Modal bind:open={messaging}>
|
||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
||||
@@ -198,7 +201,7 @@
|
||||
<FormattedNumber number={data.person_view.counts.comment_count} />
|
||||
</span>
|
||||
</div>
|
||||
{#if $user && $authData && data.person_view.person.id != $user.local_user_view.person.id}
|
||||
{#if $profile?.user && $profile.jwt && data.person_view.person.id != $profile.user.local_user_view.person.id}
|
||||
<div class="flex flex-col gap-2">
|
||||
<Button
|
||||
size="lg"
|
||||
@@ -216,7 +219,9 @@
|
||||
on:click={() => blockUser(data.person_view.person.id)}
|
||||
>
|
||||
<Icon slot="icon" mini size="16" src={NoSymbol} />
|
||||
{isBlocked($user, data.person_view.person.id) ? 'Unblock' : 'Block'}
|
||||
{isBlocked($profile.user, data.person_view.person.id)
|
||||
? 'Unblock'
|
||||
: 'Block'}
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
@@ -14,7 +15,7 @@ export async function load({ params, url }) {
|
||||
page: page,
|
||||
username: params.name,
|
||||
sort: sort,
|
||||
auth: get(authData)?.token,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
const items = [...user.posts, ...user.comments]
|
||||
|
||||
Reference in new issue
Block a user