diff --git a/src/lib/app/i18n/en.json b/src/lib/app/i18n/en.json index 0b9dba3a..5ef2c16a 100644 --- a/src/lib/app/i18n/en.json +++ b/src/lib/app/i18n/en.json @@ -342,8 +342,9 @@ "switch": "Switch to an account on {{destInstance}}" }, "automatic": { - "title": "Locating post", - "description": "That content does not originate on your account's server." + "title": "Locating content", + "description": "Locating that content on your home server...", + "found": "Redirecting" } }, "inbox": { @@ -981,7 +982,8 @@ "unsupported": "That function is not supported by your account's server software.", "not_live_supported": "That server is not running supported software, or is offline.", "token_not_found": "That email verification link expired, or never existed.", - "invalid_password": "Invalid password." + "invalid_password": "Invalid password.", + "cant_find_object": "That content couldn't be found on your home server." }, "aria": { "pagination": { diff --git a/src/lib/ui/shared/loader/TextLoader.svelte b/src/lib/ui/shared/loader/TextLoader.svelte index e00eefc2..3457041f 100644 --- a/src/lib/ui/shared/loader/TextLoader.svelte +++ b/src/lib/ui/shared/loader/TextLoader.svelte @@ -1,15 +1,17 @@
diff --git a/src/routes/comment/[instance]/[id]/+page.ts b/src/routes/comment/[instance]/[id=integer]/+page.ts similarity index 100% rename from src/routes/comment/[instance]/[id]/+page.ts rename to src/routes/comment/[instance]/[id=integer]/+page.ts diff --git a/src/routes/comment/[instance]/[id=integer]/confirm/+page.svelte b/src/routes/comment/[instance]/[id=integer]/confirm/+page.svelte new file mode 100644 index 00000000..d7e8fc06 --- /dev/null +++ b/src/routes/comment/[instance]/[id=integer]/confirm/+page.svelte @@ -0,0 +1,5 @@ + + + diff --git a/src/routes/comment/[instance]/[id]/confirm/+page.ts b/src/routes/comment/[instance]/[id=integer]/confirm/+page.ts similarity index 53% rename from src/routes/comment/[instance]/[id]/confirm/+page.ts rename to src/routes/comment/[instance]/[id=integer]/confirm/+page.ts index b1036a5f..86d8dd48 100644 --- a/src/routes/comment/[instance]/[id]/confirm/+page.ts +++ b/src/routes/comment/[instance]/[id=integer]/confirm/+page.ts @@ -1,7 +1,7 @@ +import { goto } from '$app/navigation' import { profile } from '$lib/app/auth' -import { redirect } from '@sveltejs/kit' export async function load({ params }) { if (profile.current.instance == params.instance) - redirect(302, `/comment/${params.instance}/${params.id}`) + goto(`/comment/${params.instance}/${params.id}`, { replaceState: true }) } diff --git a/src/routes/comment/[instance]/[id]/confirm/+page.svelte b/src/routes/comment/[instance]/[id]/confirm/+page.svelte deleted file mode 100644 index f95f8250..00000000 --- a/src/routes/comment/[instance]/[id]/confirm/+page.svelte +++ /dev/null @@ -1,104 +0,0 @@ - - -
-
-
- {page.params.instance}/comment/{page.params.id} -
-
- {$t('routes.postRedirect.title')} -
-

- {$t('routes.postRedirect.description', { - homeInstance: fetched, - })} -

-
-
- {#if profile.current.jwt} - - {/if} - -
- {#if profile.meta.profiles} - {@const filtered = profile.meta.profiles.filter( - (i) => i.instance == page.params.instance, - )} -
-
- {$t('routes.postRedirect.actions.switch', { - destInstance: page.params.instance, - })} -
- - {#each filtered as profile (profile.id)} - - {/each} - - {$t('account.addGuest')} - - -
- {/if} -
diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index 049ad8d6..719b7f79 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,3 +1,4 @@ +import { goto } from '$app/navigation' import { resolve } from '$app/paths' import { client } from '$lib/api/client.svelte' import { profile } from '$lib/app/auth' @@ -10,7 +11,6 @@ import { feeds, type FeedTypes, } from '$lib/feature/feeds/feed.svelte' -import { redirect } from '@sveltejs/kit' function buildContext(thread?: string) { let parentId: number | undefined @@ -50,8 +50,11 @@ async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) { } export async function load({ params, url, route }) { - if (profile.current.instance != params.instance) - redirect(302, resolve('/post/[instance]/[id=integer]/confirm', params)) + if (profile.current.instance != params.instance) { + goto(resolve('/post/[instance]/[id=integer]/confirm', params), { + replaceState: true, + }) + } // TODO use Lemmy profile default settings const sort = settings?.defaultSort?.comments ?? 'Hot' diff --git a/src/routes/post/[instance]/[id=integer]/confirm/+page.svelte b/src/routes/post/[instance]/[id=integer]/confirm/+page.svelte index 69c5e166..1aa669a0 100644 --- a/src/routes/post/[instance]/[id=integer]/confirm/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/confirm/+page.svelte @@ -9,95 +9,153 @@ import ProfileButton from '$lib/feature/user/ProfileButton.svelte' import { Header } from '$lib/ui/layout' import SidebarButton from '$lib/ui/sidebar/SidebarButton.svelte' - import { Button, Material, toast } from 'mono-svelte' + import { Button, Material, TextLoader, toast } from 'mono-svelte' import { Plus } from 'svelte-hero-icons/dist' + import { expoOut } from 'svelte/easing' + import { fly } from 'svelte/transition' - let loading = $state(false) + interface Props { + type?: 'post' | 'comment' + } + + let { type = 'post' }: Props = $props() + + let _state = $state<'loading' | 'found' | 'error' | 'none'>('loading') + let manual = $state(false) const fetched = $state.snapshot(profile.current.instance) + $effect(() => { + if (!manual) fetchOnHome() + }) + + $effect(() => { + if (_state == 'error') manual = true + }) + async function fetchOnHome() { - loading = true + const initialManual = manual + _state = 'loading' try { const res = await client().resolveObject({ - q: `https://${page.params.instance}/post/${page.params.id}`, + q: `https://${page.params.instance}/${type}/${page.params.id}`, }) - if (res.post) { - goto( - resolve(`/post/[instance]/[id=integer]`, { - instance: profile.current.instance, - id: res.post.post.id.toString(), - }), - ) - } + if ((type == 'post' && !res.post) || (type == 'comment' && !res.comment)) + throw new Error('cant_find_object') + if (initialManual != manual) return + + goto( + resolve(`/${type}/[instance]/[id=integer]`, { + instance: profile.current.instance, + id: + type == 'post' + ? res.post!.post.id.toString() + : res.comment!.comment.id.toString(), + }), + { replaceState: true }, + ) + _state = 'found' } catch (err) { toast({ content: errorMessage(err), type: 'error' }) + manual = true + _state = 'error' } - loading = false }
-
-
- {page.params.instance}/post/{page.params.id} -
-
- {$t('routes.postRedirect.title')} -
-

- {$t('routes.postRedirect.description', { - homeInstance: fetched, - })} -

-
-
- {#if profile.current.jwt} - + + {:else} +
+
- {$t('routes.postRedirect.actions.fetch', { + {page.params.instance}/{type}/{page.params.id} +
+
+ {$t('routes.postRedirect.title')} +
+

+ {$t('routes.postRedirect.description', { homeInstance: fetched, })} - - {/if} - -

- {#if profile.meta.profiles} - {@const filtered = profile.meta.profiles.filter( - (i) => i.instance == page.params.instance, - )} -
-
- {$t('routes.postRedirect.actions.switch', { - destInstance: page.params.instance, - })} -
- - {#each filtered as profile (profile.id)} - - {/each} - + +
+ {#if profile.current.jwt} + + {/if} +
+ {#if profile.meta.profiles} + {@const filtered = profile.meta.profiles.filter( + (i) => i.instance == page.params.instance, + )} +
+
+ {$t('routes.postRedirect.actions.switch', { + destInstance: page.params.instance, + })} +
+ + {#each filtered as profile (profile.id)} + + {/each} + + {$t('account.addGuest')} + + +
+ {/if} {/if}