fix: unmerged posts/comments in user profiles
This commit is contained in:
4 files changed
+124
-3
No files matched your search
@@ -1,9 +1,14 @@
|
|||||||
|
import { resolveRoute } from '$app/paths'
|
||||||
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { client } from '$lib/lemmy.svelte.js'
|
import { client } from '$lib/lemmy.svelte.js'
|
||||||
import { redirect } from '@sveltejs/kit'
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
export async function load({ params, fetch }) {
|
export async function load({ params, fetch }) {
|
||||||
|
if (profile.data.instance != params.instance)
|
||||||
|
redirect(302, resolveRoute('/post/[instance]/[id]/confirm', params))
|
||||||
|
|
||||||
const comment = await client({
|
const comment = await client({
|
||||||
instanceURL: params.instance,
|
instanceURL: profile.data.instance,
|
||||||
func: fetch,
|
func: fetch,
|
||||||
}).getComment({
|
}).getComment({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
@@ -11,6 +16,6 @@ export async function load({ params, fetch }) {
|
|||||||
|
|
||||||
redirect(
|
redirect(
|
||||||
302,
|
302,
|
||||||
`/post/${params.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
`/post/${profile.data.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { resolveRoute } from '$app/paths'
|
||||||
|
import { page } from '$app/state'
|
||||||
|
import { profile, profileData } from '$lib/auth.svelte'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
|
||||||
|
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||||
|
import { client } from '$lib/lemmy.svelte'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import { t } from '$lib/i18n/translations'
|
||||||
|
import { toast } from 'mono-svelte'
|
||||||
|
import Button from 'mono-svelte/button/Button.svelte'
|
||||||
|
import Material from 'mono-svelte/materials/Material.svelte'
|
||||||
|
import { Plus } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
let loading = $state(false)
|
||||||
|
const fetched = $state.snapshot(profile.data.instance)
|
||||||
|
|
||||||
|
async function fetchOnHome() {
|
||||||
|
loading = true
|
||||||
|
try {
|
||||||
|
const res = await client().resolveObject({
|
||||||
|
q: `https://${page.params.instance}/comment/${page.params.id}`,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.comment) {
|
||||||
|
goto(
|
||||||
|
resolveRoute(`/comment/[instance]/[id]`, {
|
||||||
|
instance: profile.data.instance,
|
||||||
|
id: res.comment.comment.id.toString(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
toast({ content: errorMessage(err), type: 'error' })
|
||||||
|
}
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="w-full h-full flex flex-col justify-center mx-auto max-w-xl gap-6">
|
||||||
|
<header class="space-y-1">
|
||||||
|
<div class="font-mono bg-zinc-950 rounded-xs p-0.5 px-1 w-max">
|
||||||
|
{page.params.instance}/comment/{page.params.id}
|
||||||
|
</div>
|
||||||
|
<Header>
|
||||||
|
{$t('routes.postRedirect.title')}
|
||||||
|
</Header>
|
||||||
|
<p>
|
||||||
|
{$t('routes.postRedirect.description', {
|
||||||
|
// @ts-ignore
|
||||||
|
homeInstance: fetched,
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||||
|
{#if profile.data.jwt}
|
||||||
|
<Button
|
||||||
|
{loading}
|
||||||
|
disabled={loading}
|
||||||
|
size="md"
|
||||||
|
rounding="pill"
|
||||||
|
color="primary"
|
||||||
|
onclick={fetchOnHome}
|
||||||
|
>
|
||||||
|
{$t('routes.postRedirect.actions.fetch', {
|
||||||
|
// @ts-ignore
|
||||||
|
homeInstance: fetched,
|
||||||
|
})}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
<Button size="md" rounding="pill" onclick={() => history.back()}>
|
||||||
|
{$t('routes.postRedirect.actions.back')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{#if profileData.profiles}
|
||||||
|
{@const filtered = profileData.profiles.filter(
|
||||||
|
i => i.instance == page.params.instance,
|
||||||
|
)}
|
||||||
|
<div class="space-y-1">
|
||||||
|
<div class="font-medium text-sm">
|
||||||
|
{$t('routes.postRedirect.actions.switch', {
|
||||||
|
// @ts-ignore
|
||||||
|
destInstance: page.params.instance,
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<Material
|
||||||
|
color="uniform"
|
||||||
|
padding="sm"
|
||||||
|
rounding="2xl"
|
||||||
|
class="dark:bg-zinc-950 max-h-96 overflow-auto"
|
||||||
|
>
|
||||||
|
{#each filtered as profile, index}
|
||||||
|
<ProfileButton prof={profile} {index} />
|
||||||
|
{/each}
|
||||||
|
<SidebarButton
|
||||||
|
href="/accounts/login/guest?redirect={page.url}"
|
||||||
|
icon={Plus}
|
||||||
|
class="rounded-lg"
|
||||||
|
>
|
||||||
|
{$t('account.addGuest')}
|
||||||
|
</SidebarButton>
|
||||||
|
</Material>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
|
export async function load({ params }) {
|
||||||
|
if (profile.data.instance == params.instance)
|
||||||
|
redirect(302, `/comment/${params.instance}/${params.id}`)
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ export async function load({ params, url, fetch }) {
|
|||||||
(url.searchParams.get('type') as 'comments' | 'posts') || 'posts'
|
(url.searchParams.get('type') as 'comments' | 'posts') || 'posts'
|
||||||
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
||||||
|
|
||||||
|
console.log(type)
|
||||||
|
|
||||||
const user = await getClient(undefined, fetch).getPersonDetails({
|
const user = await getClient(undefined, fetch).getPersonDetails({
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
@@ -16,7 +18,7 @@ export async function load({ params, url, fetch }) {
|
|||||||
sort: sort,
|
sort: sort,
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = [...user.posts, ...user.comments]
|
const items = type == 'posts' ? user.posts : user.comments
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filters: new ReactiveState({
|
filters: new ReactiveState({
|
||||||
|
|||||||
Reference in new issue
Block a user