import { graphql, useLazyLoadQuery } from "react-relay"; import { Link, NavLink, useParams } from "react-router-dom"; import { useMemo, type PropsWithChildren } from "react"; import type { ProfileLayoutQuery as ProfileLayoutQueryType } from "./__generated__/ProfileLayoutQuery.graphql"; import ScrobbleChart from "./ScrobbleChart"; export default function ProfileLayout({ children }: PropsWithChildren) { const { handle } = useParams<{ handle: string }>(); const queryVariables = useMemo(() => { // Round to start of day to keep timestamp stable const now = new Date(); now.setHours(0, 0, 0, 0); const ninetyDaysAgo = new Date(now.getTime() - 90 * 24 * 60 * 60 * 1000); return { where: { actorHandle: { eq: handle } }, chartWhere: { actorHandle: { eq: handle }, playedTime: { gte: ninetyDaysAgo.toISOString(), }, }, }; }, [handle]); const queryData = useLazyLoadQuery( graphql` query ProfileLayoutQuery($where: FmTealAlphaFeedPlayWhereInput!, $chartWhere: FmTealAlphaFeedPlayWhereInput!) { ...ScrobbleChart_data fmTealAlphaFeedPlays( first: 1 sortBy: [{ field: playedTime, direction: desc }] where: $where ) { edges { node { actorHandle appBskyActorProfile { displayName description avatar { url(preset: "avatar") } } } } } } `, queryVariables ); const profile = queryData?.fmTealAlphaFeedPlays?.edges?.[0]?.node?.appBskyActorProfile; return (
← Back
{profile?.avatar?.url && ( {profile.displayName )}

{profile?.displayName ?? handle}

@{handle}

{profile?.description && (

{profile.description}

)}
`px-4 py-2 text-xs uppercase tracking-wider ${ isActive ? "text-zinc-100 border-b-2 border-zinc-100" : "text-zinc-500 hover:text-zinc-300" }` } > Scrobbles `px-4 py-2 text-xs uppercase tracking-wider ${ isActive ? "text-zinc-100 border-b-2 border-zinc-100" : "text-zinc-500 hover:text-zinc-300" }` } > Overall
{children}
); }