@behindthemusictree/app-kit 38.0.0 → 40.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,6 +81,7 @@ __export(genre_tree_exports, {
81
81
  TrackListProvider: () => TrackListProvider,
82
82
  TrackListSidebarVisibilityProvider: () => TrackListSidebarVisibilityProvider,
83
83
  TrackMinimumSchema: () => TrackMinimumSchema,
84
+ TracksFailureAlreadyReportedError: () => TracksFailureAlreadyReportedError,
84
85
  UuidResourceSchema: () => UuidResourceSchema,
85
86
  YOUTUBE_UNPLAYABLE_REASON_LABELS: () => YOUTUBE_UNPLAYABLE_REASON_LABELS,
86
87
  YoutubeAvailabilitySchema: () => YoutubeAvailabilitySchema,
@@ -112,7 +113,7 @@ __export(genre_tree_exports, {
112
113
  makeTrackPlaylistRelPageSchema: () => makeTrackPlaylistRelPageSchema,
113
114
  makeTrackPlaylistRelSchema: () => makeTrackPlaylistRelSchema,
114
115
  musicBrainzRecordingUrl: () => musicBrainzRecordingUrl,
115
- pruneGenrePlaylistsForArtist: () => pruneGenrePlaylistsForArtist,
116
+ projectGenrePlaylistsForArtist: () => projectGenrePlaylistsForArtist,
116
117
  rankByName: () => rankByName,
117
118
  rankNameIndex: () => rankNameIndex,
118
119
  searchGenrePlaylistsByName: () => searchGenrePlaylistsByName,
@@ -647,6 +648,12 @@ async function createAppErrorFromResult(result, backendBaseUrl) {
647
648
  } else {
648
649
  return createAppErrorFromErrorCode("SER5000" /* SERVICE_INTERNAL_ERROR */);
649
650
  }
651
+ } else if (result.status === 502 || result.status === 503 || result.status === 504) {
652
+ if (isBackendError) {
653
+ return createAppErrorFromErrorCode("BAC2000" /* BACKEND_UNAVAILABLE */);
654
+ } else {
655
+ return createAppErrorFromErrorCode("SER5000" /* SERVICE_INTERNAL_ERROR */);
656
+ }
650
657
  }
651
658
  return createAppErrorFromErrorCode("CLI5001" /* CLIENT_UNKNOWN */);
652
659
  }
@@ -1415,6 +1422,7 @@ var ArtistDetailedSchema = import_zod24.z.object({
1415
1422
  })
1416
1423
  ),
1417
1424
  tracksCount: import_zod24.z.number().int(),
1425
+ playableTracksCount: import_zod24.z.number().int(),
1418
1426
  image: ArtistImageSchema.nullable()
1419
1427
  });
1420
1428
 
@@ -2000,38 +2008,41 @@ var import_react14 = require("react");
2000
2008
  // src/genre-tree/useVisibleGenrePlaylists.ts
2001
2009
  var import_react13 = require("react");
2002
2010
 
