diff --git a/lexicons/blue/microcosm/links/getBacklinksCount.json b/lexicons/blue/microcosm/links/getBacklinksCount.json new file mode 100644 index 0000000..f5acde4 --- /dev/null +++ b/lexicons/blue/microcosm/links/getBacklinksCount.json @@ -0,0 +1,44 @@ +{ + "id": "blue.microcosm.links.getBacklinksCount", + "defs": { + "main": { + "type": "query", + "output": { + "schema": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "integer", + "description": "total number of matching links" + } + } + }, + "encoding": "application/json" + }, + "parameters": { + "type": "params", + "required": [ + "subject", + "source" + ], + "properties": { + "source": { + "type": "string", + "description": "collection and path specification for the primary link" + }, + "subject": { + "type": "string", + "format": "uri", + "description": "the primary target being linked to (at-uri, did, or uri)" + } + } + }, + "description": "count records that link to another record" + } + }, + "$type": "com.atproto.lexicon.schema", + "lexicon": 1 +} \ No newline at end of file diff --git a/src/components/FeedPost.tsx b/src/components/FeedPost.tsx index 4af9ec2..db0b11e 100644 --- a/src/components/FeedPost.tsx +++ b/src/components/FeedPost.tsx @@ -4,7 +4,7 @@ import { useState } from "react"; import { Pressable, StyleSheet, View } from "react-native"; import { Post } from "../lib/post"; import { Profile } from "../lib/profile"; -import { PostInteractionButtons } from "./PostInteraction"; +import { PostInteractionButtons, PostNotesIndicator } from "./PostInteraction"; import { Text } from "./primitive/Text"; const styles = StyleSheet.create({ @@ -86,9 +86,9 @@ function PostBody({ post }: { post: Post }) { } function PostFooter({ post }: { post: Post }) { - return ( - + + ); diff --git a/src/components/PostInteraction.tsx b/src/components/PostInteraction.tsx index 65f97d1..35f23d8 100644 --- a/src/components/PostInteraction.tsx +++ b/src/components/PostInteraction.tsx @@ -1,13 +1,38 @@ import Ionicons from "@expo/vector-icons/Ionicons"; -import { Pressable } from "react-native"; +import { Pressable, View } from "react-native"; import { Post } from "../lib/post"; import { + fetchPostNotesCount, fetchUserPostInteractions, PostInteractions, setLikePost, } from "../lib/interact"; import { useContext, useEffect, useState } from "react"; import { AuthContext } from "../context/AuthContext"; +import { Text } from "./primitive/Text"; + +export function PostNotesIndicator({ post }: { post: Post }) { + const [count, setCount] = useState() + + useEffect(() => { + (async () => { + const count = await fetchPostNotesCount(post) + setCount(count) + })() + }, [post]) + + return + {count} notes + +} export function PostInteractionButtons({ post }: { post: Post }) { const authCtx = useContext(AuthContext); @@ -26,7 +51,6 @@ export function PostInteractionButtons({ post }: { post: Post }) { }, [post, authCtx]); const setLike = async (newLike: boolean) => { - console.log(newLike); const newPostInteractions = await setLikePost( newLike, post, @@ -34,11 +58,8 @@ export function PostInteractionButtons({ post }: { post: Post }) { authCtx.client!, ); setPostInteractions(newPostInteractions); - console.log(newPostInteractions.liked); }; - console.log("re-rendered (1)"); - return ( <> @@ -53,8 +74,6 @@ export function PostLike({ liked: boolean; setLike: (newLike: boolean) => void; }) { - console.log("re-rendered (2)"); - return ( +export type $Output = l.InferMethodOutput +export type $OutputBody = l.InferMethodOutputBody< + typeof main, + B +> + +export const $lxm = main.nsid, + $params = main.parameters, + $output = main.output diff --git a/src/lexicons/blue/microcosm/links/getBacklinksCount.ts b/src/lexicons/blue/microcosm/links/getBacklinksCount.ts new file mode 100644 index 0000000..1ad377c --- /dev/null +++ b/src/lexicons/blue/microcosm/links/getBacklinksCount.ts @@ -0,0 +1,6 @@ +/* + * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT. + */ + +export * from './getBacklinksCount.defs' +export * as $defs from './getBacklinksCount.defs' diff --git a/src/lib/interact.ts b/src/lib/interact.ts index 0d68d10..3d93848 100644 --- a/src/lib/interact.ts +++ b/src/lib/interact.ts @@ -13,7 +13,7 @@ export async function fetchUserPostInteractions(post: Post, did: string) { const results = await Constellation.call( blue.microcosm.links.getBacklinks, { - subject: post.uri as AtUriString, + subject: post.uri, source: `${dev.maelstrom.bramblr.like.$nsid}:subject.uri`, did: [did as AtprotoDid], limit: 1, @@ -26,6 +26,16 @@ export async function fetchUserPostInteractions(post: Post, did: string) { } as PostInteractions; } +export async function fetchPostNotesCount(post: Post) { + // TODO: Add other interaction sources + const { total } = await Constellation.call(blue.microcosm.links.getBacklinksCount, { + subject: post.uri, + source: `${dev.maelstrom.bramblr.like.$nsid}:subject.uri` + }) + + return total +} + // Also mutates input postInteractions export async function setLikePost( like: boolean,