feat: Add menu origin classes
This commit is contained in:
1 parent
ad0023260d
commit
8eef99cc18
8 files changed
+238
-48
No files matched your search
@@ -0,0 +1,59 @@
|
||||
<script lang="ts">
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import InboxItem from '../inbox/InboxItem.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import Post from '$lib/components/lemmy/Post.svelte'
|
||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
const isComment = (item: CommentView | PostView) => 'comment' in item
|
||||
|
||||
// can't do type conversions in the template, so i have to do this
|
||||
const asPost = (item: any) => item as PostView
|
||||
const asComment = (item: any) => item as CommentView
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Saved posts</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1 class="text-xl font-bold">Saved Posts</h1>
|
||||
<div class="flex flex-col gap-4 list-none my-4">
|
||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||
<p class="text-center opacity-60 text-lg mx-4">
|
||||
Wow, it's quite empty in here.
|
||||
</p>
|
||||
{:else}
|
||||
{#each data.data as item}
|
||||
{#if isComment(item)}
|
||||
<Card class="flex flex-col bg-white rounded-md p-4 flex-1">
|
||||
<div class="flex flex-row justify-between items-center">
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-xs dark:text-slate-400 text-zinc-600">
|
||||
<CommunityLink avatar community={item.community} />
|
||||
</span>
|
||||
<span class="flex flex-row items-center text-sm font-bold">
|
||||
{item.post.name}
|
||||
</span>
|
||||
</div>
|
||||
<Link href="/post/{item.post.id}#{asComment(item).comment.id}">
|
||||
Jump
|
||||
</Link>
|
||||
</div>
|
||||
<div class="list-none">
|
||||
<Comment
|
||||
postId={item.post.id}
|
||||
node={{ children: [], comment_view: asComment(item), depth: 1 }}
|
||||
replying={false}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
{:else}
|
||||
<Post post={asPost(item)} />
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,44 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
function getSavedItemPublished(item: PostView | CommentView) {
|
||||
if ('comment' in item) {
|
||||
return item.comment.published
|
||||
} else {
|
||||
return item.post.published
|
||||
}
|
||||
}
|
||||
|
||||
export async function load({ url }) {
|
||||
if (!get(authData)) return { posts: [] }
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
const client = getClient()
|
||||
|
||||
const [posts, comments] = await Promise.all([
|
||||
client.getPosts({
|
||||
saved_only: true,
|
||||
auth: get(authData)!.token,
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: 'New',
|
||||
}),
|
||||
|
||||
client.getComments({
|
||||
saved_only: true,
|
||||
auth: get(authData)!.token,
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: 'New',
|
||||
}),
|
||||
])
|
||||
|
||||
const everything = [...posts.posts, ...comments.comments].sort(
|
||||
(a, b) =>
|
||||
Date.parse(getSavedItemPublished(b)) -
|
||||
Date.parse(getSavedItemPublished(a))
|
||||
)
|
||||
|
||||
return { data: everything }
|
||||
}
|
||||
Reference in new issue
Block a user