feat: add option to resolve posts to your home instance

This commit is contained in:
Xyphyn committed 2023-08-15 16:03:13 -07:00
1 parent 735bdff376
commit c09460bd9b
4 files changed
+54 -9

No files matched your search

+10 -7
View File
@@ -75,7 +75,7 @@
vote == 1 vote == 1
? $userSettings.revertColors ? $userSettings.revertColors
? '!text-orange-500' ? '!text-orange-500'
: '!text-blue-500' : '!text-blue-500 dark:!text-blue-400'
: vote == -1 : vote == -1
? $userSettings.revertColors ? $userSettings.revertColors
? '!text-blue-500' ? '!text-blue-500'
@@ -84,28 +84,31 @@
</script> </script>
<slot {upvote} {downvote} {vote} {score}> <slot {upvote} {downvote} {vote} {score}>
<div class="flex items-center text-sm gap-0.5 rounded-md border-zinc-700"> <div
class="flex items-center text-sm gap-1 rounded-md border border-slate-200
dark:border-zinc-700 px-1 h-full duration-200"
>
<Button <Button
aria-label="Upvote" aria-label="Upvote"
class={vote == 1 ? voteColor(vote) : ''} class={vote == 1 ? voteColor(vote) : ''}
on:click={upvote} on:click={upvote}
size="square-md" size="square-sm"
color="tertiary" color="tertiary"
alignment="center" alignment="center"
> >
<Icon src={ArrowUpCircle} mini={vote == 1} size="20" /> <Icon src={ChevronUp} mini size="18" />
</Button> </Button>
<span class="font-medium {voteColor(vote)}"> <span class="font-medium transition-colors duration-200 {voteColor(vote)}">
<FormattedNumber number={score} /> <FormattedNumber number={score} />
</span> </span>
<Button <Button
aria-label="Downvote" aria-label="Downvote"
class={vote == -1 ? voteColor(vote) : ''} class={vote == -1 ? voteColor(vote) : ''}
on:click={downvote} on:click={downvote}
size="square-md" size="square-sm"
color="tertiary" color="tertiary"
> >
<Icon src={ArrowDownCircle} mini={vote == -1} size="20" /> <Icon src={ChevronDown} mini size="18" />
</Button> </Button>
</div> </div>
</slot> </slot>
@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import { import {
type Toast, type Toast,
toasts, toasts,
@@ -29,6 +30,11 @@
opacity: 0, opacity: 0,
}} }}
> >
{#if toast.loading}
<div class="relative m-2 ml-4 flex-shrink-0">
<Spinner width={20} />
</div>
{:else}
<Icon <Icon
size="20" size="20"
mini mini
@@ -43,6 +49,7 @@
? ExclamationCircle ? ExclamationCircle
: ExclamationCircle} : ExclamationCircle}
/> />
{/if}
<div class="flex flex-col p-4 pl-0 break-words max-w-full"> <div class="flex flex-col p-4 pl-0 break-words max-w-full">
{#if toast.title} {#if toast.title}
<h1 class="text-base font-bold">{toast.title}</h1> <h1 class="text-base font-bold">{toast.title}</h1>
+9
View File
@@ -14,6 +14,7 @@ export interface Toast {
title?: string title?: string
content: string content: string
type: ToastType type: ToastType
loading?: boolean
action?: () => any action?: () => any
} }
@@ -24,12 +25,14 @@ export function toast({
content, content,
type = 'info', type = 'info',
duration = 5000, duration = 5000,
loading = false,
action, action,
}: { }: {
title?: string title?: string
content: string content: string
type?: ToastType type?: ToastType
duration?: number duration?: number
loading?: boolean
action?: () => any action?: () => any
}) { }) {
let id = 0 let id = 0
@@ -44,6 +47,7 @@ export function toast({
content: content, content: content,
title: title, title: title,
type: type, type: type,
loading: loading,
action: action, action: action,
}, },
] ]
@@ -52,4 +56,9 @@ export function toast({
setTimeout(() => { setTimeout(() => {
toasts.update((toasts) => toasts.filter((toast) => toast.id != id)) toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
}, duration) }, duration)
return id
} }
export const removeToast = (id: number) =>
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
@@ -14,11 +14,12 @@
import Card from '$lib/components/ui/Card.svelte' import Card from '$lib/components/ui/Card.svelte'
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 { toast } from '$lib/components/ui/toasts/toasts.js' import { removeToast, toast } from '$lib/components/ui/toasts/toasts.js'
import type { CommentSortType } from 'lemmy-js-client' import type { CommentSortType } from 'lemmy-js-client'
import MultiSelect from '$lib/components/input/MultiSelect.svelte' import MultiSelect from '$lib/components/input/MultiSelect.svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { instance } from '$lib/instance.js' import { instance } from '$lib/instance.js'
import { goto } from '$app/navigation'
export let data export let data
@@ -30,6 +31,30 @@
post_id: data.post.post_view.post.id, post_id: data.post.post_view.post.id,
}) })
} }
if (
$page.params.instance.toLowerCase() != $instance.toLowerCase() &&
$profile?.jwt
) {
const id = toast({
content: 'Attempting to fetch this post on your home instance...',
loading: true,
})
try {
const res = await getClient().resolveObject({
auth: $profile.jwt,
q: `https://${$page.params.instance}/post/${data.post.post_view.post.id}`,
})
if (res.post) {
removeToast(id)
goto(`/post/${$instance}/${res.post.post.id}`)
}
} catch (err) {
removeToast(id)
}
}
}) })
let commentsPage = 1 let commentsPage = 1
@@ -171,7 +196,8 @@
comment.detail.comment_view, comment.detail.comment_view,
...comments.comments, ...comments.comments,
])} ])}
locked={data.post.post_view.post.locked} locked={data.post.post_view.post.locked ||
$page.params.instance.toLowerCase() != $instance.toLowerCase()}
/> />
{/if} {/if}
{#await buildCommentsTreeAsync(comments.comments)} {#await buildCommentsTreeAsync(comments.comments)}