2003
- // src/genre-tree/lib/prune-genre-playlists-for-artist.ts
2004
- var POP_ROOT_NAME = "Mainstream Pop";
2005
- var CORE_ELECTRONIC_NAME = "Core electronic";
2006
- var pruneGenrePlaylistsForArtist = (playlists, counts) => {
2011
+ // src/genre-tree/lib/project-genre-playlists-for-artist.ts
2012
+ var ZERO_SCOPED = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: { canonical: 0, regional: 0, all: 0 } };
2013
+ var ZERO_ALL = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: { all: 0 } };
2014
+ var ZERO_SCOPED_CATALOGUE = GenreCatalogueCountsSchema.parse(ZERO_SCOPED);
2015
+ var ZERO_ALL_CATALOGUE = GenreCatalogueCountsSchema.parse(ZERO_ALL);
2016
+ var projectGenrePlaylistsForArtist = (playlists, counts) => {
2007
2017
  const countByPlaylist = new Map(counts.map((count) => [count.genrePlaylist, count]));
2008
- const kept = /* @__PURE__ */ new Set();
2009
- for (const playlist of playlists) {
2010
- const isPopRoot = playlist.parent === null && playlist.name === POP_ROOT_NAME;
2011
- if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.catalogue.genreAndSubgenresTracksCount.all ?? 0) > 0) kept.add(playlist.uuid);
2012
- }
2013
- const coreElectronicUuids = new Set(
2014
- playlists.filter((playlist) => playlist.name === CORE_ELECTRONIC_NAME && kept.has(playlist.uuid)).map((p) => p.uuid)
2018
+ const focusUuids = new Set(
2019
+ counts.filter((count) => count.catalogue.genreAndSubgenresTracksCount.all > 0).map((count) => count.genrePlaylist)
2015
2020
  );
2016
- for (const playlist of playlists) {
2017
- if (playlist.parent && coreElectronicUuids.has(playlist.parent.uuid)) kept.add(playlist.uuid);
2018
- }
2019
- return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => {
2021
+ const genrePlaylists = playlists.map((playlist) => {
2020
2022
  const count = countByPlaylist.get(playlist.uuid);
2021
- const catalogue = GenreCatalogueCountsSchema.parse(playlist.catalogue);
2023
+ if (count) {
2024
+ return {
2025
+ ...playlist,
2026
+ genreOnlyTracksCount: count.genreOnlyTracksCount,
2027
+ genreAndSubgenresTracksCount: count.genreAndSubgenresTracksCount,
2028
+ catalogue: count.catalogue,
2029
+ tracksCount: genreMusicCount(count),
2030
+ // Artist view totals are not served.
2031
+ viewsCount: void 0
2032
+ };
2033
+ }
2022
2034
  const scopes = playlist.genreAndSubgenresTracksCount;
2023
- if (!scopes) throw new Error("Artist projections require a reference genre summary");
2024
- const zero = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: "canonical" in scopes ? { canonical: 0, regional: 0, all: 0 } : { all: 0 } };
2035
+ if (!scopes) throw new Error(`Artist projections require a reference genre summary (genre playlist ${playlist.uuid})`);
2036
+ const isScoped = "canonical" in scopes;
2025
2037
  return {
2026
2038
  ...playlist,
2027
- genreOnlyTracksCount: count?.genreOnlyTracksCount ?? 0,
2028
- genreAndSubgenresTracksCount: count?.genreAndSubgenresTracksCount ?? zero.genreAndSubgenresTracksCount,
2029
- catalogue: count?.catalogue ?? { ...catalogue, ...zero },
2030
- tracksCount: count ? genreMusicCount(count) : 0,
2031
- // Artist view totals are not served.
2039
+ ...isScoped ? ZERO_SCOPED : ZERO_ALL,
2040
+ catalogue: isScoped ? ZERO_SCOPED_CATALOGUE : ZERO_ALL_CATALOGUE,
2041
+ tracksCount: 0,
2032
2042
  viewsCount: void 0
2033
2043
  };
2034
2044
  });
2045
+ return { genrePlaylists, focusUuids };
2035
2046
  };
2036
2047
 
2037
2048
  // src/genre-tree/useVisibleGenrePlaylists.ts
@@ -2040,9 +2051,9 @@ function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null
2040
2051
  const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
2041
2052
  const artistCounts = artistUuid !== null ? counts.data : void 0;
2042
2053
  const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
