Somewhat sensible design (WIP)

This commit is contained in:
Astra 2025-04-20 17:15:00 +09:00
parent 164571ec19
commit dcca38a994
Signed by: astra
SSH key fingerprint: SHA256:jQDNS75/33T59Ey4yAzrUPP/5YQaXEetsW8hwUae+ag
5 changed files with 162 additions and 75 deletions

View file

@ -1,23 +1,39 @@
<script lang="ts">
import type { AccountMetadata } from "./pdsfetch";
const { account }: { account: AccountMetadata } = $props();
import { Config } from "../../config";
</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}"
src="{Config.PDS_URL}/xrpc/com.atproto.sync.getBlob?did={account.did}&cid={account.avatarCid}"
/>
{/if}
<p>{account.displayName}</p>
<div id="accountName">{account.displayName || account.did}</div>
</div>
<style>
#accountContainer {
display: column;
display: flex;
text-align: start;
border: 2px solid black;
align-items: center;
background-color: #0d0620;
padding: 4%;
margin: 10px;
/* round corners */
border-radius: 10px;
}
#accountName {
margin-left: 10px;
font-size: 0.9em;
/* replace overflow with ellipsis */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 80%;
}
#avatar {
width: 50px;

View file

@ -13,13 +13,13 @@
alt="avatar of {post.displayName}"
/>
{/if}
<p>{post.displayName} | {post.timenotstamp}</p>
<div id="headerText">{post.displayName} | {post.timenotstamp}</div>
</div>
<div id="postContent">
<p>{post.text}</p>
{#if post.replyingDid}
<p>Replying to: {post.replyingDid}</p>
{/if}
<p id="replyingText">replying to: {post.replyingDid}</p>
{/if}
<p id="postText">{post.text}</p>
{#if post.imagesCid}
<div id="imagesContainer">
{#each post.imagesCid as imageLink}
@ -42,21 +42,62 @@
<style>
#postContainer {
display: column;
text-align: start;
border: 2px solid black;
padding: 4%;
display: flex;
flex-direction: column;
border: 1px solid #8054f0;
background-color: black;
margin-bottom: -1px;
}
#postHeader {
text-decoration: underline;
display: flex;
flex-direction: row;
align-items: center;
justify-content: start;
background-color: #1f1145;
padding: 0px 0px;
height: fit-content;
border-bottom: 1px solid #8054f0;
font-weight: bold;
}
#postContent {
display: flex;
text-align: start;
flex-direction: column;
padding: 10px;
background-color: #0d0620;
color: white;
}
#replyingText {
font-size: 0.7em;
color: white;
margin: 0;
margin-bottom: 10px;
padding: 0;
}
#postText {
margin: 0;
padding: 0;
}
#headerText {
margin-left: 10px;
font-size: 0.9em;
text-align: start;
}
#avatar {
width: 50px;
height: 50px;
border-radius: 50%;
margin: 0px;
margin-left: 0px;
border-right: #8054f0 1px solid;
}
#embedImages {
width: 50%;
height: 50%;
margin-top: 0px;
margin-bottom: -5px;
}
#embedVideo {
width: 50%;
height: 50%;
}
</style>

View file

@ -5,6 +5,7 @@ import type {
AppBskyFeedPost,
ComAtprotoRepoListRecords,
} from "@atcute/client/lexicons";
import { Config } from "../../config";
// import { ComAtprotoRepoListRecords.Record } from "@atcute/client/lexicons";
// import { AppBskyFeedPost } from "@atcute/client/lexicons";
// import { AppBskyActorDefs } from "@atcute/client/lexicons";
@ -87,7 +88,7 @@ const didFromATuri = (aturi: string) => {
const rpc = new XRPC({
handler: simpleFetchHandler({
service: "https://pds.witchcraft.systems",
service: Config.PDS_URL,
}),
});
@ -99,6 +100,7 @@ const getDidsFromPDS = async () => {
};
const getAccountMetadata = async (did: `did:${string}:${string}`) => {
// gonna assume self exists in the app.bsky.actor.profile
try {
const { data } = await rpc.get("com.atproto.repo.getRecord", {
params: {
repo: did,
@ -116,6 +118,15 @@ const getAccountMetadata = async (did: `did:${string}:${string}`) => {
account.avatarCid = value.avatar.ref["$link"];
}
return account;
}
catch (e) {
console.error(`Error fetching metadata for ${did}:`, e);
return {
did: "error",
displayName: "",
avatarCid: null,
};
}
};
const getAllMetadataFromPds = async () => {
@ -125,21 +136,31 @@ const getAllMetadataFromPds = async () => {
return await getAccountMetadata(repo);
}),
);
return metadata;
return metadata.filter(account => account.did !== "error");
};
const fetchPosts = async (did: string) => {
const { data } = await rpc.get("com.atproto.repo.listRecords", {
params: {
repo: did,
collection: "app.bsky.feed.post",
limit: 5,
},
});
return {
records: data.records as ComAtprotoRepoListRecords.Record[],
did: did,
};
try {
const { data } = await rpc.get("com.atproto.repo.listRecords", {
params: {
repo: did,
collection: "app.bsky.feed.post",
limit: 5,
},
});
return {
records: data.records as ComAtprotoRepoListRecords.Record[],
did: did,
error: false
};
} catch (e) {
console.error(`Error fetching posts for ${did}:`, e);
return {
records: [],
did: did,
error: true
};
}
};
const fetchAllPosts = async () => {
@ -149,7 +170,8 @@ const fetchAllPosts = async () => {
await fetchPosts(metadata.did)
),
);
const posts: Post[] = postRecords.flatMap((userFetch) =>
const validPostRecords = postRecords.filter(record => !record.error);
const posts: Post[] = validPostRecords.flatMap((userFetch) =>
userFetch.records.map((record) => {
const user = users.find((user: AccountMetadata) =>
user.did == userFetch.did