feat: fix and re-add crosspost combining
This commit is contained in:
1 parent
5cce0fb736
commit
177ac09b04
2 files changed
+62
-9
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.21.1",
|
"version": "1.21.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -33,27 +33,34 @@
|
|||||||
string,
|
string,
|
||||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||||
>()
|
>()
|
||||||
|
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
||||||
|
const seenUrls = new Set<string>()
|
||||||
|
|
||||||
posts.forEach((post) => {
|
posts.forEach((post) => {
|
||||||
if (!post.post.url) return
|
if (!post.post.url) {
|
||||||
|
results.push(post)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let existing = urlMap.get(post.post.url)
|
let existing = urlMap.get(post.post.url)
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing = addCrosspostProperty(existing, [
|
existing.withCrossposts = true
|
||||||
...(existing.withCrossposts ? existing.crossposts : []),
|
if (existing.withCrossposts) {
|
||||||
post,
|
existing.crossposts = [...(existing.crossposts || []), post]
|
||||||
])
|
}
|
||||||
|
|
||||||
urlMap.set(post.post.url, existing)
|
urlMap.set(post.post.url, existing)
|
||||||
} else {
|
} else {
|
||||||
urlMap.set(post.post.url, post)
|
urlMap.set(post.post.url, post)
|
||||||
|
results.push(post)
|
||||||
}
|
}
|
||||||
|
seenUrls.add(post.post.url)
|
||||||
})
|
})
|
||||||
|
|
||||||
return Array.from(urlMap.values())
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
$: combinedPosts = posts
|
$: combinedPosts = combineCrossposts(posts)
|
||||||
|
|
||||||
let viewPost: number = -1
|
let viewPost: number = -1
|
||||||
</script>
|
</script>
|
||||||
@@ -77,7 +84,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={{
|
||||||
@@ -97,7 +104,53 @@
|
|||||||
? ''
|
? ''
|
||||||
: ''}"
|
: ''}"
|
||||||
>
|
>
|
||||||
|
<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>
|
</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"
|
||||||
|
class:my-4={$userSettings.view == 'card'}
|
||||||
|
>
|
||||||
|
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} view={$userSettings.view} />
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
Reference in new issue
Block a user