Live video on the AT Protocol
1import { ProfileViewDetailed } from "@atproto/api/dist/client/types/app/bsky/actor/defs";
2import {
3 getProfiles,
4 selectCachedProfiles,
5} from "features/bluesky/blueskySlice";
6import { useEffect, useMemo } from "react";
7import { useAppDispatch, useAppSelector } from "store/hooks";
8
9// Hack: Easy way to cache and get avatars
10export default function useAvatars(dids: string[]) {
11 const dispatch = useAppDispatch();
12 const profiles: Record<string, ProfileViewDetailed> =
13 useAppSelector(selectCachedProfiles);
14
15 const missingDids = useMemo(
16 () => dids.filter((did) => !(did in profiles)),
17 [dids, profiles],
18 );
19
20 useEffect(() => {
21 if (missingDids.length > 0) {
22 console.log("Fetching profiles for DIDs:", missingDids);
23 dispatch(getProfiles(missingDids)).then((e) => console.log("ok", e));
24 }
25 }, [missingDids, dispatch]);
26
27 return profiles;
28}