From cce92efab14a610e9a1045787cf8254117169ddb Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 30 Jan 2024 12:46:08 -0800 Subject: [PATCH] Fix issue where lists can't be shown on profile We were using handle to fetch lists, instead of user's DID. --- src/containers/lists/ListsContainer.tsx | 7 ++++++- src/lib/api/bsky/list/index.tsx | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/containers/lists/ListsContainer.tsx b/src/containers/lists/ListsContainer.tsx index 05c6ade8..4b0dc5df 100644 --- a/src/containers/lists/ListsContainer.tsx +++ b/src/containers/lists/ListsContainer.tsx @@ -4,6 +4,7 @@ import ListItem from "@/components/contentDisplay/listItem/ListItem"; import ListsSkeleton from "@/components/contentDisplay/lists/ListsSkeleton"; import FeedAlert from "@/components/feedback/feedAlert/FeedAlert"; import LoadingSpinner from "@/components/status/loadingSpinner/LoadingSpinner"; +import { getProfile } from "@/lib/api/bsky/actor"; import { getLists } from "@/lib/api/bsky/list"; import useAgent from "@/lib/hooks/bsky/useAgent"; import { useInfiniteQuery } from "@tanstack/react-query"; @@ -28,7 +29,11 @@ export default function ListsContainer(props: Props) { fetchNextPage, } = useInfiniteQuery({ queryKey: ["user lists", handle], - queryFn: ({ pageParam }) => getLists(handle, pageParam, agent), + queryFn: async ({ pageParam }) => { + const profile = await getProfile(handle, agent); + if (!profile) throw new Error("Could not get user id to show lists"); + return getLists(profile.did, pageParam, agent); + }, initialPageParam: "", getNextPageParam: (lastPage) => lastPage?.cursor, }); diff --git a/src/lib/api/bsky/list/index.tsx b/src/lib/api/bsky/list/index.tsx index 088b70f8..2b396064 100644 --- a/src/lib/api/bsky/list/index.tsx +++ b/src/lib/api/bsky/list/index.tsx @@ -1,4 +1,4 @@ -import { type BskyAgent, AppBskyActorDefs } from "@atproto/api"; +import { type BskyAgent } from "@atproto/api"; export const getLists = async ( did: string, @@ -9,6 +9,7 @@ export const getLists = async ( actor: did, cursor: cursor, }); + if (!lists.success) throw new Error("Could not fetch list"); return lists.data; };