Your music, beautifully tracked. All yours. (coming soon)
teal.fm
teal-fm
atproto
1import { useEffect, useState } from "react";
2import { ScrollView } from "react-native";
3import { Text } from "@/components/ui/text";
4import { useStore } from "@/stores/mainStore";
5import { Agent } from "@atproto/api";
6
7import { OutputSchema as ActorFeedResponse } from "@teal/lexicons/src/types/fm/teal/alpha/feed/getActorFeed";
8
9import PlayView from "./playView";
10
11interface ActorPlaysViewProps {
12 repo: string | undefined;
13 pdsAgent: Agent | null;
14}
15const ActorPlaysView = ({ repo, pdsAgent }: ActorPlaysViewProps) => {
16 const [play, setPlay] = useState<ActorFeedResponse["plays"] | null>(null);
17 const isReady = useStore((state) => state.isAgentReady);
18 const tealDid = useStore((state) => state.tealDid);
19 useEffect(() => {
20 if (pdsAgent) {
21 pdsAgent
22 .call(
23 "fm.teal.alpha.feed.getActorFeed",
24 { authorDID: repo },
25 {},
26 { headers: { "atproto-proxy": tealDid + "#teal_fm_appview" } },
27 )
28 .then((res) => {
29 res.data.plays as ActorFeedResponse;
30 return setPlay(res.data.plays);
31 })
32 .catch((e) => {
33 console.log(e);
34 });
35 } else {
36 console.log("No agent");
37 }
38 }, [isReady, pdsAgent, repo, tealDid]);
39 if (!play) {
40 return <Text>Loading...</Text>;
41 }
42 return (
43 <ScrollView className="w-full *:gap-4">
44 {play.map((p) => (
45 <PlayView
46 key={p.playedTime + p.trackName}
47 dateListened={p.playedTime ? new Date(p.playedTime) : undefined}
48 trackTitle={p.trackName}
49 artistName={p.artists.map((a) => a.artistName).join(", ")}
50 releaseMbid={p.releaseMbId}
51 />
52 ))}
53 </ScrollView>
54 );
55};
56
57export default ActorPlaysView;