feat: combine crossposts in feeds
This commit is contained in:
1 parent
aeca64e895
commit
4047b43451
3 files changed
+151
-46
No files matched your search
@@ -1,20 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from "lemmy-js-client"
|
||||||
import { isImage, isVideo } from '$lib/ui/image.js'
|
import { isImage, isVideo } from "$lib/ui/image.js"
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
import { getInstance } from "$lib/lemmy.js"
|
||||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
import PostActions from "$lib/components/lemmy/post/PostActions.svelte"
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from "$lib/settings.js"
|
||||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
import PostLink from "$lib/components/lemmy/post/PostLink.svelte"
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
import PostMeta from "$lib/components/lemmy/post/PostMeta.svelte"
|
||||||
import { Material, toast } from 'mono-svelte'
|
import { Material, toast } from "mono-svelte"
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from "$lib/components/markdown/Markdown.svelte"
|
||||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
import ExpandableImage from "$lib/components/ui/ExpandableImage.svelte"
|
||||||
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
|
import { bestImageURL, postLink } from "$lib/components/lemmy/post/helpers.js"
|
||||||
import Empty from '$lib/components/helper/Empty.svelte'
|
import Empty from "$lib/components/helper/Empty.svelte"
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from "$lib/components/util/date.js"
|
||||||
import { Icon, VideoCamera } from 'svelte-hero-icons'
|
import { Icon, VideoCamera } from "svelte-hero-icons"
|
||||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
import PostMedia from "$lib/components/lemmy/post/media/PostMedia.svelte"
|
||||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
import PostMediaCompact from "$lib/components/lemmy/post/media/PostMediaCompact.svelte"
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
export let actions: boolean = true
|
export let actions: boolean = true
|
||||||
@@ -25,14 +25,14 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Material
|
<Material
|
||||||
color={view != 'card' ? 'none' : 'distinct'}
|
color={view != "card" ? "none" : "distinct"}
|
||||||
padding="none"
|
padding="none"
|
||||||
class="relative max-w-full min-w-0 w-full group
|
class="relative max-w-full min-w-0 w-full group
|
||||||
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
|
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
|
||||||
? 'py-4'
|
? 'py-4'
|
||||||
: view == 'list'
|
: view == 'list'
|
||||||
? 'py-5'
|
? 'py-5'
|
||||||
: 'py-5'}"
|
: 'py-5'} {$$props.class}"
|
||||||
id={post.post.id}
|
id={post.post.id}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -54,8 +54,10 @@
|
|||||||
featured={post.post.featured_local || post.post.featured_community}
|
featured={post.post.featured_local || post.post.featured_community}
|
||||||
nsfw={post.post.nsfw}
|
nsfw={post.post.nsfw}
|
||||||
saved={post.saved}
|
saved={post.saved}
|
||||||
/>
|
>
|
||||||
{#if post.post.embed_title != post.post.name || view == 'compact'}
|
<slot name="badges" slot="badges" />
|
||||||
|
</PostMeta>
|
||||||
|
{#if post.post.embed_title != post.post.name || view == "compact"}
|
||||||
<a
|
<a
|
||||||
href="/post/{getInstance()}/{post.post.id}"
|
href="/post/{getInstance()}/{post.post.id}"
|
||||||
class="font-medium max-w-full w-full break-words text-base"
|
class="font-medium max-w-full w-full break-words text-base"
|
||||||
@@ -68,7 +70,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<PostMedia bind:post={post.post} {view} />
|
<PostMedia bind:post={post.post} {view} />
|
||||||
{#if post.post.body && !post.post.nsfw && view != 'compact'}
|
{#if post.post.body && !post.post.nsfw && view != "compact"}
|
||||||
<div
|
<div
|
||||||
class="text-sm relative overflow-hidden
|
class="text-sm relative overflow-hidden
|
||||||
bg-gradient-to-b text-transparent from-slate-600 via-slate-600
|
bg-gradient-to-b text-transparent from-slate-600 via-slate-600
|
||||||
@@ -79,7 +81,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if view == 'list' || view == 'compact'}
|
{#if view == "list" || view == "compact"}
|
||||||
<PostMediaCompact {view} bind:post={post.post} />
|
<PostMediaCompact {view} bind:post={post.post} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -89,8 +91,8 @@
|
|||||||
bind:post
|
bind:post
|
||||||
on:edit={(e) => {
|
on:edit={(e) => {
|
||||||
toast({
|
toast({
|
||||||
content: 'The post was edited successfully.',
|
content: "The post was edited successfully.",
|
||||||
type: 'success',
|
type: "success",
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,14 +1,61 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from "$lib/components/lemmy/post/Post.svelte"
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from "$lib/components/ui/Placeholder.svelte"
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from "$lib/settings.js"
|
||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from "lemmy-js-client"
|
||||||
import { Button } from 'mono-svelte'
|
import { Badge, Button } from "mono-svelte"
|
||||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
import { ArchiveBox, Icon, Minus, Plus } from "svelte-hero-icons"
|
||||||
import { fly } from 'svelte/transition'
|
import { expoOut } from "svelte/easing"
|
||||||
|
import { fly, slide } from "svelte/transition"
|
||||||
|
|
||||||
|
type PostViewWithCrossposts = PostView & {
|
||||||
|
withCrossposts: true
|
||||||
|
crossposts: PostView[]
|
||||||
|
}
|
||||||
|
type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
|
|
||||||
|
const addCrosspostProperty = (
|
||||||
|
post: PostView,
|
||||||
|
crossposts: PostView[]
|
||||||
|
): PostViewWithCrossposts => ({
|
||||||
|
...post,
|
||||||
|
crossposts: crossposts,
|
||||||
|
withCrossposts: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const combineCrossposts = (
|
||||||
|
posts: PostView[]
|
||||||
|
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
||||||
|
const urlMap = new Map<
|
||||||
|
string,
|
||||||
|
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||||
|
>()
|
||||||
|
|
||||||
|
posts.forEach((post) => {
|
||||||
|
if (!post.post.url) return
|
||||||
|
|
||||||
|
let existing = urlMap.get(post.post.url)
|
||||||
|
if (existing) {
|
||||||
|
existing = addCrosspostProperty(existing, [
|
||||||
|
...(existing.withCrossposts ? existing.crossposts : []),
|
||||||
|
post,
|
||||||
|
])
|
||||||
|
|
||||||
|
urlMap.set(post.post.url, existing)
|
||||||
|
} else {
|
||||||
|
urlMap.set(post.post.url, post)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return Array.from(urlMap.values())
|
||||||
|
}
|
||||||
|
|
||||||
|
$: combinedPosts = combineCrossposts(posts)
|
||||||
|
|
||||||
|
let viewPost: number = -1
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
@@ -30,7 +77,7 @@
|
|||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each posts as post, index}
|
{#each combinedPosts as post, index}
|
||||||
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
||||||
<li
|
<li
|
||||||
in:fly|global={{
|
in:fly|global={{
|
||||||
@@ -39,8 +86,61 @@
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
delay: index < 4 ? index * 100 : 0,
|
delay: index < 4 ? index * 100 : 0,
|
||||||
}}
|
}}
|
||||||
|
class="relative"
|
||||||
>
|
>
|
||||||
<Post hideCommunity={community} view={$userSettings.view} bind:post />
|
<Post
|
||||||
|
hideCommunity={community}
|
||||||
|
view={$userSettings.view}
|
||||||
|
{post}
|
||||||
|
class="transition-all duration-250 {post.withCrossposts &&
|
||||||
|
viewPost != post.post.id
|
||||||
|
? ''
|
||||||
|
: ''}"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
slot="badges"
|
||||||
|
class:hidden={!post.withCrossposts}
|
||||||
|
on:click={() => {
|
||||||
|
if (viewPost == post.post.id) viewPost = -1
|
||||||
|
else viewPost = post.post.id
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{#if post.withCrossposts}
|
||||||
|
<Badge
|
||||||
|
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
|
||||||
|
color="gray-subtle"
|
||||||
|
>
|
||||||
|
{#if viewPost == post.post.id}
|
||||||
|
<Icon mini src={Minus} size="14" />
|
||||||
|
{:else}
|
||||||
|
<Icon mini src={Plus} size="14" />
|
||||||
|
{/if}
|
||||||
|
{post.crossposts.length} crosspost{post.crossposts.length == 1
|
||||||
|
? ""
|
||||||
|
: "s"}
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</Post>
|
||||||
|
{#if post.withCrossposts && viewPost == post.post.id}
|
||||||
|
<div
|
||||||
|
transition:slide|global={{
|
||||||
|
axis: "y",
|
||||||
|
duration: 500,
|
||||||
|
easing: expoOut,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span class="text-sm flex flex-row gap-2 items-center">
|
||||||
|
Crossposts <hr class="w-full dark:border-zinc-800" />
|
||||||
|
{post.crossposts.length}
|
||||||
|
</span>
|
||||||
|
{#each post.crossposts as crosspost, index}
|
||||||
|
<div class="w-full transition-all mb-4">
|
||||||
|
<Post post={crosspost} />
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from "$lib/components/lemmy/community/CommunityLink.svelte"
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from "$lib/components/ui/Avatar.svelte"
|
||||||
import { Badge } from 'mono-svelte'
|
import { Badge } from "mono-svelte"
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from "$lib/components/lemmy/user/UserLink.svelte"
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from "$lib/components/util/RelativeDate.svelte"
|
||||||
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
|
import type { Community, Person, SubscribedType } from "lemmy-js-client"
|
||||||
import {
|
import {
|
||||||
Bookmark,
|
Bookmark,
|
||||||
Check,
|
Check,
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
Megaphone,
|
Megaphone,
|
||||||
Plus,
|
Plus,
|
||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from "svelte-hero-icons"
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
import { getInstance } from "$lib/lemmy.js"
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from "$lib/auth.js"
|
||||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
import Subscribe from "../../../../routes/communities/Subscribe.svelte"
|
||||||
|
|
||||||
export let community: Community | undefined = undefined
|
export let community: Community | undefined = undefined
|
||||||
export let subscribed: SubscribedType | undefined = undefined
|
export let subscribed: SubscribedType | undefined = undefined
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
if (!community) return
|
if (!community) return
|
||||||
await subscribe(community.id, subscribed)
|
await subscribe(community.id, subscribed)
|
||||||
subscribed =
|
subscribed =
|
||||||
subscribed == 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed'
|
subscribed == "NotSubscribed" ? "Subscribed" : "NotSubscribed"
|
||||||
}}
|
}}
|
||||||
class="relative cursor-pointer"
|
class="relative cursor-pointer"
|
||||||
>
|
>
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
-bottom-1.5 -right-1.5 grid place-items-center transition-all"
|
-bottom-1.5 -right-1.5 grid place-items-center transition-all"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
src={subscribed == 'NotSubscribed' ? Plus : Check}
|
src={subscribed == "NotSubscribed" ? Plus : Check}
|
||||||
mini
|
mini
|
||||||
size="12"
|
size="12"
|
||||||
/>
|
/>
|
||||||
@@ -99,7 +99,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-row ml-auto gap-2 flex-wrap">
|
<div
|
||||||
|
class="flex flex-row ml-auto gap-2 flex-shrink overflow-scroll [&>*]:flex-shrink-0"
|
||||||
|
>
|
||||||
{#if nsfw}
|
{#if nsfw}
|
||||||
<Badge color="red-subtle">NSFW</Badge>
|
<Badge color="red-subtle">NSFW</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -133,6 +135,7 @@
|
|||||||
<span class="max-md:hidden">Featured</span>
|
<span class="max-md:hidden">Featured</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
|
<slot name="badges" />
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
{#if title && id}
|
{#if title && id}
|
||||||
|
|||||||
Reference in new issue
Block a user