feat: switch to new account system
This commit is contained in:
1 parent
54ab6fdc82
commit
2da415b670
38 files changed
+213
-353
No files matched your search
+15
-8
@@ -1,9 +1,15 @@
|
|||||||
|
import { env } from '$env/dynamic/public'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { DEFAULT_INSTANCE_URL, getClient, instance } from '$lib/lemmy.js'
|
import { getClient, instance } from '$lib/lemmy.js'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { MyUserInfo } from 'lemmy-js-client'
|
import type { MyUserInfo } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
|
||||||
|
const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL
|
||||||
|
const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml'
|
||||||
|
|
||||||
function getFromStorage<T>(key: string): T | undefined {
|
function getFromStorage<T>(key: string): T | undefined {
|
||||||
|
if (typeof localStorage == 'undefined') return undefined
|
||||||
const lc = localStorage.getItem(key)
|
const lc = localStorage.getItem(key)
|
||||||
if (!lc) return undefined
|
if (!lc) return undefined
|
||||||
|
|
||||||
@@ -11,6 +17,7 @@ function getFromStorage<T>(key: string): T | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setFromStorage(key: string, item: any) {
|
function setFromStorage(key: string, item: any) {
|
||||||
|
if (typeof localStorage == 'undefined') return
|
||||||
return localStorage.setItem(key, JSON.stringify(item))
|
return localStorage.setItem(key, JSON.stringify(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,15 +53,13 @@ profileData.subscribe((pd) => {
|
|||||||
export const profile = writable<Profile | undefined>(getProfile())
|
export const profile = writable<Profile | undefined>(getProfile())
|
||||||
|
|
||||||
profile.subscribe(async (p) => {
|
profile.subscribe(async (p) => {
|
||||||
if (p?.instance) {
|
|
||||||
instance.set(p.instance)
|
|
||||||
}
|
|
||||||
if (!p || !p.jwt) {
|
if (!p || !p.jwt) {
|
||||||
profileData.update((pd) => ({ ...pd, profile: -1 }))
|
profileData.update((pd) => ({ ...pd, profile: -1 }))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (p.user) return
|
if (p.user) return
|
||||||
|
|
||||||
|
instance.set(p.instance)
|
||||||
// fetch the user because p.user is undefined
|
// fetch the user because p.user is undefined
|
||||||
const user = await userFromJwt(p.jwt, p.instance)
|
const user = await userFromJwt(p.jwt, p.instance)
|
||||||
|
|
||||||
@@ -134,11 +139,13 @@ function getProfile() {
|
|||||||
return pd.profiles.find((p) => p.id == id)
|
return pd.profiles.find((p) => p.id == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resetProfile() {
|
const getDefaultProfile = () => ({
|
||||||
profile.set({
|
|
||||||
id: -1,
|
id: -1,
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: get(instance),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export function resetProfile() {
|
||||||
|
profile.set(getDefaultProfile())
|
||||||
profileData.update((p) => ({ ...p, profile: -1 }))
|
profileData.update((p) => ({ ...p, profile: -1 }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +175,7 @@ export function setUserID(id: number) {
|
|||||||
}
|
}
|
||||||
const prof = pd.profiles.find((p) => p.id == id)
|
const prof = pd.profiles.find((p) => p.id == id)
|
||||||
|
|
||||||
profile.set(prof)
|
profile.set(prof ?? getDefaultProfile())
|
||||||
profileData.update((p) => ({ ...p, profile: id }))
|
profileData.update((p) => ({ ...p, profile: id }))
|
||||||
|
|
||||||
return prof
|
return prof
|
||||||
|
|||||||
@@ -11,16 +11,13 @@
|
|||||||
import type { CommentNodeI } from './comments'
|
import type { CommentNodeI } from './comments'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import CommentForm from './CommentForm.svelte'
|
import CommentForm from './CommentForm.svelte'
|
||||||
import { page } from '$app/stores'
|
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
||||||
import { createEventDispatcher, getContext } from 'svelte'
|
|
||||||
import type { CommentView } from 'lemmy-js-client'
|
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
export let node: CommentNodeI
|
||||||
export let postId: number
|
export let postId: number
|
||||||
@@ -39,11 +36,11 @@
|
|||||||
bind:open={editing}
|
bind:open={editing}
|
||||||
action="Save"
|
action="Save"
|
||||||
on:action={async () => {
|
on:action={async () => {
|
||||||
if (!$authData || newComment.length <= 0) return
|
if (!$profile?.jwt || newComment.length <= 0) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().editComment({
|
await getClient().editComment({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: node.comment_view.comment.id,
|
comment_id: node.comment_view.comment.id,
|
||||||
content: newComment,
|
content: newComment,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
PencilSquare,
|
PencilSquare,
|
||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
@@ -25,12 +25,13 @@
|
|||||||
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||||
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let comment: CommentView
|
export let comment: CommentView
|
||||||
export let replying: boolean = false
|
export let replying: boolean = false
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
const saved = comment.saved
|
const saved = comment.saved
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().saveComment({
|
await getClient().saveComment({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: comment.comment.id,
|
comment_id: comment.comment.id,
|
||||||
save: !saved,
|
save: !saved,
|
||||||
})
|
})
|
||||||
@@ -70,7 +71,7 @@
|
|||||||
<Icon src={ArrowUturnLeft} width={14} height={14} mini />
|
<Icon src={ArrowUturnLeft} width={14} height={14} mini />
|
||||||
<span class="text-xs">Reply</span>
|
<span class="text-xs">Reply</span>
|
||||||
</Button>
|
</Button>
|
||||||
{#if $user && amMod($user, comment.community)}
|
{#if $profile?.user && amMod($profile?.user, comment.community)}
|
||||||
<CommentModerationMenu item={comment} />
|
<CommentModerationMenu item={comment} />
|
||||||
{/if}
|
{/if}
|
||||||
<Menu
|
<Menu
|
||||||
@@ -89,8 +90,8 @@
|
|||||||
<Icon src={EllipsisHorizontal} width={16} height={16} mini slot="icon" />
|
<Icon src={EllipsisHorizontal} width={16} height={16} mini slot="icon" />
|
||||||
</Button>
|
</Button>
|
||||||
<span class="text-xs opacity-80 py-1 my-1 px-4">Comment actions</span>
|
<span class="text-xs opacity-80 py-1 my-1 px-4">Comment actions</span>
|
||||||
{#if $authData?.token}
|
{#if $profile?.jwt}
|
||||||
{#if comment.creator.id == $user?.local_user_view.person.id}
|
{#if comment.creator.id == $profile.user?.local_user_view.person.id}
|
||||||
<MenuButton on:click={() => dispatcher('edit', comment)}>
|
<MenuButton on:click={() => dispatcher('edit', comment)}>
|
||||||
<Icon src={PencilSquare} mini size="16" />
|
<Icon src={PencilSquare} mini size="16" />
|
||||||
<span>Edit</span>
|
<span>Edit</span>
|
||||||
@@ -100,14 +101,14 @@
|
|||||||
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||||
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
|
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $user && $authData && isCommentMutable(comment, $user.local_user_view)}
|
{#if $profile?.user && $profile.jwt && isCommentMutable(comment, $profile.user.local_user_view)}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="dangerSecondary"
|
color="dangerSecondary"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
try {
|
try {
|
||||||
await getClient().deleteComment({
|
await getClient().deleteComment({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: comment.comment.id,
|
comment_id: comment.comment.id,
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
@@ -127,7 +128,7 @@
|
|||||||
<span>Delete</span>
|
<span>Delete</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $authData && $user?.local_user_view.person.id != comment.creator.id}
|
{#if $profile.jwt && $profile.user?.local_user_view.person.id != comment.creator.id}
|
||||||
<MenuButton on:click={() => report(comment)} color="dangerSecondary">
|
<MenuButton on:click={() => report(comment)} color="dangerSecondary">
|
||||||
<Icon src={Flag} mini size="16" />
|
<Icon src={Flag} mini size="16" />
|
||||||
<span>Report</span>
|
<span>Report</span>
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import type { CommentResponse } from 'lemmy-js-client'
|
import type { CommentResponse } from 'lemmy-js-client'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let postId: number
|
export let postId: number
|
||||||
export let parentId: number | undefined = undefined
|
export let parentId: number | undefined = undefined
|
||||||
@@ -25,13 +26,13 @@
|
|||||||
let preview = false
|
let preview = false
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!$user || !$authData || value == '') return
|
if (!$profile?.user || !$profile?.jwt || value == '') return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getClient().createComment({
|
const response = await getClient().createComment({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
content: value,
|
content: value,
|
||||||
post_id: postId,
|
post_id: postId,
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Color } from '$lib/ui/colors'
|
import { Color } from '$lib/ui/colors'
|
||||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||||
import { authData, getClient } from '$lib/lemmy'
|
import { getClient } from '$lib/lemmy'
|
||||||
import { userSettings } from '$lib/settings'
|
import { userSettings } from '$lib/settings'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let vote: number = 0
|
export let vote: number = 0
|
||||||
export let score: number
|
export let score: number
|
||||||
export let commentId: number
|
export let commentId: number
|
||||||
|
|
||||||
async function upvote() {
|
async function upvote() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
const upvoted = vote == 1
|
const upvoted = vote == 1
|
||||||
|
|
||||||
@@ -26,14 +27,14 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likeComment({
|
.likeComment({
|
||||||
score: upvoted ? 0 : 1,
|
score: upvoted ? 0 : 1,
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: commentId,
|
comment_id: commentId,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downvote() {
|
async function downvote() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
const upvoted = vote == -1
|
const upvoted = vote == -1
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likeComment({
|
.likeComment({
|
||||||
score: upvoted ? 0 : -1,
|
score: upvoted ? 0 : -1,
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: commentId,
|
comment_id: commentId,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
import { onMount, setContext } from 'svelte'
|
import { onMount, setContext } from 'svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentView, Post } from 'lemmy-js-client'
|
import type { CommentView, Post } from 'lemmy-js-client'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js'
|
import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import { profile } from '$lib/auth.js'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
export let nodes: CommentNodeI[]
|
||||||
export let isParent: boolean
|
export let isParent: boolean
|
||||||
@@ -44,7 +43,7 @@
|
|||||||
parent.loading = true
|
parent.loading = true
|
||||||
|
|
||||||
const newComments = await getClient($page.params.instance).getComments({
|
const newComments = await getClient($page.params.instance).getComments({
|
||||||
auth: $authData?.token,
|
auth: $profile?.jwt,
|
||||||
max_depth: 5,
|
max_depth: 5,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
@@ -7,8 +8,7 @@
|
|||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
|
||||||
import type { CommunityView } from 'lemmy-js-client'
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
import {
|
import {
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function subscribe() {
|
async function subscribe() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
loading.subscribing = true
|
loading.subscribing = true
|
||||||
const subscribed =
|
const subscribed =
|
||||||
community_view.subscribed == 'Subscribed' ||
|
community_view.subscribed == 'Subscribed' ||
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().followCommunity({
|
await getClient().followCommunity({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
community_id: community_view.community.id,
|
community_id: community_view.community.id,
|
||||||
follow: !subscribed,
|
follow: !subscribed,
|
||||||
})
|
})
|
||||||
@@ -47,13 +47,13 @@
|
|||||||
loading.subscribing = false
|
loading.subscribing = false
|
||||||
}
|
}
|
||||||
async function block() {
|
async function block() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
loading.blocking = true
|
loading.blocking = true
|
||||||
const blocked = community_view.blocked
|
const blocked = community_view.blocked
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().blockCommunity({
|
await getClient().blockCommunity({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
community_id: community_view.community.id,
|
community_id: community_view.community.id,
|
||||||
block: !blocked,
|
block: !blocked,
|
||||||
})
|
})
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
<FormattedNumber number={community_view.counts.comments} />
|
<FormattedNumber number={community_view.counts.comments} />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{#if $authData}
|
{#if $profile?.jwt}
|
||||||
<div class="w-full mt-2 flex flex-col gap-2">
|
<div class="w-full mt-2 flex flex-col gap-2">
|
||||||
<Button
|
<Button
|
||||||
disabled={loading.subscribing}
|
disabled={loading.subscribing}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let open = false
|
export let open = false
|
||||||
let item: Person | undefined
|
let item: Person | undefined
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
$: if (item) resetReason()
|
$: if (item) resetReason()
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!item || !$user || !community || !$authData) return
|
if (!item || !$profile?.user || !community || !$profile?.jwt) return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
await getClient().banFromCommunity({
|
await getClient().banFromCommunity({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
ban: !banned,
|
ban: !banned,
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: item.id,
|
person_id: item.id,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { authData, getClient, user } from '$lib/lemmy'
|
import { getClient } from '$lib/lemmy'
|
||||||
import type {
|
import type {
|
||||||
CommentView,
|
CommentView,
|
||||||
Community,
|
Community,
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
import { Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
|
import { Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import { isComment } from '$lib/lemmy/item.js'
|
import { isComment } from '$lib/lemmy/item.js'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let item: PostView | CommentView
|
export let item: PostView | CommentView
|
||||||
</script>
|
</script>
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
{item.post.removed ? 'Restore' : 'Remove'}
|
{item.post.removed ? 'Restore' : 'Remove'}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $user && $user.local_user_view.person.id != item.creator.id}
|
{#if $profile.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||||
User
|
User
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { authData, getClient, user } from '$lib/lemmy'
|
import { getClient } from '$lib/lemmy'
|
||||||
import type {
|
import type { CommentView, Community, PostView } from 'lemmy-js-client'
|
||||||
CommentView,
|
|
||||||
Community,
|
|
||||||
CommunityView,
|
|
||||||
PostView,
|
|
||||||
} from 'lemmy-js-client'
|
|
||||||
import { amMod, ban, remove } from './moderation'
|
import { amMod, ban, remove } from './moderation'
|
||||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
@@ -21,6 +16,7 @@
|
|||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let item: PostView | CommentView
|
export let item: PostView | CommentView
|
||||||
|
|
||||||
@@ -30,12 +26,12 @@
|
|||||||
$: acting = locking || pinning
|
$: acting = locking || pinning
|
||||||
|
|
||||||
async function lock(lock: boolean) {
|
async function lock(lock: boolean) {
|
||||||
if (!$authData || !isPost(item)) return
|
if (!$profile?.jwt || !isPost(item)) return
|
||||||
locking = true
|
locking = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().lockPost({
|
await getClient().lockPost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
locked: lock,
|
locked: lock,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
})
|
})
|
||||||
@@ -59,14 +55,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function pin(pinned: boolean) {
|
async function pin(pinned: boolean) {
|
||||||
if (!$authData || !isPost(item)) return
|
if (!$profile?.jwt || !isPost(item)) return
|
||||||
|
|
||||||
pinning = true
|
pinning = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().featurePost({
|
await getClient().featurePost({
|
||||||
feature_type: 'Community',
|
feature_type: 'Community',
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
featured: pinned,
|
featured: pinned,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
})
|
})
|
||||||
@@ -149,7 +145,7 @@
|
|||||||
{item.post.removed ? 'Restore' : 'Remove'}
|
{item.post.removed ? 'Restore' : 'Remove'}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $user && $user.local_user_view.person.id != item.creator.id}
|
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
|
||||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||||
User
|
User
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let open: boolean
|
export let open: boolean
|
||||||
export let item: PostView | CommentView | undefined = undefined
|
export let item: PostView | CommentView | undefined = undefined
|
||||||
@@ -23,14 +24,14 @@
|
|||||||
|
|
||||||
async function remove() {
|
async function remove() {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
if (!$authData) throw new Error('Unauthenticated')
|
if (!$profile?.jwt) throw new Error('Unauthenticated')
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isComment(item)) {
|
if (isComment(item)) {
|
||||||
await getClient().removeComment({
|
await getClient().removeComment({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: item.comment.id,
|
comment_id: item.comment.id,
|
||||||
removed: !removed,
|
removed: !removed,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
item.comment.removed = !removed
|
item.comment.removed = !removed
|
||||||
} else if (isPost(item)) {
|
} else if (isPost(item)) {
|
||||||
await getClient().removePost({
|
await getClient().removePost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
removed: !removed,
|
removed: !removed,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let open: boolean
|
export let open: boolean
|
||||||
export let item: PostView | CommentView | undefined = undefined
|
export let item: PostView | CommentView | undefined = undefined
|
||||||
@@ -21,19 +22,19 @@
|
|||||||
let reason = ''
|
let reason = ''
|
||||||
|
|
||||||
async function report() {
|
async function report() {
|
||||||
if (!item || !$authData || reason == '') return
|
if (!item || !$profile?.jwt || reason == '') return
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isComment(item)) {
|
if (isComment(item)) {
|
||||||
await getClient().createCommentReport({
|
await getClient().createCommentReport({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
comment_id: item.comment.id,
|
comment_id: item.comment.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
} else if (isPost(item)) {
|
} else if (isPost(item)) {
|
||||||
await getClient().createPostReport({
|
await getClient().createPostReport({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import PostVote from './PostVote.svelte'
|
import PostVote from './PostVote.svelte'
|
||||||
import { getClient, getInstance } from '$lib/lemmy.js'
|
import { getClient, getInstance } from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
|
||||||
import {
|
import {
|
||||||
Bookmark,
|
Bookmark,
|
||||||
BookmarkSlash,
|
BookmarkSlash,
|
||||||
@@ -22,25 +20,24 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { user, authData } from '$lib/lemmy.js'
|
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { isMutable } from '$lib/components/lemmy/post/helpers.js'
|
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
||||||
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
|
|
||||||
async function deletePost() {
|
async function deletePost() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
const deleted = post.post.deleted
|
const deleted = post.post.deleted
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().deletePost({
|
await getClient().deletePost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
deleted: !deleted,
|
deleted: !deleted,
|
||||||
post_id: post.post.id,
|
post_id: post.post.id,
|
||||||
})
|
})
|
||||||
@@ -58,7 +55,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function save(post: PostView) {
|
async function save(post: PostView) {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
const saved = post.saved
|
const saved = post.saved
|
||||||
|
|
||||||
@@ -66,7 +63,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().savePost({
|
await getClient().savePost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
post_id: post.post.id,
|
post_id: post.post.id,
|
||||||
save: !saved,
|
save: !saved,
|
||||||
})
|
})
|
||||||
@@ -117,7 +114,7 @@
|
|||||||
<FormattedNumber number={post.counts.comments} />
|
<FormattedNumber number={post.counts.comments} />
|
||||||
</Button>
|
</Button>
|
||||||
<div class="ml-auto" />
|
<div class="ml-auto" />
|
||||||
{#if $user && amMod($user, post.community)}
|
{#if $profile?.user && amMod($profile.user, post.community)}
|
||||||
<ModerationMenu item={post} community={post.community} />
|
<ModerationMenu item={post} community={post.community} />
|
||||||
{/if}
|
{/if}
|
||||||
<Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen>
|
<Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen>
|
||||||
@@ -148,7 +145,7 @@
|
|||||||
</MenuButton>
|
</MenuButton>
|
||||||
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
||||||
<li class="mx-4 text-xs opacity-80 text-left my-1 py-1">Actions</li>
|
<li class="mx-4 text-xs opacity-80 text-left my-1 py-1">Actions</li>
|
||||||
{#if $user && $user.local_user_view.person.id == post.creator.id}
|
{#if $profile?.user && $profile.user.local_user_view.person.id == post.creator.id}
|
||||||
<MenuButton on:click={() => (editing = true)}>
|
<MenuButton on:click={() => (editing = true)}>
|
||||||
<Icon src={PencilSquare} width={16} mini />
|
<Icon src={PencilSquare} width={16} mini />
|
||||||
Edit
|
Edit
|
||||||
@@ -164,18 +161,18 @@
|
|||||||
<Icon src={Square2Stack} width={16} mini />
|
<Icon src={Square2Stack} width={16} mini />
|
||||||
Copy Link
|
Copy Link
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $authData?.token}
|
{#if $profile?.jwt}
|
||||||
<MenuButton on:click={() => save(post)}>
|
<MenuButton on:click={() => save(post)}>
|
||||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
|
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
|
||||||
{post.saved ? 'Unsave' : 'Save'}
|
{post.saved ? 'Unsave' : 'Save'}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $user && post.creator.id == $user.local_user_view.person.id}
|
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
||||||
<MenuButton on:click={deletePost} color="dangerSecondary">
|
<MenuButton on:click={deletePost} color="dangerSecondary">
|
||||||
<Icon src={Trash} width={16} mini />
|
<Icon src={Trash} width={16} mini />
|
||||||
{post.post.deleted ? 'Restore' : 'Delete'}
|
{post.post.deleted ? 'Restore' : 'Delete'}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $user?.local_user_view.person.id != post.creator.id}
|
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
||||||
<MenuButton on:click={() => report(post)} color="dangerSecondary">
|
<MenuButton on:click={() => report(post)} color="dangerSecondary">
|
||||||
<Icon src={Flag} width={16} mini />
|
<Icon src={Flag} width={16} mini />
|
||||||
Report
|
Report
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher, onMount } from 'svelte'
|
import { createEventDispatcher, onMount } from 'svelte'
|
||||||
import { getClient, authData, uploadImage } from '$lib/lemmy.js'
|
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import SelectMenu from '$lib/components/input/SelectMenu.svelte'
|
|
||||||
import Dots from '$lib/components/ui/loader/Dots.svelte'
|
|
||||||
import FileInput from '$lib/components/input/FileInput.svelte'
|
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { goto } from '$app/navigation'
|
|
||||||
import SearchInput from '$lib/components/input/SearchInput.svelte'
|
import SearchInput from '$lib/components/input/SearchInput.svelte'
|
||||||
import { Check, Icon } from 'svelte-hero-icons'
|
import { Check, Icon } from 'svelte-hero-icons'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let edit = false
|
export let edit = false
|
||||||
|
|
||||||
@@ -67,7 +65,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const list = await getClient().listCommunities({
|
const list = await getClient().listCommunities({
|
||||||
auth: $authData?.token,
|
auth: $profile?.jwt,
|
||||||
type_: 'Subscribed',
|
type_: 'Subscribed',
|
||||||
sort: 'Active',
|
sort: 'Active',
|
||||||
limit: 40,
|
limit: 40,
|
||||||
@@ -84,7 +82,7 @@
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!data.title || !$authData) return
|
if (!data.title || !$profile?.jwt) return
|
||||||
|
|
||||||
data.loading = true
|
data.loading = true
|
||||||
|
|
||||||
@@ -95,7 +93,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const post = await getClient().editPost({
|
const post = await getClient().editPost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
url: data.url || undefined,
|
url: data.url || undefined,
|
||||||
@@ -111,7 +109,7 @@
|
|||||||
let image = data.image ? await uploadImage(data.image[0]) : undefined
|
let image = data.image ? await uploadImage(data.image[0]) : undefined
|
||||||
data.url = image || data.url || undefined
|
data.url = image || data.url || undefined
|
||||||
const post = await getClient().createPost({
|
const post = await getClient().createPost({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
community_id: data.community!,
|
community_id: data.community!,
|
||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
@@ -158,7 +156,7 @@
|
|||||||
on:search={async () => {
|
on:search={async () => {
|
||||||
const results = await getClient().search({
|
const results = await getClient().search({
|
||||||
q: communitySearch,
|
q: communitySearch,
|
||||||
auth: $authData?.token,
|
auth: $profile?.jwt,
|
||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
limit: 20,
|
limit: 20,
|
||||||
listing_type: 'Subscribed',
|
listing_type: 'Subscribed',
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { authData, getClient } from '$lib/lemmy'
|
import { getClient } from '$lib/lemmy'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let post: Post
|
export let post: Post
|
||||||
export let vote: number = 0
|
export let vote: number = 0
|
||||||
export let score: number
|
export let score: number
|
||||||
|
|
||||||
async function upvote() {
|
async function upvote() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
if (vote == undefined) vote = 0
|
if (vote == undefined) vote = 0
|
||||||
|
|
||||||
@@ -31,14 +32,14 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likePost({
|
.likePost({
|
||||||
score: upvoted ? 0 : 1,
|
score: upvoted ? 0 : 1,
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downvote() {
|
async function downvote() {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
if (vote == undefined) vote = 0
|
if (vote == undefined) vote = 0
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likePost({
|
.likePost({
|
||||||
score: upvoted ? 0 : -1,
|
score: upvoted ? 0 : -1,
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
|
|||||||
@@ -9,13 +9,7 @@
|
|||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import {
|
import { LINKED_INSTANCE_URL, instance, site } from '$lib/lemmy.js'
|
||||||
LINKED_INSTANCE_URL,
|
|
||||||
authData,
|
|
||||||
instance,
|
|
||||||
site,
|
|
||||||
user,
|
|
||||||
} from '$lib/lemmy.js'
|
|
||||||
import {
|
import {
|
||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
@@ -87,7 +81,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row gap-2 py-2 px-2">
|
<div class="flex flex-row gap-2 py-2 px-2">
|
||||||
{#if $user && amModOfAny($user)}
|
{#if amModOfAny($profile?.user)}
|
||||||
<Button
|
<Button
|
||||||
href="/moderation"
|
href="/moderation"
|
||||||
label="Search"
|
label="Search"
|
||||||
@@ -95,7 +89,7 @@
|
|||||||
dark:text-zinc-300 text-slate-700 hover:text-inherit
|
dark:text-zinc-300 text-slate-700 hover:text-inherit
|
||||||
hover:bg-slate-200 hover:dark:bg-zinc-900 relative"
|
hover:bg-slate-200 hover:dark:bg-zinc-900 relative"
|
||||||
>
|
>
|
||||||
{#if $user.reports ?? 0 > 0}
|
{#if $profile?.user?.reports ?? 0 > 0}
|
||||||
<div
|
<div
|
||||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||||
/>
|
/>
|
||||||
@@ -134,11 +128,15 @@
|
|||||||
<span class="hidden md:inline">Create</span>
|
<span class="hidden md:inline">Create</span>
|
||||||
</Button>
|
</Button>
|
||||||
<li class="text-xs opacity-80 text-left mx-4 my-1 py-1">Create</li>
|
<li class="text-xs opacity-80 text-left mx-4 my-1 py-1">Create</li>
|
||||||
<MenuButton link href="/create/post" disabled={$authData == undefined}>
|
<MenuButton
|
||||||
|
link
|
||||||
|
href="/create/post"
|
||||||
|
disabled={$profile?.jwt == undefined}
|
||||||
|
>
|
||||||
<Icon src={PencilSquare} mini width={16} />
|
<Icon src={PencilSquare} mini width={16} />
|
||||||
Post
|
Post
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if !$authData}
|
{#if !$profile?.jwt}
|
||||||
<span class="text-sm mx-4 my-1 py-1">
|
<span class="text-sm mx-4 my-1 py-1">
|
||||||
<Link highlight href="/login">Log in</Link> to create content.
|
<Link highlight href="/login">Log in</Link> to create content.
|
||||||
</span>
|
</span>
|
||||||
@@ -193,22 +191,15 @@
|
|||||||
<Icon src={Bookmark} mini width={16} /> Saved
|
<Icon src={Bookmark} mini width={16} /> Saved
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if !$profile?.user && $profileData.profiles.length == 0}
|
|
||||||
<MenuButton link href="/login">
|
|
||||||
<Icon src={ArrowLeftOnRectangle} mini width={16} />
|
|
||||||
Log in
|
|
||||||
</MenuButton>
|
|
||||||
{:else}
|
|
||||||
<MenuButton link href="/accounts">
|
<MenuButton link href="/accounts">
|
||||||
<Icon src={ArrowLeftOnRectangle} mini width={16} />
|
<Icon src={ArrowLeftOnRectangle} mini width={16} />
|
||||||
Switch account
|
{$profileData.profiles.length == 0 ? 'Log in' : 'Switch accounts'}
|
||||||
<span
|
<span
|
||||||
class="text-xs font-bold bg-slate-100 dark:bg-zinc-700 px-2 py-0.5 rounded-md ml-auto"
|
class="text-xs font-bold bg-slate-100 dark:bg-zinc-700 px-2 py-0.5 rounded-md ml-auto"
|
||||||
>
|
>
|
||||||
{$profileData.profiles.length}
|
{$profileData.profiles.length}
|
||||||
</span>
|
</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
|
||||||
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
||||||
<li class="text-xs px-4 py-1 my-1 opacity-80">App</li>
|
<li class="text-xs px-4 py-1 my-1 opacity-80">App</li>
|
||||||
<MenuButton link href="/settings">
|
<MenuButton link href="/settings">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Button from '../input/Button.svelte'
|
import Button from '../input/Button.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import { user } from '$lib/lemmy.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
let expanded = true
|
let expanded = true
|
||||||
</script>
|
</script>
|
||||||
@@ -50,8 +50,8 @@
|
|||||||
<span class:hidden={!expanded}>Settings</span>
|
<span class:hidden={!expanded}>Settings</span>
|
||||||
</Button>
|
</Button>
|
||||||
<hr class="border-slate-300 dark:border-zinc-800 my-1" />
|
<hr class="border-slate-300 dark:border-zinc-800 my-1" />
|
||||||
{#if $user}
|
{#if $profile?.user}
|
||||||
{#each $user.follows
|
{#each $profile.user.follows
|
||||||
.map((f) => f.community)
|
.map((f) => f.community)
|
||||||
.sort((a, b) => a.title.localeCompare(b.title)) as follow}
|
.sort((a, b) => a.title.localeCompare(b.title)) as follow}
|
||||||
<Button
|
<Button
|
||||||
@@ -60,11 +60,17 @@
|
|||||||
alignment="left"
|
alignment="left"
|
||||||
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
|
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
|
||||||
>
|
>
|
||||||
<Avatar url={follow.icon} alt={follow.name} title={follow.title} width={20} slot="icon" />
|
<Avatar
|
||||||
|
url={follow.icon}
|
||||||
|
alt={follow.name}
|
||||||
|
title={follow.title}
|
||||||
|
width={20}
|
||||||
|
slot="icon"
|
||||||
|
/>
|
||||||
<span class:hidden={!expanded}>{follow.title}</span>
|
<span class:hidden={!expanded}>{follow.title}</span>
|
||||||
</Button>
|
</Button>
|
||||||
{/each}
|
{/each}
|
||||||
{#if $user.follows.length == 0}
|
{#if $profile.user.follows.length == 0}
|
||||||
<Button
|
<Button
|
||||||
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
|
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
|
||||||
href="/communities"
|
href="/communities"
|
||||||
|
|||||||
+4
-88
@@ -5,10 +5,8 @@ import {
|
|||||||
type PersonView,
|
type PersonView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
|
||||||
import { userSettings } from '$lib/settings.js'
|
|
||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL
|
export const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL
|
||||||
export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml'
|
export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml'
|
||||||
@@ -24,21 +22,6 @@ export function getClient(instanceURL?: string): LemmyHttp {
|
|||||||
|
|
||||||
export const getInstance = () => get(instance)
|
export const getInstance = () => get(instance)
|
||||||
|
|
||||||
export interface AuthData {
|
|
||||||
token: string
|
|
||||||
username: string
|
|
||||||
instance: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UserData {
|
|
||||||
unreads: number
|
|
||||||
reports?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export const authData = writable<AuthData | undefined>()
|
|
||||||
export const user = writable<(MyUserInfo & UserData) | undefined | null>(
|
|
||||||
undefined
|
|
||||||
)
|
|
||||||
export const site = writable<GetSiteResponse | undefined>(undefined)
|
export const site = writable<GetSiteResponse | undefined>(undefined)
|
||||||
|
|
||||||
if (LINKED_INSTANCE_URL) {
|
if (LINKED_INSTANCE_URL) {
|
||||||
@@ -47,73 +30,6 @@ if (LINKED_INSTANCE_URL) {
|
|||||||
.then((s) => site.set(s))
|
.then((s) => site.set(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(async () => {
|
|
||||||
// check for unread messages
|
|
||||||
if (!get(authData) || !get(user)) return
|
|
||||||
|
|
||||||
const response = await getClient().getUnreadCount({
|
|
||||||
auth: get(authData)!.token,
|
|
||||||
})
|
|
||||||
|
|
||||||
const u = get(user)
|
|
||||||
if (!u) return
|
|
||||||
u.unreads = response.mentions + response.private_messages + response.replies
|
|
||||||
|
|
||||||
if (amModOfAny(u)) {
|
|
||||||
const reports = await getClient().getReportCount({
|
|
||||||
auth: get(authData)!.token,
|
|
||||||
})
|
|
||||||
|
|
||||||
u.reports =
|
|
||||||
reports.comment_reports +
|
|
||||||
reports.post_reports +
|
|
||||||
(reports.private_message_reports ?? 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
user.set(u)
|
|
||||||
}, 30 * 1000)
|
|
||||||
|
|
||||||
if (typeof localStorage != 'undefined') {
|
|
||||||
if (localStorage.getItem('user')) {
|
|
||||||
try {
|
|
||||||
authData.set(JSON.parse(localStorage.getItem('user') ?? ''))
|
|
||||||
} catch (error) {
|
|
||||||
// keep authdata until we can verify that the user is infact invalid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
authData.subscribe(async (data) => {
|
|
||||||
instance.set(
|
|
||||||
data?.instance ?? get(userSettings).instance ?? DEFAULT_INSTANCE_URL
|
|
||||||
)
|
|
||||||
if (!data?.token) {
|
|
||||||
user.set(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const site = await getClient().getSite({
|
|
||||||
auth: data.token,
|
|
||||||
})
|
|
||||||
if (!site?.my_user) {
|
|
||||||
user.set(null)
|
|
||||||
throw Error('Missing user')
|
|
||||||
}
|
|
||||||
user.set({ ...site.my_user, unreads: 0 })
|
|
||||||
if (typeof localStorage != 'undefined') {
|
|
||||||
localStorage.setItem('user', JSON.stringify(data))
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
toast({
|
|
||||||
content: 'Failed to fetch your user. Is your instance down?',
|
|
||||||
type: ToastType.error,
|
|
||||||
})
|
|
||||||
console.error(error)
|
|
||||||
authData.set(undefined)
|
|
||||||
user.set(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export async function validateInstance(instance: string): Promise<boolean> {
|
export async function validateInstance(instance: string): Promise<boolean> {
|
||||||
if (instance == '') return false
|
if (instance == '') return false
|
||||||
|
|
||||||
@@ -129,7 +45,7 @@ export async function validateInstance(instance: string): Promise<boolean> {
|
|||||||
export async function uploadImage(
|
export async function uploadImage(
|
||||||
image: File | null | undefined
|
image: File | null | undefined
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
if (!image || !get(authData)) return
|
if (!image || !get(profile)?.jwt) return
|
||||||
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('images[]', image)
|
formData.append('images[]', image)
|
||||||
@@ -138,7 +54,7 @@ export async function uploadImage(
|
|||||||
`${
|
`${
|
||||||
window.location.origin
|
window.location.origin
|
||||||
}/cors/${getInstance()}/pictrs/image?${new URLSearchParams({
|
}/cors/${getInstance()}/pictrs/image?${new URLSearchParams({
|
||||||
auth: get(authData)!.token,
|
auth: get(profile)!.jwt!,
|
||||||
})}`,
|
})}`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -149,7 +65,7 @@ export async function uploadImage(
|
|||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
if (json.msg == 'ok') {
|
if (json.msg == 'ok') {
|
||||||
return `https://${get(authData)?.instance}/pictrs/image/${
|
return `https://${get(profile)?.instance}/pictrs/image/${
|
||||||
json.files?.[0]?.file
|
json.files?.[0]?.file
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { MyUserInfo, PersonView } from 'lemmy-js-client'
|
import type { MyUserInfo, PersonView } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export const blockUser = async (block: boolean, id: number) => {
|
export const blockUser = async (block: boolean, id: number) => {
|
||||||
const auth = get(authData)?.token
|
const auth = get(profile)?.jwt
|
||||||
|
|
||||||
if (!auth) throw new Error('Unauthorized')
|
if (!auth) throw new Error('Unauthorized')
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
import { authData } from '$lib/lemmy.js'
|
|
||||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
>
|
>
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
options={['Subscribed', 'Local', 'All']}
|
options={['Subscribed', 'Local', 'All']}
|
||||||
disabled={[$authData?.token == undefined]}
|
disabled={[$profile?.jwt == undefined]}
|
||||||
selected={data.listingType}
|
selected={data.listingType}
|
||||||
on:select={(e) => {
|
on:select={(e) => {
|
||||||
$page.url.searchParams.set('type', e.detail)
|
$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 { userSettings } from '$lib/settings.js'
|
||||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
const page = Number(url.searchParams.get('page') || 1) || 1
|
const page = Number(url.searchParams.get('page') || 1) || 1
|
||||||
@@ -24,7 +25,7 @@ export async function load({ url }) {
|
|||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
type_: listingType,
|
type_: listingType,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
}),
|
}),
|
||||||
streamed: {
|
streamed: {
|
||||||
site: getClient().getSite({}),
|
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 { userSettings } from '$lib/settings.js'
|
||||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
@@ -18,12 +19,12 @@ export async function load(req: any) {
|
|||||||
community_name: req.params.name,
|
community_name: req.params.name,
|
||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
}),
|
}),
|
||||||
community: (
|
community: (
|
||||||
await getClient().getCommunity({
|
await getClient().getCommunity({
|
||||||
name: req.params.name,
|
name: req.params.name,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
})
|
})
|
||||||
).community_view,
|
).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 type { ListingType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ export async function load({ url }) {
|
|||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
listing_type: type,
|
listing_type: type,
|
||||||
q: query,
|
q: query,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return await getClient().listCommunities({
|
return await getClient().listCommunities({
|
||||||
@@ -23,7 +24,7 @@ export async function load({ url }) {
|
|||||||
page: page,
|
page: page,
|
||||||
sort: 'TopAll',
|
sort: 'TopAll',
|
||||||
type_: type,
|
type_: type,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type {
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
Community,
|
|
||||||
CommunityView,
|
|
||||||
SubscribedType,
|
|
||||||
} from 'lemmy-js-client'
|
|
||||||
import { authData } from '$lib/lemmy.js'
|
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let community: CommunityView
|
export let community: CommunityView
|
||||||
|
|
||||||
let subscribing = false
|
let subscribing = false
|
||||||
|
|
||||||
async function subscribe() {
|
async function subscribe() {
|
||||||
if (!$authData?.token) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
subscribing = true
|
subscribing = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().followCommunity({
|
const res = await getClient().followCommunity({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
community_id: community.community.id,
|
community_id: community.community.id,
|
||||||
follow: community.subscribed == 'NotSubscribed',
|
follow: community.subscribed == 'NotSubscribed',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
||||||
import Card from '$lib/components/ui/Card.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'
|
import { onMount } from 'svelte'
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!$authData) {
|
if (!$profile?.jwt) {
|
||||||
goto('/login')
|
goto('/login')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,19 +2,20 @@
|
|||||||
import InboxItem from './InboxItem.svelte'
|
import InboxItem from './InboxItem.svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { Check, EnvelopeOpen, Icon } from 'svelte-hero-icons'
|
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 { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { isRead } from '$lib/lemmy/inbox.js'
|
import { isRead } from '$lib/lemmy/inbox.js'
|
||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let markingAsRead = false
|
let markingAsRead = false
|
||||||
|
|
||||||
async function markAllAsRead() {
|
async function markAllAsRead() {
|
||||||
if (!$user) {
|
if (!$profile?.user) {
|
||||||
goto('/login')
|
goto('/login')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -22,10 +23,10 @@
|
|||||||
markingAsRead = true
|
markingAsRead = true
|
||||||
|
|
||||||
const response = await getClient().markAllAsRead({
|
const response = await getClient().markAllAsRead({
|
||||||
auth: $authData!.token,
|
auth: $profile.jwt!,
|
||||||
})
|
})
|
||||||
|
|
||||||
$user!.unreads = 0
|
$profile.user.unreads = 0
|
||||||
|
|
||||||
goto($page.url, {
|
goto($page.url, {
|
||||||
invalidateAll: true,
|
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 { getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
const auth = get(authData)
|
const auth = get(profile)
|
||||||
if (!auth) return
|
if (!auth?.jwt) return
|
||||||
|
|
||||||
const type: InboxFeedType =
|
const type: InboxFeedType =
|
||||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||||
@@ -18,7 +19,7 @@ export async function load({ url }) {
|
|||||||
const params = {
|
const params = {
|
||||||
limit: 50,
|
limit: 50,
|
||||||
page: page,
|
page: page,
|
||||||
auth: auth.token,
|
auth: auth.jwt,
|
||||||
unread_only: unreadOnly,
|
unread_only: unreadOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
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 TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import type {
|
import type {
|
||||||
CommentReplyView,
|
CommentReplyView,
|
||||||
PersonMentionView,
|
PersonMentionView,
|
||||||
@@ -34,13 +33,13 @@
|
|||||||
async function replyToMessage(
|
async function replyToMessage(
|
||||||
message: PrivateMessageView | CommentReplyView | PersonMentionView
|
message: PrivateMessageView | CommentReplyView | PersonMentionView
|
||||||
) {
|
) {
|
||||||
if (!$authData) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().createPrivateMessage({
|
await getClient().createPrivateMessage({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
content: reply,
|
content: reply,
|
||||||
recipient_id: message.creator.id,
|
recipient_id: message.creator.id,
|
||||||
})
|
})
|
||||||
@@ -105,7 +104,7 @@
|
|||||||
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
|
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
|
||||||
>
|
>
|
||||||
<span class="font-bold flex items-center">
|
<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
|
You
|
||||||
{:else}
|
{:else}
|
||||||
<UserLink avatar user={item.creator} />
|
<UserLink avatar user={item.creator} />
|
||||||
@@ -113,7 +112,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<span>messaged</span>
|
<span>messaged</span>
|
||||||
<span class="font-bold flex items-center">
|
<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
|
You
|
||||||
{:else}
|
{:else}
|
||||||
<UserLink avatar user={item.recipient} />
|
<UserLink avatar user={item.recipient} />
|
||||||
@@ -124,7 +123,7 @@
|
|||||||
<p class="text-sm py-2">
|
<p class="text-sm py-2">
|
||||||
<Markdown source={item.private_message.content} />
|
<Markdown source={item.private_message.content} />
|
||||||
</p>
|
</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">
|
<div class="flex flex-row gap-2">
|
||||||
<Button color="ghost" on:click={() => (replying = !replying)}>
|
<Button color="ghost" on:click={() => (replying = !replying)}>
|
||||||
<Icon mini src={ChatBubbleOvalLeft} width={16} />
|
<Icon mini src={ChatBubbleOvalLeft} width={16} />
|
||||||
|
|||||||
@@ -12,9 +12,7 @@
|
|||||||
import {
|
import {
|
||||||
DEFAULT_INSTANCE_URL,
|
DEFAULT_INSTANCE_URL,
|
||||||
LINKED_INSTANCE_URL,
|
LINKED_INSTANCE_URL,
|
||||||
authData,
|
|
||||||
getClient,
|
getClient,
|
||||||
user,
|
|
||||||
validateInstance,
|
validateInstance,
|
||||||
} from '$lib/lemmy.js'
|
} from '$lib/lemmy.js'
|
||||||
|
|
||||||
@@ -53,7 +51,6 @@
|
|||||||
content: error as any,
|
content: error as any,
|
||||||
type: ToastType.error,
|
type: ToastType.error,
|
||||||
})
|
})
|
||||||
user.set(null)
|
|
||||||
}
|
}
|
||||||
data.loading = false
|
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 { getItemPublished } from '$lib/lemmy/item.js'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
@@ -12,11 +13,11 @@ export async function load({ url }) {
|
|||||||
const filter: ReportFilter =
|
const filter: ReportFilter =
|
||||||
(url.searchParams.get('filter') as ReportFilter) || 'all'
|
(url.searchParams.get('filter') as ReportFilter) || 'all'
|
||||||
|
|
||||||
const jwt = get(authData)?.token
|
const jwt = get(profile)?.jwt
|
||||||
|
|
||||||
if (!jwt) return { type: type, page: page }
|
if (!jwt) return { type: type, page: page }
|
||||||
|
|
||||||
// can they like
|
// can they please
|
||||||
// make a sane, consistent, and simple API for once
|
// make a sane, consistent, and simple API for once
|
||||||
// 3 separate requests? really?
|
// 3 separate requests? really?
|
||||||
// and this time instead of get() it's list(). Why?!
|
// and this time instead of get() it's list(). Why?!
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
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 { isCommentReport, isPostReport } from '$lib/lemmy/item.js'
|
||||||
import type {
|
import type {
|
||||||
CommentReportView,
|
CommentReportView,
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
PrivateMessageReportView,
|
PrivateMessageReportView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { Check, Icon } from 'svelte-hero-icons'
|
import { Check, Icon } from 'svelte-hero-icons'
|
||||||
import { get } from 'svelte/store'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let item: PostReportView | CommentReportView | PrivateMessageReportView
|
export let item: PostReportView | CommentReportView | PrivateMessageReportView
|
||||||
|
|
||||||
@@ -23,13 +23,13 @@
|
|||||||
|
|
||||||
let resolving = false
|
let resolving = false
|
||||||
async function resolve() {
|
async function resolve() {
|
||||||
if (!$authData || !$user) return
|
if (!$profile?.jwt || !$profile.user) return
|
||||||
resolving = true
|
resolving = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isCommentReport(item)) {
|
if (isCommentReport(item)) {
|
||||||
await getClient().resolveCommentReport({
|
await getClient().resolveCommentReport({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
report_id: item.comment_report.id,
|
report_id: item.comment_report.id,
|
||||||
resolved: !resolved,
|
resolved: !resolved,
|
||||||
})
|
})
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
})
|
})
|
||||||
} else if (isPostReport(item)) {
|
} else if (isPostReport(item)) {
|
||||||
await getClient().resolvePostReport({
|
await getClient().resolvePostReport({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
report_id: item.post_report.id,
|
report_id: item.post_report.id,
|
||||||
resolved: !resolved,
|
resolved: !resolved,
|
||||||
})
|
})
|
||||||
@@ -55,10 +55,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const reports = await getClient().getReportCount({
|
const reports = await getClient().getReportCount({
|
||||||
auth: get(authData)!.token,
|
auth: $profile?.jwt,
|
||||||
})
|
})
|
||||||
|
|
||||||
$user.reports =
|
$profile.user.reports =
|
||||||
reports.comment_reports +
|
reports.comment_reports +
|
||||||
reports.post_reports +
|
reports.post_reports +
|
||||||
(reports.private_message_reports ?? 0)
|
(reports.private_message_reports ?? 0)
|
||||||
|
|||||||
@@ -4,26 +4,15 @@
|
|||||||
buildCommentsTreeAsync,
|
buildCommentsTreeAsync,
|
||||||
} from '$lib/components/lemmy/comment/comments.js'
|
} from '$lib/components/lemmy/comment/comments.js'
|
||||||
import Comments from '$lib/components/lemmy/comment/Comments.svelte'
|
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 { 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 CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
|
||||||
import Markdown from '$lib/components/markdown/Markdown.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 Button from '$lib/components/input/Button.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||||
import Badge from '$lib/components/ui/Badge.svelte'
|
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||||
import {
|
|
||||||
Bookmark,
|
|
||||||
ExclamationTriangle,
|
|
||||||
Icon,
|
|
||||||
InformationCircle,
|
|
||||||
Trash,
|
|
||||||
} from 'svelte-hero-icons'
|
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
@@ -32,6 +21,7 @@
|
|||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import type { CommentSortType } from 'lemmy-js-client'
|
import type { CommentSortType } from 'lemmy-js-client'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -39,9 +29,9 @@
|
|||||||
const post = postData.post
|
const post = postData.post
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (!postData.read && $authData) {
|
if (!postData.read && $profile?.jwt) {
|
||||||
getClient().markPostAsRead({
|
getClient().markPostAsRead({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
read: true,
|
read: true,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
})
|
})
|
||||||
@@ -58,7 +48,7 @@
|
|||||||
commentsPage = 1
|
commentsPage = 1
|
||||||
|
|
||||||
data.streamed.comments = getClient().getComments({
|
data.streamed.comments = getClient().getComments({
|
||||||
auth: $authData?.token,
|
auth: $profile?.jwt,
|
||||||
max_depth: 3,
|
max_depth: 3,
|
||||||
page: commentsPage,
|
page: commentsPage,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
@@ -82,7 +72,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<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">
|
<Card cardColor="warning" class="p-4 flex flex-col gap-1">
|
||||||
<Icon
|
<Icon
|
||||||
src={ExclamationTriangle}
|
src={ExclamationTriangle}
|
||||||
@@ -183,7 +173,7 @@
|
|||||||
<Spinner width={24} />
|
<Spinner width={24} />
|
||||||
</div>
|
</div>
|
||||||
{:then comments}
|
{:then comments}
|
||||||
{#if $user}
|
{#if $profile?.user}
|
||||||
<CommentForm
|
<CommentForm
|
||||||
postId={post.id}
|
postId={post.id}
|
||||||
on:comment={(comment) =>
|
on:comment={(comment) =>
|
||||||
@@ -211,7 +201,7 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
const loadedComments = await getClient().getComments({
|
const loadedComments = await getClient().getComments({
|
||||||
auth: $authData?.token,
|
auth: $profile?.jwt,
|
||||||
max_depth: 3,
|
max_depth: 3,
|
||||||
page: ++commentsPage,
|
page: ++commentsPage,
|
||||||
limit: 25,
|
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'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ params, url }) {
|
export async function load({ params, url }) {
|
||||||
const post = await getClient(params.instance.toLowerCase()).getPost({
|
const post = await getClient(params.instance.toLowerCase()).getPost({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
})
|
})
|
||||||
|
|
||||||
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
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,
|
max_depth: max_depth,
|
||||||
saved_only: false,
|
saved_only: false,
|
||||||
sort: 'Hot',
|
sort: 'Hot',
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
parent_id: parentId,
|
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 type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
if (!get(authData)) return { posts: [] }
|
if (!get(profile)) return { posts: [] }
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
@@ -19,7 +20,7 @@ export async function load({ url }) {
|
|||||||
const [posts, comments] = await Promise.all([
|
const [posts, comments] = await Promise.all([
|
||||||
client.getPosts({
|
client.getPosts({
|
||||||
saved_only: true,
|
saved_only: true,
|
||||||
auth: get(authData)!.token,
|
auth: get(profile)!.jwt,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
sort: 'New',
|
sort: 'New',
|
||||||
@@ -27,7 +28,7 @@ export async function load({ url }) {
|
|||||||
|
|
||||||
client.getComments({
|
client.getComments({
|
||||||
saved_only: true,
|
saved_only: true,
|
||||||
auth: get(authData)!.token,
|
auth: get(profile)!.jwt,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
sort: 'New',
|
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 { getItemPublished } from '$lib/lemmy/item.js'
|
||||||
import type {
|
import type {
|
||||||
CommentView,
|
CommentView,
|
||||||
@@ -21,7 +22,7 @@ export async function load({ url }) {
|
|||||||
if (query) {
|
if (query) {
|
||||||
const results = await getClient().search({
|
const results = await getClient().search({
|
||||||
q: query,
|
q: query,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
community_name: community ?? undefined,
|
community_name: community ?? undefined,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
import { userSettings } from '$lib/settings'
|
import { userSettings } from '$lib/settings'
|
||||||
import {
|
import {
|
||||||
LINKED_INSTANCE_URL,
|
LINKED_INSTANCE_URL,
|
||||||
authData,
|
|
||||||
instance,
|
instance,
|
||||||
user,
|
|
||||||
validateInstance,
|
validateInstance,
|
||||||
} from '$lib/lemmy.js'
|
} from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
@@ -17,34 +15,8 @@
|
|||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
newInstance: $instance,
|
|
||||||
loading: false,
|
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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -54,31 +26,6 @@
|
|||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<h1 class="text-3xl font-bold">Settings</h1>
|
<h1 class="text-3xl font-bold">Settings</h1>
|
||||||
<h2 class="uppercase font-bold opacity-80 text-sm mt-4">General</h2>
|
<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>
|
<Setting>
|
||||||
<span slot="title">Default sort</span>
|
<span slot="title">Default sort</span>
|
||||||
<span slot="description">The default sort to use for feeds.</span>
|
<span slot="description">The default sort to use for feeds.</span>
|
||||||
|
|||||||
@@ -19,34 +19,37 @@
|
|||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { isComment } from '$lib/lemmy/item.js'
|
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 { isBlocked } from '$lib/lemmy/user.js'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let blocking = false
|
let blocking = false
|
||||||
|
|
||||||
async function blockUser(block: number) {
|
async function blockUser(block: number) {
|
||||||
if (!$user || !$authData) throw new Error('Unauthenticated')
|
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
||||||
|
|
||||||
blocking = true
|
blocking = true
|
||||||
try {
|
try {
|
||||||
const blocked = isBlocked($user, block)
|
const blocked = isBlocked($profile.user, block)
|
||||||
|
|
||||||
await getClient().blockPerson({
|
await getClient().blockPerson({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
block: !blocked,
|
block: !blocked,
|
||||||
person_id: block,
|
person_id: block,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (blocked) {
|
if (blocked) {
|
||||||
const index = $user.person_blocks.map((p) => p.target.id).indexOf(block)
|
const index = $profile.user.person_blocks
|
||||||
$user.person_blocks.splice(index, 1)
|
.map((p) => p.target.id)
|
||||||
|
.indexOf(block)
|
||||||
|
$profile.user.person_blocks.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -71,13 +74,13 @@
|
|||||||
let message = ''
|
let message = ''
|
||||||
|
|
||||||
async function sendMessage() {
|
async function sendMessage() {
|
||||||
if (!$authData || message == '') return
|
if (!$profile?.jwt || message == '') return
|
||||||
|
|
||||||
loadingMessage = true
|
loadingMessage = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().createPrivateMessage({
|
await getClient().createPrivateMessage({
|
||||||
auth: $authData.token,
|
auth: $profile.jwt,
|
||||||
content: message,
|
content: message,
|
||||||
recipient_id: data.person_view.person.id,
|
recipient_id: data.person_view.person.id,
|
||||||
})
|
})
|
||||||
@@ -103,7 +106,7 @@
|
|||||||
<title>{data.person_view.person.name}</title>
|
<title>{data.person_view.person.name}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if $authData}
|
{#if $profile?.user}
|
||||||
<Modal bind:open={messaging}>
|
<Modal bind:open={messaging}>
|
||||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
||||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
||||||
@@ -198,7 +201,7 @@
|
|||||||
<FormattedNumber number={data.person_view.counts.comment_count} />
|
<FormattedNumber number={data.person_view.counts.comment_count} />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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">
|
<div class="flex flex-col gap-2">
|
||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="lg"
|
||||||
@@ -216,7 +219,9 @@
|
|||||||
on:click={() => blockUser(data.person_view.person.id)}
|
on:click={() => blockUser(data.person_view.person.id)}
|
||||||
>
|
>
|
||||||
<Icon slot="icon" mini size="16" src={NoSymbol} />
|
<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>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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 { getItemPublished } from '$lib/lemmy/item.js'
|
||||||
import type { SortType } from 'lemmy-js-client'
|
import type { SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
@@ -14,7 +15,7 @@ export async function load({ params, url }) {
|
|||||||
page: page,
|
page: page,
|
||||||
username: params.name,
|
username: params.name,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(authData)?.token,
|
auth: get(profile)?.jwt,
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = [...user.posts, ...user.comments]
|
const items = [...user.posts, ...user.comments]
|
||||||
|
|||||||
Reference in new issue
Block a user