-
Notifications
You must be signed in to change notification settings - Fork 18
feat: homepage valuation hero (Catalog HQ 1/3, chat#1850) #1852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
528523b
feat: homepage valuation hero for accounts with a catalog (chat#1850)
sweetmantech 537fb3f
fix(home): artist-scope the valuation hero — verify the artist has so…
sweetmantech 7355a77
fix(home): verify the artist/catalog pairing client-side — the api ar…
sweetmantech 67afc14
refactor(home): artist-scope the hero via the v2 measurements filter;…
sweetmantech d9f076c
refactor(home): hero visibility + count from the whole-scope measured…
sweetmantech 86e9131
refactor(home): measurements fetch moves to GET /api/catalogs/{catalo…
sweetmantech 540a53c
refactor(home): valuation hero renders inside ChatGreeting — no chat.…
sweetmantech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import ImageWithFallback from "@/components/ImageWithFallback"; | ||
| import { formatValuationAmount } from "@/lib/catalog/formatValuationAmount"; | ||
| import type { CatalogValuationBand } from "@/lib/catalog/getCatalogMeasurements"; | ||
|
|
||
| interface ValuationHeroProps { | ||
| artistName: string; | ||
| artistImage: string; | ||
| valuation: CatalogValuationBand; | ||
| measuredTrackCount: number; | ||
| } | ||
|
|
||
| /** | ||
| * Homepage hero: the estimated catalog value a valuation lead converted on | ||
| * (recoupable/chat#1850). Card styling follows DESIGN.md: shadow-as-border, | ||
| * achromatic chrome, display treatment on the dollar figure. | ||
| */ | ||
| const ValuationHero = ({ | ||
| artistName, | ||
| artistImage, | ||
| valuation, | ||
| measuredTrackCount, | ||
| }: ValuationHeroProps) => ( | ||
| <section | ||
| aria-label="Estimated catalog value" | ||
| className="w-full rounded-xl bg-card p-6 shadow-[0px_0px_0px_1px_var(--border),0px_2px_4px_rgba(0,0,0,0.04)] dark:shadow-[0px_0px_0px_1px_var(--border),0px_2px_4px_rgba(0,0,0,0.2)]" | ||
| > | ||
| <div className="flex items-center gap-3"> | ||
| {artistImage && ( | ||
| <span className="inline-block size-10 shrink-0 overflow-hidden rounded-full ring-1 ring-foreground"> | ||
| <ImageWithFallback src={artistImage} /> | ||
| </span> | ||
| )} | ||
| <div className="flex flex-col"> | ||
| <span className="font-heading text-base font-semibold text-foreground"> | ||
| {artistName} | ||
| </span> | ||
| <span className="text-xs uppercase tracking-[0.05em] text-muted-foreground"> | ||
| Estimated catalog value | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <p className="mt-4 font-heading text-5xl font-semibold tracking-tight text-foreground tabular-nums sm:text-6xl"> | ||
| {formatValuationAmount(valuation.mid)} | ||
| </p> | ||
| <p className="mt-2 text-sm text-muted-foreground"> | ||
| Range {formatValuationAmount(valuation.low)} to{" "} | ||
| {formatValuationAmount(valuation.high)} · {measuredTrackCount}{" "} | ||
| {measuredTrackCount === 1 ? "track" : "tracks"} measured | ||
| </p> | ||
| </section> | ||
| ); | ||
|
|
||
| export default ValuationHero; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { useQuery, UseQueryResult } from "@tanstack/react-query"; | ||
| import { usePrivy } from "@privy-io/react-auth"; | ||
| import { | ||
| getCatalogMeasurements, | ||
| CatalogMeasurementsResponse, | ||
| } from "@/lib/catalog/getCatalogMeasurements"; | ||
|
|
||
| const useCatalogMeasurements = ( | ||
| catalogId: string | undefined, | ||
| artistAccountId?: string, | ||
| limit?: number, | ||
| ): UseQueryResult<CatalogMeasurementsResponse> => { | ||
| const { getAccessToken, authenticated } = usePrivy(); | ||
|
|
||
| return useQuery({ | ||
| queryKey: [ | ||
| "catalog-measurements", | ||
| catalogId, | ||
| artistAccountId ?? null, | ||
| limit ?? null, | ||
| ], | ||
| queryFn: async () => { | ||
| const accessToken = await getAccessToken(); | ||
| if (!accessToken) throw new Error("No access token"); | ||
| return getCatalogMeasurements( | ||
| catalogId as string, | ||
| accessToken, | ||
| artistAccountId, | ||
| limit, | ||
| ); | ||
| }, | ||
| enabled: !!catalogId && authenticated, | ||
| staleTime: 5 * 60 * 1000, // 5 minutes | ||
| refetchOnWindowFocus: false, | ||
| // The measurements endpoint is still rolling out (chat#1850); a 404 must | ||
| // fall back to the greeting immediately instead of retrying. | ||
| retry: false, | ||
| }); | ||
| }; | ||
|
|
||
| export default useCatalogMeasurements; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import useCatalogs from "@/hooks/useCatalogs"; | ||
| import useCatalogMeasurements from "@/hooks/useCatalogMeasurements"; | ||
| import { useArtistProvider } from "@/providers/ArtistProvider"; | ||
| import { getValuationHeroState } from "@/lib/home/getValuationHeroState"; | ||
| import type { CatalogValuationBand } from "@/lib/catalog/getCatalogMeasurements"; | ||
|
|
||
| export type HomeValuationState = | ||
| | { show: false } | ||
| | { | ||
| show: true; | ||
| artistName: string; | ||
| artistImage: string; | ||
| valuation: CatalogValuationBand; | ||
| measuredTrackCount: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Composed hook behind the homepage valuation hero. The hero reads the | ||
| * account's catalog through the measurements endpoint; with an artist | ||
| * selected the read is scoped server-side via artist_account_id | ||
| * (catalog_songs ∩ song_artists) and only renders when the response echoes | ||
| * that scope — a pre-v2 api ignores the param and gets hidden instead of | ||
| * showing whole-catalog money under an artist label. With no artist | ||
| * selected it shows the whole catalog's value under the catalog name. | ||
| * Auth/context come from providers per the chat hooks conventions; nothing | ||
| * here touches the chat transport (recoupable/chat#1850). | ||
| */ | ||
| const useHomeValuation = (): HomeValuationState => { | ||
| const { selectedArtist } = useArtistProvider(); | ||
| const selectedArtistName = selectedArtist?.name ?? null; | ||
| const selectedArtistAccountId = selectedArtist?.account_id ?? null; | ||
|
|
||
| const { data: catalogsData, isError: catalogsFailed } = useCatalogs(); | ||
| const catalog = catalogsData?.catalogs?.[0]; | ||
|
|
||
| // limit 1: the hero only needs the whole-scope aggregates | ||
| // (measured_song_count + valuation), not the measurement rows. | ||
| const { data: measurements, isError: measurementsFailed } = | ||
| useCatalogMeasurements( | ||
| catalog?.id, | ||
| selectedArtistAccountId ?? undefined, | ||
| 1, | ||
| ); | ||
|
|
||
| const state = getValuationHeroState({ | ||
| catalog, | ||
| catalogsFailed, | ||
| measurements, | ||
| measurementsFailed, | ||
| selectedArtistName, | ||
| selectedArtistAccountId, | ||
| }); | ||
|
|
||
| if (!state.show) return { show: false }; | ||
|
|
||
| return { | ||
| show: true, | ||
| artistName: state.showArtist | ||
| ? selectedArtistName || state.catalogName | ||
| : state.catalogName, | ||
| artistImage: state.showArtist ? selectedArtist?.image || "" : "", | ||
| valuation: state.valuation, | ||
| measuredTrackCount: state.measuredTrackCount, | ||
| }; | ||
| }; | ||
|
|
||
| export default useHomeValuation; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { formatValuationAmount } from "@/lib/catalog/formatValuationAmount"; | ||
|
|
||
| describe("formatValuationAmount", () => { | ||
| it("formats millions compactly", () => { | ||
| expect(formatValuationAmount(1400000)).toBe("$1.4M"); | ||
| }); | ||
|
|
||
| it("formats thousands compactly", () => { | ||
| expect(formatValuationAmount(959000)).toBe("$959K"); | ||
| }); | ||
|
|
||
| it("drops trailing zero decimals", () => { | ||
| expect(formatValuationAmount(2000000)).toBe("$2M"); | ||
| }); | ||
|
|
||
| it("formats zero", () => { | ||
| expect(formatValuationAmount(0)).toBe("$0"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.