Accounts component

This commit is contained in:
Ariadna 2025-04-20 02:02:47 -04:00
parent 8bf166f134
commit fe96164f4e
Signed by: ari
SSH key fingerprint: SHA256:j4xpQafvRcIH4rwZqM5aREIogWsCjyYohia7vH0+uZY
4 changed files with 85 additions and 21 deletions

View file

@ -1,19 +1,35 @@
<script lang="ts"> <script lang="ts">
import PostComponent from "./lib/PostComponent.svelte"; import PostComponent from "./lib/PostComponent.svelte";
import { fetchAllPosts, Post } from "./lib/pdsfetch"; import AccountComponent from "./lib/AccountComponent.svelte";
import { fetchAllPosts, Post, getAllMetadataFromPds } from "./lib/pdsfetch";
const postsPromise = fetchAllPosts(); const postsPromise = fetchAllPosts();
const accountsPromise = getAllMetadataFromPds();
</script> </script>
<main> <main>
<h1>Welcome to the Feed</h1>
{#await accountsPromise}
<p>Loading...</p>
{:then accountsData}
<div id="Account">
{#each accountsData as accountObject}
<AccountComponent account={accountObject} />
{/each}
</div>
{:catch error}
<p>Error: {error.message}</p>
{/await}
{#await postsPromise} {#await postsPromise}
<p>Loading...</p> <p>Loading...</p>
{:then postsData} {:then postsData}
{#each postsData as postObject} <div id="Feed">
<PostComponent post={postObject as Post} /> {#each postsData as postObject}
{/each} <PostComponent post={postObject as Post} />
{/each}
</div>
{/await} {/await}
</main> </main>
<style> <style>
</style> </style>

View file

@ -0,0 +1,27 @@
<script lang="ts">
import type { AccountMetadata } from "./pdsfetch";
const { account }: { account: AccountMetadata } = $props();
</script>
<div id="accountContainer">
{#if account.avatarCid}
<img
id="avatar"
alt="avatar of {account.displayName}"
src="https://pds.witchcraft.systems/xrpc/com.atproto.sync.getBlob?did={account.did}&cid={account.avatarCid}"
/>
{/if}
<p>{account.displayName}</p>
</div>
<style>
#accountContainer {
display: column;
text-align: start;
border: 2px solid black;
padding: 4%;
}
#avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
</style>

View file

@ -8,6 +8,7 @@
{#if post.authorAvatarCid} {#if post.authorAvatarCid}
<img <img
id="avatar" id="avatar"
alt="avatar of {post.displayName}"
src="https://pds.witchcraft.systems/xrpc/com.atproto.sync.getBlob?did={post.authorDid}&cid={post.authorAvatarCid}" src="https://pds.witchcraft.systems/xrpc/com.atproto.sync.getBlob?did={post.authorDid}&cid={post.authorAvatarCid}"
/> />
{/if} {/if}
@ -18,13 +19,16 @@
{#if post.replyingDid} {#if post.replyingDid}
<p>Replying to: {post.replyingDid}</p> <p>Replying to: {post.replyingDid}</p>
{/if} {/if}
{#if post.imagesLinksCid} {#if post.imagesCid}
{#each post.imagesLinksCid as imageLink} <div id="imagesContainer">
<img {#each post.imagesCid as imageLink}
id="embedImages" <img
src="https://pds.witchcraft.systems/xrpc/com.atproto.sync.getBlob?did={post.authorDid}&cid={imageLink}" id="embedImages"
/> alt="Post Image"
{/each} src="https://pds.witchcraft.systems/xrpc/com.atproto.sync.getBlob?did={post.authorDid}&cid={imageLink}"
/>
{/each}
</div>
{/if} {/if}
{#if post.videosLinkCid} {#if post.videosLinkCid}
<video <video

View file

@ -1,5 +1,10 @@
import { simpleFetchHandler, XRPC } from "@atcute/client"; import { simpleFetchHandler, XRPC } from "@atcute/client";
import "@atcute/bluesky/lexicons"; import "@atcute/bluesky/lexicons";
import type {
AppBskyActorDefs,
AppBskyFeedPost,
ComAtprotoRepoListRecords,
} from "@atcute/client/lexicons";
// import { ComAtprotoRepoListRecords.Record } from "@atcute/client/lexicons"; // import { ComAtprotoRepoListRecords.Record } from "@atcute/client/lexicons";
// import { AppBskyFeedPost } from "@atcute/client/lexicons"; // import { AppBskyFeedPost } from "@atcute/client/lexicons";
// import { AppBskyActorDefs } from "@atcute/client/lexicons"; // import { AppBskyActorDefs } from "@atcute/client/lexicons";
@ -12,16 +17,19 @@ interface AccountMetadata {
class Post { class Post {
authorDid: string; authorDid: string;
authorAvatarCid: string | null; authorAvatarCid: string | null;
displayName : string; displayName: string;
text: string; text: string;
timestamp: number; timestamp: number;
timenotstamp: string; timenotstamp: string;
quotingDid: string | null; quotingDid: string | null;
replyingDid: string | null; replyingDid: string | null;
imagesLinksCid: string[] | null; imagesCid: string[] | null;
videosLinkCid: string | null; videosLinkCid: string | null;
constructor(record: ComAtprotoRepoListRecords.Record, account : AccountMetadata) { constructor(
record: ComAtprotoRepoListRecords.Record,
account: AccountMetadata,
) {
this.authorDid = account.did; this.authorDid = account.did;
this.authorAvatarCid = account.avatarCid; this.authorAvatarCid = account.avatarCid;
this.displayName = account.displayName; this.displayName = account.displayName;
@ -35,11 +43,11 @@ class Post {
this.replyingDid = null; this.replyingDid = null;
} }
this.quotingDid = null; this.quotingDid = null;
this.imagesLinksCid = null; this.imagesCid = null;
this.videosLinkCid = null; this.videosLinkCid = null;
switch (post.embed?.$type) { switch (post.embed?.$type) {
case "app.bsky.embed.images": case "app.bsky.embed.images":
this.imagesLinksCid = post.embed.images.map((imageRecord) => this.imagesCid = post.embed.images.map((imageRecord: any) =>
imageRecord.image.ref.$link imageRecord.image.ref.$link
); );
break; break;
@ -53,7 +61,7 @@ class Post {
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo; this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
switch (post.embed.media.$type) { switch (post.embed.media.$type) {
case "app.bsky.embed.images": case "app.bsky.embed.images":
this.imagesLinksCid = post.embed.media.images.map((imageRecord) => this.imagesCid = post.embed.media.images.map((imageRecord) =>
imageRecord.image.ref.$link imageRecord.image.ref.$link
); );
@ -141,11 +149,20 @@ const fetchAllPosts = async () => {
await fetchPosts(metadata.did) await fetchPosts(metadata.did)
), ),
); );
const posts : Post[] = postRecords.flatMap((userFetch) => const posts: Post[] = postRecords.flatMap((userFetch) =>
userFetch.records.map((record) => new Post(record, users.find((user : AccountMetadata) => user.did == userFetch.did))) userFetch.records.map((record) => {
const user = users.find((user: AccountMetadata) =>
user.did == userFetch.did
);
if (!user) {
throw new Error(`User with DID ${userFetch.did} not found`);
}
return new Post(record, user);
})
); );
posts.sort((a, b) => b.timestamp - a.timestamp); posts.sort((a, b) => b.timestamp - a.timestamp);
return posts; return posts;
}; };
export { fetchAllPosts, Post }; export { fetchAllPosts, getAllMetadataFromPds, Post };
export type { AccountMetadata };