diff --git a/actions/getIdentityData.ts b/actions/getIdentityData.ts index c83a287c..6ed8e690 100644 --- a/actions/getIdentityData.ts +++ b/actions/getIdentityData.ts @@ -42,7 +42,6 @@ export async function uncachedGetIdentityData() { .eq("confirmed", true) .single() : null; - console.log(auth_res); if (!auth_res?.data?.identities) return null; if (auth_res.data.identities.atp_did) { //I should create a relationship table so I can do this in the above query diff --git a/app/api/rpc/[command]/get_user_recommendations.ts b/app/api/rpc/[command]/get_user_recommendations.ts new file mode 100644 index 00000000..1c608695 --- /dev/null +++ b/app/api/rpc/[command]/get_user_recommendations.ts @@ -0,0 +1,40 @@ +import { z } from "zod"; +import { makeRoute } from "../lib"; +import type { Env } from "./route"; +import { getIdentityData } from "actions/getIdentityData"; + +export type GetUserRecommendationsReturnType = Awaited< + ReturnType<(typeof get_user_recommendations)["handler"]> +>; + +export const get_user_recommendations = makeRoute({ + route: "get_user_recommendations", + input: z.object({ + documentUris: z.array(z.string()), + }), + handler: async ({ documentUris }, { supabase }: Pick) => { + const identity = await getIdentityData(); + const currentUserDid = identity?.atp_did; + + if (!currentUserDid || documentUris.length === 0) { + return { + result: {} as Record, + }; + } + + const { data: recommendations } = await supabase + .from("recommends_on_documents") + .select("document") + .eq("recommender_did", currentUserDid) + .in("document", documentUris); + + const recommendedSet = new Set(recommendations?.map((r) => r.document)); + + const result: Record = {}; + for (const uri of documentUris) { + result[uri] = recommendedSet.has(uri); + } + + return { result }; + }, +}); diff --git a/app/api/rpc/[command]/route.ts b/app/api/rpc/[command]/route.ts index df7a865b..c6ba128e 100644 --- a/app/api/rpc/[command]/route.ts +++ b/app/api/rpc/[command]/route.ts @@ -14,6 +14,7 @@ import { get_publication_data } from "./get_publication_data"; import { search_publication_names } from "./search_publication_names"; import { search_publication_documents } from "./search_publication_documents"; import { get_profile_data } from "./get_profile_data"; +import { get_user_recommendations } from "./get_user_recommendations"; let supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, @@ -41,6 +42,7 @@ let Routes = [ search_publication_names, search_publication_documents, get_profile_data, + get_user_recommendations, ]; export async function POST( req: Request, diff --git a/app/lish/[did]/[publication]/[rkey]/CanvasPage.tsx b/app/lish/[did]/[publication]/[rkey]/CanvasPage.tsx index 03fb8cab..05c9e1c1 100644 --- a/app/lish/[did]/[publication]/[rkey]/CanvasPage.tsx +++ b/app/lish/[did]/[publication]/[rkey]/CanvasPage.tsx @@ -72,7 +72,6 @@ export function CanvasPage({ commentsCount={getCommentCount(document.comments_on_documents, pageId)} quotesCount={getQuoteCount(document.quotesAndMentions, pageId)} recommendsCount={document.recommendsCount} - hasRecommended={document.hasRecommended} /> { let isMobile = useIsMobile(); return ( @@ -221,7 +219,6 @@ const CanvasMetadata = (props: { quotesCount={props.quotesCount || 0} commentsCount={props.commentsCount || 0} recommendsCount={props.recommendsCount} - hasRecommended={props.hasRecommended} showComments={props.preferences.showComments !== false} showMentions={props.preferences.showMentions !== false} pageId={props.pageId} diff --git a/app/lish/[did]/[publication]/[rkey]/Interactions/Interactions.tsx b/app/lish/[did]/[publication]/[rkey]/Interactions/Interactions.tsx index 42b22cb9..54d68574 100644 --- a/app/lish/[did]/[publication]/[rkey]/Interactions/Interactions.tsx +++ b/app/lish/[did]/[publication]/[rkey]/Interactions/Interactions.tsx @@ -107,7 +107,6 @@ export const Interactions = (props: { quotesCount: number; commentsCount: number; recommendsCount: number; - hasRecommended: boolean; className?: string; showComments: boolean; showMentions: boolean; @@ -138,7 +137,6 @@ export const Interactions = (props: { {props.quotesCount === 0 || props.showMentions === false ? null : ( @@ -177,7 +175,6 @@ export const ExpandedInteractions = (props: { quotesCount: number; commentsCount: number; recommendsCount: number; - hasRecommended: boolean; className?: string; showComments: boolean; showMentions: boolean; @@ -238,7 +235,6 @@ export const ExpandedInteractions = (props: { {props.quotesCount === 0 || !props.showMentions ? null : (