feat: Add posts to profile pages

This commit is contained in:
Xyphyn committed 2023-07-05 17:21:48 -07:00
1 parent 948ad6fb1c
commit 28d9820b1e
5 files changed
+69 -29

No files matched your search

@@ -14,7 +14,6 @@
PencilSquare,
UserGroup,
} from 'svelte-hero-icons'
import SvelteMarkdown from 'svelte-markdown'
export let community_view: CommunityView
</script>
@@ -26,7 +25,7 @@
`https://api.dicebear.com/6.x/initials/svg?seed=${community_view.community.name}`}
alt={community_view.community.name}
/>
<span class="flex flex-row items-center gap-1 text-sm">
<span class="flex flex-row items-center gap-1 text-sm capitalize">
<Icon src={Calendar} width={16} height={16} mini />
<RelativeDate date={new Date(community_view.community.published)} />
</span>
+1 -1
View File
@@ -46,7 +46,7 @@
}
</script>
<Card class="bg-white flex flex-col overflow-hidden max-w-xl w-full relative">
<Card class="bg-white flex flex-col overflow-hidden w-full relative">
<div class="flex flex-col gap-2 bg-white dark:bg-zinc-900 p-4 rounded-md">
<span class="flex flex-row gap-2 text-xs items-center">
<CommunityLink avatarSize={20} avatar community={postRes.community} />
+3 -3
View File
@@ -27,8 +27,8 @@
<title>Xylemmy</title>
</svelte:head>
<div class="flex flex-row gap-4">
<div class="flex flex-col gap-4 max-w-full">
<div class="flex flex-row gap-4 justify-between">
<div class="flex flex-col gap-4 max-w-full w-full">
<div class="flex flex-col sm:flex-row gap-4 max-w-full">
<MultiSelect
options={['Subscribed', 'Local', 'All']}
@@ -80,7 +80,7 @@
</Button>
</div>
</div>
<div class="ml-auto hidden lg:block max-w-sm w-full">
<div class="hidden lg:block max-w-sm w-full">
{#await data.streamed.site}
<Card>
<div
+2 -2
View File
@@ -23,8 +23,8 @@
</script>
<div class="flex flex-row gap-4 justify-between">
<div class="flex flex-col gap-4 max-w-full">
<div class="flex flex-col sm:flex-row gap-4 max-w-full">
<div class="flex flex-col gap-4 max-w-full w-full">
<div class="flex flex-col sm:flex-row gap-4 max-w-full w-full">
<MultiSelect
options={['Active', 'Hot', 'TopAll', 'New']}
optionNames={['Active', 'Hot', 'Top', 'New']}
+62 -21
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
import Link from '$lib/components/input/Link.svelte'
import Post from '$lib/components/lemmy/Post.svelte'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
@@ -8,7 +9,12 @@
import StickyCard from '$lib/components/ui/StickyCard.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import type { GetPersonDetailsResponse } from 'lemmy-js-client'
import { getClient } from '$lib/lemmy.js'
import type {
CommentView,
GetPersonDetailsResponse,
PostView,
} from 'lemmy-js-client'
import {
Calendar,
ChatBubbleOvalLeftEllipsis,
@@ -19,6 +25,35 @@
export let data: {
user: GetPersonDetailsResponse
}
interface Item {
post: boolean
comment: boolean
item: CommentView & PostView
}
function getDateOfItem(item: Item): number {
if (item.post) {
return Date.parse(item.item.post.published)
} else if (item.comment) {
return Date.parse(item.item.comment.published)
} else {
return Date.now()
}
}
const items: Item[] = [...data.user.comments, ...data.user.posts]
.map((i) => {
const post = 'read' in i
const comment = !post
return {
post: post,
comment: comment,
item: i as CommentView & PostView,
}
})
.sort((a, b) => getDateOfItem(b) - getDateOfItem(a))
</script>
<svelte:head>
@@ -27,27 +62,33 @@
<div class="flex flex-row gap-4 max-w-full">
<div class="flex flex-col gap-4 max-w-full">
{#each data.user.comments as 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>
{#each items as item}
{#if item.post}
<Post post={item.item} />
{:else}
<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.item.community} />
</span>
<span class="flex flex-row items-center text-sm font-bold">
{item.item.post.name}
</span>
</div>
<Link href="/post/{item.item.post.id}#{item.item.comment.id}">
Jump
</Link>
</div>
<Link href="/post/{item.post.id}#{item.comment.id}">Jump</Link>
</div>
<div class="list-none">
<Comment
postId={item.post.id}
node={{ children: [], comment_view: item, depth: 1 }}
replying={false}
/>
</div>
</Card>
<div class="list-none">
<Comment
postId={item.item.post.id}
node={{ children: [], comment_view: item.item, depth: 1 }}
replying={false}
/>
</div>
</Card>
{/if}
{/each}
</div>