diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index 653e2a63..c30690fa 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -16,6 +16,7 @@ Icon, Newspaper, PencilSquare, + ServerStack, Share, Trash, UserCircle, @@ -41,6 +42,8 @@ Modal, Spinner, } from 'mono-svelte' + import { fediseer, type Data } from '$lib/fediseer/fediseer' + import Fediseer from '$lib/fediseer/Fediseer.svelte' export let post: PostView @@ -49,8 +52,16 @@ let editing = false let saving = false export let debug: boolean = false + + let fediseerOpen = false + let fediseerData: Data | null = null + let fediseerLoading = false +{#if fediseerData} + +{/if} + {#if editing}

Editing post

@@ -166,6 +177,28 @@ {post.community.title} + { + e.stopImmediatePropagation() + + fediseerLoading = true + const data = await fediseer.getInstanceInfo(new URL(post.community.actor_id).hostname) + console.log(data) + fediseerData = data + fediseerOpen = true + fediseerLoading = false + + return + }} + > + {#if fediseerLoading} + + {:else} + + {/if} + {new URL(post.community.actor_id).hostname} +
Actions {#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id} @@ -181,7 +214,7 @@ post.read = await markAsRead(post.post, !post.read, $profile.jwt) }} > - + Mark as {post.read ? 'Unread' : 'Read'} {/if} diff --git a/src/lib/components/ui/LabelStat.svelte b/src/lib/components/ui/LabelStat.svelte index da2df533..2388bb8b 100644 --- a/src/lib/components/ui/LabelStat.svelte +++ b/src/lib/components/ui/LabelStat.svelte @@ -7,8 +7,8 @@
- {label} - + {label} + {#if formatted} {:else} diff --git a/src/lib/fediseer/Fediseer.svelte b/src/lib/fediseer/Fediseer.svelte new file mode 100644 index 00000000..5ac2a658 --- /dev/null +++ b/src/lib/fediseer/Fediseer.svelte @@ -0,0 +1,83 @@ + + + +
+ + + Endorsements {data.endorsements.instances.length} + +
+ {#each data.endorsements.instances as instance} +
+ + +
+ {/each} +
+
+ + + Guarantees {data.guarantees.instances.length} + +
+ {#each data.guarantees.instances as instance} +
+ + +
+ {/each} +
+
+ + + Censures {data.censures.instances.length} + +
+ {#each data.censures.instances as instance} +
+ + +
+ {/each} +
+
+ + + Hesitations {data.hesitations.instances.length} + +
+ {#each data.hesitations.instances as instance} +
+ + +
+ {/each} +
+
+
+
\ No newline at end of file diff --git a/src/lib/fediseer/fediseer.ts b/src/lib/fediseer/fediseer.ts new file mode 100644 index 00000000..81641240 --- /dev/null +++ b/src/lib/fediseer/fediseer.ts @@ -0,0 +1,55 @@ +export interface Endorsements { + instances: { + domain: string + endorsement_reasons: string[] + }[] +} + +export interface Hesitations { + instances: { + domain: string + hesitation_reasons: string[] + }[] +} + +export interface Censures { + instances: { + domain: string + censure_reasons: string[] + }[] +} + +export interface Guarantees { + instances: { + domain: string + guarantee_reasons: string[] + }[] +} + +export interface Data { + endorsements: Endorsements + hesitations: Hesitations + guarantees: Guarantees + censures: Censures +} + +class Fediseer { + url: string + + constructor(url: string) { + this.url = url + } + + async getInstanceInfo(domain: string): Promise { + const [endorsements, hesitations, guarantees, censures] = await Promise.all([ + fetch(`${this.url}/v1/endorsements/${domain}`).then(r => r.json()) as Promise, + fetch(`${this.url}/v1/hesitations/${domain}`).then(r => r.json()) as Promise, + fetch(`${this.url}/v1/guarantees/${domain}`).then(r => r.json()) as Promise, + fetch(`${this.url}/v1/censures/${domain}`).then(r => r.json()) as Promise + ]) + + return { endorsements, hesitations, guarantees, censures } + } +} + +export const fediseer = new Fediseer('https://fediseer.com/api') \ No newline at end of file