forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1import { didAtom } from "@/src/atoms/did";
2import { handleAtom } from "@/src/atoms/handle";
3import { useProfileByDidQuery } from "@/src/hooks/useProfile";
4import dayjs from "dayjs";
5import { useAtomValue, useSetAtom } from "jotai";
6import { useEffect } from "react";
7import { Linking } from "react-native";
8import Avatar from "./Avatar";
9
10const AvatarWithData = () => {
11 const handle = useAtomValue(handleAtom);
12 const setDid = useSetAtom(didAtom);
13
14 const { data, isLoading } = useProfileByDidQuery(
15 handle || "did:plc:7vdlgi2bflelz7mmuxoqjfcr",
16 );
17
18 useEffect(() => {
19 if (data) {
20 setDid(data.did);
21 }
22 }, [data]);
23
24 return (
25 <>
26 {!isLoading && data && (
27 <Avatar
28 avatar={data.avatar}
29 name={data.display_name}
30 handle={`@${data.handle}`}
31 scrobblingSince={dayjs(data.xata_createdat).format("DD MMM YYYY")}
32 did={data.did}
33 onOpenBlueskyProfile={(handle: string) => {
34 Linking.openURL(
35 `https://bsky.app/profile/${handle.replace("@", "")}`,
36 );
37 }}
38 onViewOnPdsls={(did: string) => {
39 Linking.openURL(`https://pdsls.dev/at/${did}`);
40 }}
41 />
42 )}
43 </>
44 );
45};
46
47export default AvatarWithData;