feat: switch to a toast

This commit is contained in:
Xyphyn committed 2023-08-25 14:50:44 -07:00
1 parent 0fbe243f7b
commit 45fbc7d25f
1 file changed
+31 -26
@@ -40,38 +40,43 @@
afterNavigate(async () => { afterNavigate(async () => {
// reactivity hack // reactivity hack
post = data.post post = data.post
})
beforeNavigate(async () => { if ($page.params.instance.toLowerCase() != $instance.toLowerCase()) {
if ( if (!$profile?.jwt) return
$page.params.instance.toLowerCase() != $instance.toLowerCase() && toast({
$profile?.jwt content: 'Do you want to open this post on your home instance?',
) { action: () => {
const id = toast({ if ($profile?.jwt) fetchOnHome($profile.jwt)
content: 'Attempting to fetch this post on your home instance...', },
loading: true, duration: 9999 * 1000,
}) })
try {
const res = await getClient().resolveObject({
auth: $profile.jwt,
q: post.post_view.post.ap_id,
})
if (res.post) {
removeToast(id)
goto(`/post/${$instance}/${res.post.post.id}`, {}).then(() =>
removeToast(id)
)
}
} catch (err) {
removeToast(id)
}
} }
}) })
const fetchOnHome = async (jwt: string) => {
const id = toast({
content: 'Attempting to fetch this post on your home instance...',
loading: true,
})
try {
const res = await getClient().resolveObject({
auth: jwt,
q: post.post_view.post.ap_id,
})
if (res.post) {
removeToast(id)
goto(`/post/${$instance}/${res.post.post.id}`, {}).then(() =>
removeToast(id)
)
}
} catch (err) {
removeToast(id)
}
}
let commentsPage = 1 let commentsPage = 1
let commentSort: CommentSortType = data.commentSort let commentSort: CommentSortType = data.commentSort
let loading = false let loading = false