diff --git a/apps/web/src/api/profile.ts b/apps/web/src/api/profile.ts index 2ab213a0..780095ad 100644 --- a/apps/web/src/api/profile.ts +++ b/apps/web/src/api/profile.ts @@ -1,11 +1,16 @@ import { client } from "."; +import { Compatibility } from "../types/compatibility"; import { Neighbour } from "../types/neighbour"; +import { Profile } from "../types/profile"; import { Scrobble } from "../types/scrobble"; export const getProfileByDid = async (did: string) => { - const response = await client.get("/xrpc/app.rocksky.actor.getProfile", { - params: { did }, - }); + const response = await client.get( + "/xrpc/app.rocksky.actor.getProfile", + { + params: { did }, + }, + ); return response.data; }; @@ -39,3 +44,16 @@ export const getActorNeighbours = async (did: string) => { ); return response.data; }; + +export const getActorCompatibility = async (did: string) => { + const response = await client.get<{ compatibility: Compatibility | null }>( + "/xrpc/app.rocksky.actor.getActorCompatibility", + { + params: { did }, + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + }, + ); + return response.data; +}; diff --git a/apps/web/src/components/Stats/Stats.tsx b/apps/web/src/components/Stats/Stats.tsx index a28df1a4..0923022f 100644 --- a/apps/web/src/components/Stats/Stats.tsx +++ b/apps/web/src/components/Stats/Stats.tsx @@ -27,27 +27,23 @@ export type StatsProps = { function Stats(props: StatsProps) { const { stats, mb } = props; return ( - +
- - SCROBBLES - + SCROBBLES {numeral(stats?.scrobbles).format("0,0")}
- - ARTISTS - + ARTISTS {numeral(stats?.artists).format("0,0")}
-
- +
+ LOVED TRACKS - + {numeral(stats?.lovedTracks).format("0,0")} diff --git a/apps/web/src/hooks/useGraph.tsx b/apps/web/src/hooks/useGraph.tsx index e57b9eba..1262f803 100644 --- a/apps/web/src/hooks/useGraph.tsx +++ b/apps/web/src/hooks/useGraph.tsx @@ -35,14 +35,14 @@ export const useFollowsInfiniteQuery = ( }); export const useFollowersQuery = ( - actor: string, + actor: string | undefined, limit: number, dids?: string[], cursor?: string, ) => useQuery({ queryKey: ["followers", actor, limit, dids, cursor], - queryFn: () => getFollowers(actor, limit, dids, cursor), + queryFn: () => getFollowers(actor!, limit, dids, cursor), }); export const useFollowersInfiniteQuery = ( diff --git a/apps/web/src/hooks/useProfile.tsx b/apps/web/src/hooks/useProfile.tsx index 563114f3..8a29526c 100644 --- a/apps/web/src/hooks/useProfile.tsx +++ b/apps/web/src/hooks/useProfile.tsx @@ -2,6 +2,7 @@ import { useQuery } from "@tanstack/react-query"; import { useSetAtom } from "jotai"; import { useEffect, useState } from "react"; import { + getActorCompatibility, getActorNeighbours, getProfileByDid, getProfileStatsByDid, @@ -38,6 +39,13 @@ export const useActorNeighboursQuery = (did: string) => enabled: !!did, }); +export const useActorCompatibilityQuery = (did: string | undefine) => + useQuery({ + queryKey: ["profile", "compatibility", did], + queryFn: () => getActorCompatibility(did!), + enabled: !!did, + }); + function useProfile(token?: string | null) { const setProfile = useSetAtom(profileAtom); const [data, setData] = useState(null); diff --git a/apps/web/src/pages/profile/Profile.tsx b/apps/web/src/pages/profile/Profile.tsx index 56717d66..db7dd436 100644 --- a/apps/web/src/pages/profile/Profile.tsx +++ b/apps/web/src/pages/profile/Profile.tsx @@ -73,8 +73,11 @@ function Profile(props: ProfileProps) { setIsSignInOpen(true); return; } - setFollows((prev) => new Set(prev).add(profile.data?.did)); - followAccount(profile.data?.did); + + if (!profile.data) return; + + setFollows((prev) => new Set(prev).add(profile.data.did)); + followAccount(profile.data.did); }; const onUnfollow = () => { @@ -82,12 +85,14 @@ function Profile(props: ProfileProps) { setIsSignInOpen(true); return; } + if (!profile.data) return; + setFollows((prev) => { const newSet = new Set(prev); - newSet.delete(profile.data?.did); + newSet.delete(profile.data.did); return newSet; }); - unfollowAccount(profile.data?.did); + unfollowAccount(profile.data.did); }; useEffect(() => { @@ -104,18 +109,26 @@ function Profile(props: ProfileProps) { } setFollows((prev) => { const newSet = new Set(prev); + if (!profile.data) return newSet; if ( data.followers.some( (follower: { did: string }) => follower.did === currentDid, ) ) { - newSet.add(profile.data?.did); + newSet.add(profile.data.did); } else { - newSet.delete(profile.data?.did); + newSet.delete(profile.data.did); } return newSet; }); - }, [data, isLoading, currentDid, setFollows, profile.data?.did]); + }, [ + data, + isLoading, + currentDid, + setFollows, + profile.data?.did, + profile.data, + ]); useEffect(() => { if (tab === undefined) { @@ -213,7 +226,7 @@ function Profile(props: ProfileProps) { {(profile.data?.did !== localStorage.getItem("did") || !localStorage.getItem("did")) && ( <> - {!follows.has(profile.data?.did) && !isLoading && ( + {!follows.has(profile.data?.did || "") && !isLoading && (