feat: add sorts to user pages
This commit is contained in:
1 parent
d427d4b2fc
commit
c0aaf08a9f
12 files changed
+129
-69
No files matched your search
@@ -79,7 +79,7 @@
|
||||
</Button>
|
||||
<span class="text-xs opacity-80 py-1 my-1 px-4">Comment actions</span>
|
||||
{#if $authData?.token}
|
||||
{#if comment.creator.id == $user?.person.id}
|
||||
{#if comment.creator.id == $user?.local_user_view.person.id}
|
||||
<MenuButton on:click={() => dispatcher('edit', comment)}>
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
<span>Edit</span>
|
||||
@@ -89,7 +89,7 @@
|
||||
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
|
||||
</MenuButton>
|
||||
{#if $user && $authData && isCommentMutable(comment, $user)}
|
||||
{#if $user && $authData && isCommentMutable(comment, $user.local_user_view)}
|
||||
<MenuButton
|
||||
color={Color.dangerSecondary}
|
||||
on:click={async () => {
|
||||
@@ -116,7 +116,7 @@
|
||||
<span>Delete</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $authData && $user?.person.id != comment.creator.id}
|
||||
{#if $authData && $user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton
|
||||
on:click={() => report(comment)}
|
||||
color={Color.dangerSecondary}
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
</MenuButton>
|
||||
<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>
|
||||
{#if $user && $user.person.id == post.creator.id}
|
||||
{#if $user && $user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton on:click={() => (editing = true)}>
|
||||
<Icon src={PencilSquare} width={16} mini />
|
||||
Edit
|
||||
@@ -147,13 +147,13 @@
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
|
||||
{post.saved ? 'Unsave' : 'Save'}
|
||||
</MenuButton>
|
||||
{#if $user && isMutable(post, $user)}
|
||||
{#if $user && isMutable(post, $user.local_user_view)}
|
||||
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||
<Icon src={Trash} width={16} mini />
|
||||
Delete
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $user?.person.id != post.creator.id}
|
||||
{#if $user?.local_user_view.person.id != post.creator.id}
|
||||
<MenuButton on:click={() => report(post)} color={Color.dangerSecondary}>
|
||||
<Icon src={Flag} width={16} mini />
|
||||
Report
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
{/if}
|
||||
{#if $user}
|
||||
<img
|
||||
src={$user.person.avatar ??
|
||||
src={$user.local_user_view.person.avatar ??
|
||||
'https://xylo.xylight.dev/img/logo-background.svg'}
|
||||
alt=""
|
||||
width={32}
|
||||
@@ -113,10 +113,13 @@
|
||||
{/if}
|
||||
</button>
|
||||
<li class="text-xs opacity-80 text-left mx-4 my-1 py-1">
|
||||
{$user ? $user.person.name : 'Profile'}
|
||||
{$user ? $user.local_user_view.person.name : 'Profile'}
|
||||
</li>
|
||||
{#if $user && $authData}
|
||||
<MenuButton link href="/u/{$user.person.name}@{$authData.instance}">
|
||||
<MenuButton
|
||||
link
|
||||
href="/u/{$user.local_user_view.person.name}@{$authData.instance}"
|
||||
>
|
||||
<Icon src={UserCircle} mini width={16} /> Profile
|
||||
</MenuButton>
|
||||
<MenuButton link href="/inbox">
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
import { LemmyHttp, type PersonView } from 'lemmy-js-client'
|
||||
import { LemmyHttp, type MyUserInfo, type PersonView } from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
@@ -42,7 +42,7 @@ export interface UserData {
|
||||
}
|
||||
|
||||
export const authData = writable<AuthData | undefined>()
|
||||
export const user = writable<(PersonView & UserData) | undefined | null>(
|
||||
export const user = writable<(MyUserInfo & UserData) | undefined | null>(
|
||||
undefined
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@ authData.subscribe(async (data) => {
|
||||
user.set(null)
|
||||
throw Error('Missing user')
|
||||
}
|
||||
user.set({ ...site.my_user.local_user_view, unreads: 0 })
|
||||
user.set({ ...site.my_user, unreads: 0 })
|
||||
if (typeof localStorage != 'undefined') {
|
||||
localStorage.setItem('user', JSON.stringify(data))
|
||||
}
|
||||
|
||||
@@ -20,3 +20,21 @@ export function getInboxItemPublished(item: InboxItemView): string {
|
||||
|
||||
return item.person_mention.published
|
||||
}
|
||||
|
||||
export function isRead(
|
||||
item: PersonMentionView | CommentReplyView | PrivateMessageView
|
||||
) {
|
||||
if ('person_mention' in item) {
|
||||
return (item as PersonMentionView).person_mention.read
|
||||
}
|
||||
|
||||
if ('comment_reply' in item) {
|
||||
return (item as CommentReplyView).comment_reply.read
|
||||
}
|
||||
|
||||
if ('private_message' in item) {
|
||||
return (item as PrivateMessageView).private_message.read
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type {
|
||||
CommentView,
|
||||
CommunityView,
|
||||
PersonView,
|
||||
PostView,
|
||||
} from 'lemmy-js-client'
|
||||
|
||||
export function getItemPublished(
|
||||
item: PostView | CommentView | PersonView | CommunityView
|
||||
) {
|
||||
if ('comment' in item) {
|
||||
return item.comment.published
|
||||
} else if ('post' in item) {
|
||||
return item.post.published
|
||||
}
|
||||
|
||||
if ('person' in item) {
|
||||
return item.person.published
|
||||
}
|
||||
|
||||
if ('community' in item) {
|
||||
return item.community.published
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import type { MyUserInfo, PersonView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export const blockUser = async (block: boolean, id: number) => {
|
||||
const auth = get(authData)?.token
|
||||
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
const response = await getClient().blockPerson({
|
||||
auth: auth,
|
||||
block: block,
|
||||
person_id: id,
|
||||
})
|
||||
}
|
||||
|
||||
export const isBlocked = (me: MyUserInfo, user: number) =>
|
||||
me.person_blocks.map((b) => b.target.id).includes(user)
|
||||
Reference in new issue
Block a user