2043
- const genrePlaylists = (0, import_react13.useMemo)(() => {
2044
- if (!tree) return [];
2045
- return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
2054
+ const projection = (0, import_react13.useMemo)(() => {
2055
+ if (!tree) return { genrePlaylists: [], focusUuids: void 0 };
2056
+ return artistCounts ? projectGenrePlaylistsForArtist(tree, artistCounts) : { genrePlaylists: tree, focusUuids: void 0 };
2046
2057
  }, [tree, artistCounts]);
2047
2058
  return {
2048
2059
  isLoading: isTreePending,
@@ -2050,7 +2061,8 @@ function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null
2050
2061
  isError: isTreeError && !tree,
2051
2062
  refetch,
2052
2063
  isFetching: isCountsLoading || !isTreePending && isTreeFetching,
2053
- genrePlaylists
2064
+ genrePlaylists: projection.genrePlaylists,
2065
+ focusUuids: projection.focusUuids
2054
2066
  };
2055
2067
  }
2056
2068
 
@@ -2087,7 +2099,7 @@ function useGenreTreeViewState({
2087
2099
  },
2088
2100
  [isSelectionControlled, onSelectedGenreUuidChange]
2089
2101
  );
2090
- const { isLoading, isError, refetch, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
2102
+ const { isLoading, isError, refetch, isFetching, genrePlaylists, focusUuids } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
2091
2103
  const genrePlaylistByNodeId = (0, import_react14.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
2092
2104
  const selectedGenrePlaylist = (0, import_react14.useMemo)(
2093
2105
  () => genrePlaylists.find((gp) => gp.criteria?.uuid === selectedGenreUuid),
@@ -2153,6 +2165,7 @@ function useGenreTreeViewState({
2153
2165
  refetch: () => void refetch(),
2154
2166
  isFetching,
2155
2167
  genrePlaylists,
2168
+ focusUuids,
2156
2169
  genrePlaylistByNodeId,
2157
2170
  visibleGenrePlaylists,
2158
2171
  groupedGenrePlaylistsByRoot,
@@ -2364,6 +2377,12 @@ var AUTO_SKIP_DELAY_MS = 1e3;
2364
2377
  function isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure) {
2365
2378
  return !runtimeUnplayableTrackIds.has(track.uuid) && (!isSong(track) || songUnplayableReason(track) === null && (!track.youtubeVideo || !hasPlaybackFailure(track.youtubeVideo.id)));
2366
2379
  }
2380
+ var TracksFailureAlreadyReportedError = class extends Error {
2381
+ constructor() {
2382
+ super("Genre playlist tracks request failed; the failure was already reported globally");
2383
+ this.name = "TracksFailureAlreadyReportedError";
2384
+ }
2385
+ };
2367
2386
  function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQueryKey, page = 1, pageSize = 50) {
2368
2387
  const { session, sessionRestored } = useSession();
2369
2388
  return usePlaybackQuery({
@@ -2432,6 +2451,7 @@ function TrackListProvider({
2432
2451
  if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
2433
2452
  const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
2434
2453
  const response = await (page === 1 ? fetchLatest : fetchBound)(endpoint, true, scope === "me", {}, params, false, !!from);
2454
+ if (response === null && !from) throw new TracksFailureAlreadyReportedError();
2435
2455
  const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
2436
2456
  return {
2437
2457
  tracks: parsed.results.map((rel) => rel.track),
@@ -2976,6 +2996,7 @@ function editGenreSongPages(data, edit) {
2976
2996
  TrackListProvider,
2977
2997
  TrackListSidebarVisibilityProvider,
2978
2998
  TrackMinimumSchema,
2999
+ TracksFailureAlreadyReportedError,
2979
3000
  UuidResourceSchema,
2980
3001
  YOUTUBE_UNPLAYABLE_REASON_LABELS,
2981
3002
  YoutubeAvailabilitySchema,
@@ -3007,7 +3028,7 @@ function editGenreSongPages(data, edit) {
3007
3028
  makeTrackPlaylistRelPageSchema,
3008
3029
  makeTrackPlaylistRelSchema,
3009
3030
  musicBrainzRecordingUrl,
3010
- pruneGenrePlaylistsForArtist,
3031
+ projectGenrePlaylistsForArtist,
3011
3032
  rankByName,
3012
3033
  rankNameIndex,
3013
3034
  searchGenrePlaylistsByName,