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
+68 -23

No files matched your search

+10 -7
View File
@@ -75,7 +75,7 @@
vote == 1
? $userSettings.revertColors
? '!text-orange-500'
: '!text-blue-500'
: '!text-blue-500 dark:!text-blue-400'
: vote == -1
? $userSettings.revertColors
? '!text-blue-500'
@@ -84,28 +84,31 @@
</script>
<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
aria-label="Upvote"
class={vote == 1 ? voteColor(vote) : ''}
on:click={upvote}
size="square-md"
size="square-sm"
color="tertiary"
alignment="center"
>
<Icon src={ArrowUpCircle} mini={vote == 1} size="20" />
<Icon src={ChevronUp} mini size="18" />
</Button>
<span class="font-medium {voteColor(vote)}">
<span class="font-medium transition-colors duration-200 {voteColor(vote)}">
<FormattedNumber number={score} />
</span>
<Button
aria-label="Downvote"
class={vote == -1 ? voteColor(vote) : ''}
on:click={downvote}
size="square-md"
size="square-sm"
color="tertiary"
>
<Icon src={ArrowDownCircle} mini={vote == -1} size="20" />
<Icon src={ChevronDown} mini size="18" />
</Button>
</div>
</slot>
+21 -14
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import {
type Toast,
toasts,
@@ -29,20 +30,26 @@
opacity: 0,
}}
>
<Icon
size="20"
mini
class="relative m-2 ml-4 flex-shrink-0"
src={toast.type == 'info'
? InformationCircle
: toast.type == 'success'
? CheckCircle
: toast.type == 'warning'
? ExclamationTriangle
: toast.type == 'error'
? ExclamationCircle
: ExclamationCircle}
/>
{#if toast.loading}
<div class="relative m-2 ml-4 flex-shrink-0">
<Spinner width={20} />
</div>
{:else}
<Icon
size="20"
mini
class="relative m-2 ml-4 flex-shrink-0"
src={toast.type == 'info'
? InformationCircle
: toast.type == 'success'
? CheckCircle
: toast.type == 'warning'
? ExclamationTriangle
: toast.type == 'error'
? ExclamationCircle
: ExclamationCircle}
/>
{/if}
<div class="flex flex-col p-4 pl-0 break-words max-w-full">
{#if toast.title}
<h1 class="text-base font-bold">{toast.title}</h1>
+9
View File
@@ -14,6 +14,7 @@ export interface Toast {
title?: string
content: string
type: ToastType
loading?: boolean
action?: () => any
}
@@ -24,12 +25,14 @@ export function toast({
content,
type = 'info',
duration = 5000,
loading = false,
action,
}: {
title?: string
content: string
type?: ToastType
duration?: number
loading?: boolean
action?: () => any
}) {
let id = 0
@@ -44,6 +47,7 @@ export function toast({
content: content,
title: title,
type: type,
loading: loading,
action: action,
},
]
@@ -52,4 +56,9 @@ export function toast({
setTimeout(() => {
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
}, 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 PostLink from '$lib/components/lemmy/post/PostLink.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 MultiSelect from '$lib/components/input/MultiSelect.svelte'
import { profile } from '$lib/auth.js'
import { instance } from '$lib/instance.js'
import { goto } from '$app/navigation'
export let data
@@ -30,6 +31,30 @@
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
@@ -171,7 +196,8 @@
comment.detail.comment_view,
...comments.comments,
])}
locked={data.post.post_view.post.locked}
locked={data.post.post_view.post.locked ||
$page.params.instance.toLowerCase() != $instance.toLowerCase()}
/>
{/if}
{#await buildCommentsTreeAsync(comments.comments)}