@behindthemusictree/app-kit 34.1.0 → 36.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.
@@ -151,7 +151,7 @@ __export(genre_tree_exports, {
151
151
  module.exports = __toCommonJS(genre_tree_exports);
152
152
 
153
153
  // src/genre-tree/useGenre.ts
154
- var import_zod24 = require("zod");
154
+ var import_zod23 = require("zod");
155
155
 
156
156
  // src/genre-tree/schemas/criteria/detailed.ts
157
157
  var import_zod11 = require("zod");
@@ -271,12 +271,12 @@ var CriteriaDetailedSchema = import_zod11.z.object({
271
271
  wikidataId: import_zod11.z.string().nullable().optional(),
272
272
  parent: CriteriaMinimumSchema.nullable(),
273
273
  ascendants: import_zod11.z.array(CriteriaLineageRelWithoutDescendantSchema),
274
- descendants: import_zod11.z.array(CriteriaLineageRelWithoutAscendantSchema),
274
+ descendants: import_zod11.z.array(CriteriaLineageRelWithoutAscendantSchema).optional(),
275
275
  root: CriteriaMinimumSchema,
276
276
  children: import_zod11.z.array(CriteriaMinimumSchema),
277
277
  catalogue: GenreCatalogueCountsSchema.optional(),
278
- criteriaPlaylist: import_zod11.z.union([GenrePlaylistSummarySchema, CriteriaPlaylistMinimumSchema]),
279
- tracks: import_zod11.z.array(TrackMinimumSchema),
278
+ criteriaPlaylist: import_zod11.z.union([GenrePlaylistSummarySchema, CriteriaPlaylistMinimumSchema]).nullable(),
279
+ tracks: import_zod11.z.array(TrackMinimumSchema).optional(),
280
280
  essentialSongs: import_zod11.z.array(TrackMinimumSchema),
281
281
  tracksCount: import_zod11.z.number(),
282
282
  updatedOn: import_zod11.z.string().datetime().nullable()
@@ -332,7 +332,7 @@ var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
332
332
  // src/genre-tree/schemas/reference-genre.ts
333
333
  var ReferenceGenreDetailedSchema = CriteriaDetailedSchema.extend({
334
334
  catalogue: GenreCatalogueCountsSchema,
335
- criteriaPlaylist: GenrePlaylistSummarySchema
335
+ criteriaPlaylist: GenrePlaylistSummarySchema.nullable()
336
336
  });
337
337
  var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
338
338
  ...GenreCountsSchema.shape,
@@ -346,32 +346,18 @@ var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
346
346
  var import_react_query5 = require("@tanstack/react-query");
347
347
  var import_react6 = require("react");
348
348
 
349
- // src/transport/PlaybackContext.tsx
350
- var import_react = require("react");
351
- var import_zod14 = require("zod");
352
- var import_jsx_runtime = require("react/jsx-runtime");
353
- var PlaybackContextSchema = import_zod14.z.object({ country: import_zod14.z.string().regex(/^[A-Z]{2}$/).nullable() });
354
- var unmanaged = {
355
- country: null,
356
- key: null,
357
- ready: true,
358
- error: null,
359
- isCurrent: (_key) => true,
360
- snapshot: () => ({ key: null, country: null }),
361
- refresh: async (_force = false) => null
362
- };
363
- var PlaybackContext = (0, import_react.createContext)(unmanaged);
364
- var usePlaybackContext = () => (0, import_react.useContext)(PlaybackContext);
365
-
366
349
  // src/transport/useFetchWrapper.ts
367
350
  var import_react4 = require("react");
368
351
 
352
+ // src/transport/lib/use-backend-request.ts
353
+ var import_react3 = require("react");
354
+
369
355
  // src/transport/connectivity-error-context.tsx
370
- var import_react2 = require("react");
371
- var import_jsx_runtime2 = require("react/jsx-runtime");
372
- var ConnectivityErrorContext = (0, import_react2.createContext)(void 0);
356
+ var import_react = require("react");
357
+ var import_jsx_runtime = require("react/jsx-runtime");
358
+ var ConnectivityErrorContext = (0, import_react.createContext)(void 0);
373
359
  function useConnectivityError() {
374
- const context = (0, import_react2.useContext)(ConnectivityErrorContext);
360
+ const context = (0, import_react.useContext)(ConnectivityErrorContext);
375
361
  if (context === void 0) {
376
362
  throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
377
363
  }
@@ -379,7 +365,7 @@ function useConnectivityError() {
379
365
  }
380
366
 
381
367
  // src/auth/SessionContext.tsx
382
- var import_react3 = require("react");
368
+ var import_react2 = require("react");
383
369
 
384
370
  // src/transport/query-client.ts
385
371
  var import_react_query = require("@tanstack/react-query");
@@ -394,10 +380,10 @@ var queryClient = new import_react_query.QueryClient({
394
380
  });
395
381
 
396
382
  // src/auth/SessionContext.tsx
397
- var import_jsx_runtime3 = require("react/jsx-runtime");
398
- var SessionContext = (0, import_react3.createContext)(void 0);
383
+ var import_jsx_runtime2 = require("react/jsx-runtime");
384
+ var SessionContext = (0, import_react2.createContext)(void 0);
399
385
  function useSession() {
400
- const context = (0, import_react3.useContext)(SessionContext);
386
+ const context = (0, import_react2.useContext)(SessionContext);
401
387
  if (context === void 0) {
402
388
  throw new Error("useSession must be used within a SessionProvider");
403
389
  }
@@ -777,12 +763,11 @@ var fetchWrapper = async (url, requiresAuth, options = {}, accessToken, queryPar
777
763
  }
778
764
  };
779
765
 
780
- // src/transport/useFetchWrapper.ts
781
- var useFetchWrapper = (getBackendBaseUrl) => {
782
- const playback = usePlaybackContext();
766
+ // src/transport/lib/use-backend-request.ts
767
+ var useBackendRequest = (getBackendBaseUrl) => {
783
768
  const { setConnectivityError } = useConnectivityError();
784
769
  const { clearSession, session, sessionRestored } = useSession();
785
- const handleError = (0, import_react4.useCallback)((error) => {
770
+ const handleError = (0, import_react3.useCallback)((error) => {
786
771
  if (error instanceof ConnectivityError) {
787
772
  const authDetailErrors = [
788
773
  "BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
@@ -809,64 +794,55 @@ var useFetchWrapper = (getBackendBaseUrl) => {
809
794
  if (!sessionRestored) return;
810
795
  setConnectivityError(createAppErrorFromErrorCode("SES4012" /* SESSION_REQUIRED */));
811
796
  };
812
- const fetch2 = (0, import_react4.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false, acceptRefreshedContext = false) => {
797
+ const request = (0, import_react3.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false, onResponse) => {
813
798
  const baseUrl = getBackendBaseUrl().replace(/\/+$/, "");
814
799
  const endpointPath = String(backendEndpointOrUrl);
815
800
  if (fromBackend && endpointPath.startsWith("/")) {
816
801
  throw new Error(`Endpoint path must be relative (no leading slash). Got: "${endpointPath}".`);
817
802
  }
818
803
  const url = fromBackend ? endpointPath ? `${baseUrl}/${endpointPath}` : baseUrl : backendEndpointOrUrl;
819
- const perform = async (retryContextChange) => {
820
- const contextual = playback.key !== null && fromBackend && /^(?:me\/)?(library\/songs|genre-playlists|playlists|manual-playlists)\//.test(endpointPath);
821
- let requestContext = { key: playback.key, country: playback.country };
822
- if (contextual) {
823
- await playback.refresh();
824
- if (acceptRefreshedContext) requestContext = playback.snapshot();
825
- if (!playback.isCurrent(requestContext.key)) throw new DOMException("Playback context changed", "AbortError");
826
- }
827
- try {
828
- const result = await fetchWrapper(
829
- url,
830
- requiresAuth,
831
- options,
832
- session?.accessToken || void 0,
833
- queryParams,
834
- handleMissingRequiredSession,
835
- skipGlobalError ? void 0 : handleError,
836
- expectBinary,
837
- baseUrl,
838
- contextual ? async (response) => {
839
- const responseCountry = response.headers.get("x-playback-country");
840
- if (responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
841
- await playback.refresh(true);
842
- throw new DOMException("Playback context changed", "AbortError");
843
- }
844
- if (!playback.isCurrent(requestContext.key)) throw new DOMException("Playback context changed", "AbortError");
845
- } : void 0
804
+ return fetchWrapper(
805
+ url,
806
+ requiresAuth,
807
+ options,
808
+ session?.accessToken || void 0,
809
+ queryParams,
810
+ handleMissingRequiredSession,
811
+ skipGlobalError ? void 0 : handleError,
812
+ expectBinary,
813
+ baseUrl,
814
+ onResponse
815
+ );
816
+ }, [session?.accessToken, handleError, getBackendBaseUrl, sessionRestored, setConnectivityError]);
817
+ return { request };
818
+ };
819
+
820
+ // src/transport/useFetchWrapper.ts
821
+ var useFetchWrapper = (getBackendBaseUrl) => {
822
+ const { request } = useBackendRequest(getBackendBaseUrl);
823
+ const fetch2 = (0, import_react4.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => {
824
+ const isRead = (options.method ?? "GET").toUpperCase() === "GET";
825
+ const warnOnStampedRead = isRead && fromBackend && process.env.NODE_ENV !== "production" ? (response) => {
826
+ if (response.headers.get("x-playback-country") !== null) {
827
+ console.error(
828
+ `GET ${backendEndpointOrUrl} is country-dependent (X-Playback-Country) but was fetched without the playback context. Use usePlaybackQuery/usePlaybackFetch.`
846
829
  );
847
- if (contextual && !playback.isCurrent(requestContext.key)) throw new DOMException("Playback context changed", "AbortError");
848
- return result;
849
- } catch (error) {
850
- if (retryContextChange && contextual && error instanceof DOMException && error.name === "AbortError" && !playback.isCurrent(requestContext.key)) {
851
- return perform(false);
852
- }
853
- throw error;
854
830
  }
855
- };
856
- return perform(acceptRefreshedContext);
857
- }, [session?.accessToken, handleError, getBackendBaseUrl, sessionRestored, setConnectivityError, playback]);
831
+ } : void 0;
832
+ return request(backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError, warnOnStampedRead);
833
+ }, [request]);
858
834
  return { fetch: fetch2 };
859
835
  };
860
836
 
861
837
  // src/genre-tree/useGenrePlaylist.ts
862
- var import_zod17 = require("zod");
838
+ var import_zod16 = require("zod");
863
839
  var import_react_query3 = require("@tanstack/react-query");
864
840
 
865
841
  // src/transport/lib/use-query-with-parse.ts
866
842
  var import_react_query2 = require("@tanstack/react-query");
867
843
 
868
844
  // src/transport/lib/parse-with-log.ts
869
- var import_zod15 = require("zod");
845
+ var import_zod14 = require("zod");
870
846
  function parseWithLog(schema, data, context) {
871
847
  const result = schema.safeParse(data);
872
848
  if (!result.success) {
@@ -874,7 +850,7 @@ function parseWithLog(schema, data, context) {
874
850
  if (data == null) {
875
851
  throw new Error(`${prefix} received null response before schema validation`);
876
852
  }
877
- console.error(`${prefix} schema validation failed`, import_zod15.z.flattenError(result.error));
853
+ console.error(`${prefix} schema validation failed`, import_zod14.z.flattenError(result.error));
878
854
  throw result.error;
879
855
  }
880
856
  return result.data;
@@ -897,15 +873,15 @@ function useQueryWithParse({
897
873
  }
898
874
 
899
875
  // src/transport/lib/paginated-response.ts
900
- var import_zod16 = require("zod");
901
- var PaginatedResponseSchema = (itemSchema) => import_zod16.z.object({
902
- overallTotal: import_zod16.z.number(),
903
- next: import_zod16.z.string().url().nullable(),
904
- previous: import_zod16.z.string().url().nullable(),
905
- results: import_zod16.z.array(itemSchema),
906
- page: import_zod16.z.number(),
907
- pageSize: import_zod16.z.number(),
908
- totalPages: import_zod16.z.number()
876
+ var import_zod15 = require("zod");
877
+ var PaginatedResponseSchema = (itemSchema) => import_zod15.z.object({
878
+ overallTotal: import_zod15.z.number(),
879
+ next: import_zod15.z.string().url().nullable(),
880
+ previous: import_zod15.z.string().url().nullable(),
881
+ results: import_zod15.z.array(itemSchema),
882
+ page: import_zod15.z.number(),
883
+ pageSize: import_zod15.z.number(),
884
+ totalPages: import_zod15.z.number()
909
885
  });
910
886
 
911
887
  // src/genre-tree/api/genre-playlists/queryKeys.ts
@@ -1057,7 +1033,7 @@ var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
1057
1033
  { page, pageSize: FULL_LIST_PAGE_SIZE, treeName: "canonical" }
1058
1034
  )
1059
1035
  ),
1060
- schema: scope === "reference" ? import_zod17.z.array(ReferenceGenrePlaylistSchema) : import_zod17.z.array(CriteriaPlaylistSimpleSchema),
1036
+ schema: scope === "reference" ? import_zod16.z.array(ReferenceGenrePlaylistSchema) : import_zod16.z.array(CriteriaPlaylistSimpleSchema),
1061
1037
  context: "useListFullGenrePlaylists",
1062
1038
  enabled: scope === "reference" || sessionRestored && !!session?.accessToken
1063
1039
  });
@@ -1093,7 +1069,7 @@ var useInvalidateAllGenrePlaylistQueries = () => {
1093
1069
  // src/transport/lib/use-validated-mutation.ts
1094
1070
  var import_react_query4 = require("@tanstack/react-query");
1095
1071
  var import_react5 = require("react");
1096
- var import_zod18 = require("zod");
1072
+ var import_zod17 = require("zod");
1097
1073
  function useValidatedMutation({
1098
1074
  inputSchema,
1099
1075
  outputSchema,
@@ -1126,9 +1102,9 @@ function useValidatedMutation({
1126
1102
  } catch (error) {
1127
1103
  if (error instanceof Error && "json" in error) {
1128
1104
  try {
1129
- const errorResponse = import_zod18.z.object({
1130
- details: import_zod18.z.object({
1131
- fieldErrors: import_zod18.z.record(import_zod18.z.string(), import_zod18.z.array(import_zod18.z.object({ message: import_zod18.z.string() })))
1105
+ const errorResponse = import_zod17.z.object({
1106
+ details: import_zod17.z.object({
1107
+ fieldErrors: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.array(import_zod17.z.object({ message: import_zod17.z.string() })))
1132
1108
  })
1133
1109
  }).parse(error.json);
1134
1110
  setFormErrors(
@@ -1152,47 +1128,47 @@ function useValidatedMutation({
1152
1128
  }
1153
1129
 
1154
1130
  // src/genre-tree/schemas/criteria/overview.ts
1155
- var import_zod20 = require("zod");
1131
+ var import_zod19 = require("zod");
1156
1132
 
1157
1133
  // src/genre-tree/schemas/http-url.ts
1158
- var import_zod19 = require("zod");
1159
- var HttpUrlSchema = import_zod19.z.url({ protocol: /^https?$/ });
1134
+ var import_zod18 = require("zod");
1135
+ var HttpUrlSchema = import_zod18.z.url({ protocol: /^https?$/ });
1160
1136
 
1161
1137
  // src/genre-tree/schemas/criteria/overview.ts
1162
- var CriteriaOverviewSchema = import_zod20.z.object({
1138
+ var CriteriaOverviewSchema = import_zod19.z.object({
1163
1139
  uuid: GenreUuidSchema,
1164
- name: import_zod20.z.string(),
1165
- summary: import_zod20.z.string().nullable(),
1166
- description: import_zod20.z.string().nullable(),
1140
+ name: import_zod19.z.string(),
1141
+ summary: import_zod19.z.string().nullable(),
1142
+ description: import_zod19.z.string().nullable(),
1167
1143
  summarySourceUrl: HttpUrlSchema.nullable(),
1168
- essentialSongs: import_zod20.z.array(TrackMinimumSchema).optional()
1144
+ essentialSongs: import_zod19.z.array(TrackMinimumSchema).optional()
1169
1145
  });
1170
1146
 
1171
1147
  // src/genre-tree/schemas/criteria/simple.ts
1172
- var import_zod21 = require("zod");
1173
- var CriteriaSimpleSchema = import_zod21.z.object({
1148
+ var import_zod20 = require("zod");
1149
+ var CriteriaSimpleSchema = import_zod20.z.object({
1174
1150
  uuid: GenreUuidSchema,
1175
- name: import_zod21.z.string(),
1151
+ name: import_zod20.z.string(),
1176
1152
  parent: CriteriaMinimumSchema.nullable(),
1177
- createdOn: import_zod21.z.string().datetime(),
1178
- summary: import_zod21.z.string().nullable()
1153
+ createdOn: import_zod20.z.string().datetime(),
1154
+ summary: import_zod20.z.string().nullable()
1179
1155
  });
1180
1156
 
1181
1157
  // src/genre-tree/schemas/criteria/creation.ts
1182
- var import_zod22 = require("zod");
1183
- var CriteriaCreationSchema = import_zod22.z.object({
1184
- name: import_zod22.z.string().min(1, "Name is required"),
1158
+ var import_zod21 = require("zod");
1159
+ var CriteriaCreationSchema = import_zod21.z.object({
1160
+ name: import_zod21.z.string().min(1, "Name is required"),
1185
1161
  parent: GenreUuidSchema.optional(),
1186
- essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional()
1162
+ essentialSongs: import_zod21.z.array(import_zod21.z.string().uuid()).optional()
1187
1163
  });
1188
1164
 
1189
1165
  // src/genre-tree/schemas/criteria/update.ts
1190
- var import_zod23 = require("zod");
1191
- var CriteriaUpdateSchema = import_zod23.z.object({
1192
- name: import_zod23.z.string().optional(),
1166
+ var import_zod22 = require("zod");
1167
+ var CriteriaUpdateSchema = import_zod22.z.object({
1168
+ name: import_zod22.z.string().optional(),
1193
1169
  parent: GenreUuidSchema.nullable().optional(),
1194
- essentialSongs: import_zod23.z.array(import_zod23.z.string().uuid()).optional(),
1195
- side: import_zod23.z.enum(["core", "pop"]).optional()
1170
+ essentialSongs: import_zod22.z.array(import_zod22.z.string().uuid()).optional(),
1171
+ side: import_zod22.z.enum(["core", "pop"]).optional()
1196
1172
  });
1197
1173
 
1198
1174
  // src/genre-tree/api/genres/queryKeys.ts
@@ -1347,7 +1323,7 @@ function useUpdateGenre(scope, getBackendBaseUrl) {
1347
1323
  const refreshGenreTree = useRefreshGenreTree(scope);
1348
1324
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1349
1325
  const { mutate, mutateAsync, isPending, formErrors } = useValidatedMutation({
1350
- inputSchema: import_zod24.z.object({
1326
+ inputSchema: import_zod23.z.object({
1351
1327
  uuid: GenreUuidSchema,
1352
1328
  data: CriteriaUpdateSchema
1353
1329
  }),
@@ -1377,8 +1353,8 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1377
1353
  const refreshGenreTree = useRefreshGenreTree(scope);
1378
1354
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1379
1355
  return useValidatedMutation({
1380
- inputSchema: import_zod24.z.object({ uuid: GenreUuidSchema }),
1381
- outputSchema: import_zod24.z.null(),
1356
+ inputSchema: import_zod23.z.object({ uuid: GenreUuidSchema }),
1357
+ outputSchema: import_zod23.z.null(),
1382
1358
  mutationFn: async ({ uuid }) => {
1383
1359
  const endpoint = scope === "reference" ? genreEndpoints.reference.delete(uuid) : genreEndpoints.me.delete(uuid);
1384
1360
  return fetch2(endpoint, true, scope === "me", { method: "DELETE" }, void 0, false, true);
@@ -1388,16 +1364,16 @@ function useDeleteGenre(scope, getBackendBaseUrl) {
1388
1364
  }
1389
1365
 
1390
1366
  // src/genre-tree/useArtist.ts
1391
- var import_zod26 = require("zod");
1367
+ var import_zod25 = require("zod");
1392
1368
 
1393
1369
  // src/genre-tree/schemas/artist-detailed.ts
1394
- var import_zod25 = require("zod");
1395
- var ArtistMembershipSchema = import_zod25.z.object({
1370
+ var import_zod24 = require("zod");
1371
+ var ArtistMembershipSchema = import_zod24.z.object({
1396
1372
  artist: ArtistMinimumSchema,
1397
- beginYear: import_zod25.z.number().int().nullable(),
1398
- endYear: import_zod25.z.number().int().nullable(),
1399
- ended: import_zod25.z.boolean(),
1400
- roles: import_zod25.z.array(import_zod25.z.string())
1373
+ beginYear: import_zod24.z.number().int().nullable(),
1374
+ endYear: import_zod24.z.number().int().nullable(),
1375
+ ended: import_zod24.z.boolean(),
1376
+ roles: import_zod24.z.array(import_zod24.z.string())
1401
1377
  });
1402
1378
  var ARTIST_LINK_KINDS = [
1403
1379
  "official",
@@ -1410,35 +1386,35 @@ var ARTIST_LINK_KINDS = [
1410
1386
  "discogs",
1411
1387
  "social"
1412
1388
  ];
1413
- var ArtistImageSchema = import_zod25.z.object({
1389
+ var ArtistImageSchema = import_zod24.z.object({
1414
1390
  url: HttpUrlSchema,
1415
1391
  pageUrl: HttpUrlSchema,
1416
- author: import_zod25.z.string().nullable(),
1417
- license: import_zod25.z.string(),
1392
+ author: import_zod24.z.string().nullable(),
1393
+ license: import_zod24.z.string(),
1418
1394
  licenseUrl: HttpUrlSchema.nullable()
1419
1395
  });
1420
- var ArtistDetailedSchema = import_zod25.z.object({
1421
- uuid: import_zod25.z.string().uuid(),
1422
- name: import_zod25.z.string(),
1423
- musicbrainzArtistId: import_zod25.z.string().uuid().nullable(),
1424
- type: import_zod25.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1425
- country: import_zod25.z.string().nullable(),
1426
- beginYear: import_zod25.z.number().int().nullable(),
1427
- endYear: import_zod25.z.number().int().nullable(),
1428
- ended: import_zod25.z.boolean(),
1429
- links: import_zod25.z.array(import_zod25.z.object({ kind: import_zod25.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1430
- members: import_zod25.z.array(ArtistMembershipSchema),
1431
- memberOf: import_zod25.z.array(ArtistMembershipSchema),
1432
- albums: import_zod25.z.array(
1433
- import_zod25.z.object({
1434
- uuid: import_zod25.z.string().uuid(),
1435
- name: import_zod25.z.string(),
1436
- year: import_zod25.z.string().nullable(),
1437
- primaryType: import_zod25.z.string().nullable(),
1438
- secondaryTypes: import_zod25.z.array(import_zod25.z.string())
1396
+ var ArtistDetailedSchema = import_zod24.z.object({
1397
+ uuid: import_zod24.z.string().uuid(),
1398
+ name: import_zod24.z.string(),
1399
+ musicbrainzArtistId: import_zod24.z.string().uuid().nullable(),
1400
+ type: import_zod24.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1401
+ country: import_zod24.z.string().nullable(),
1402
+ beginYear: import_zod24.z.number().int().nullable(),
1403
+ endYear: import_zod24.z.number().int().nullable(),
1404
+ ended: import_zod24.z.boolean(),
1405
+ links: import_zod24.z.array(import_zod24.z.object({ kind: import_zod24.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
1406
+ members: import_zod24.z.array(ArtistMembershipSchema),
1407
+ memberOf: import_zod24.z.array(ArtistMembershipSchema),
1408
+ albums: import_zod24.z.array(
1409
+ import_zod24.z.object({
1410
+ uuid: import_zod24.z.string().uuid(),
1411
+ name: import_zod24.z.string(),
1412
+ year: import_zod24.z.string().nullable(),
1413
+ primaryType: import_zod24.z.string().nullable(),
1414
+ secondaryTypes: import_zod24.z.array(import_zod24.z.string())
1439
1415
  })
1440
1416
  ),
1441
- tracksCount: import_zod25.z.number().int(),
1417
+ tracksCount: import_zod24.z.number().int(),
1442
1418
  image: ArtistImageSchema.nullable()
1443
1419
  });
1444
1420
 
@@ -1461,7 +1437,7 @@ var artistEndpoints = {
1461
1437
  var isNotFound = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
1462
1438
  function useArtist(uuid, getBackendBaseUrl) {
1463
1439
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1464
- const isUuid = uuid !== null && import_zod26.z.string().uuid().safeParse(uuid).success;
1440
+ const isUuid = uuid !== null && import_zod25.z.string().uuid().safeParse(uuid).success;
1465
1441
  const { data, isPending, error } = useQueryWithParse({
1466
1442
  queryKey: artistQueryKeys.detail(uuid),
1467
1443
  // A missing artist is shown in the panel, not raised as an app-wide connectivity error.
@@ -1479,27 +1455,28 @@ function useArtist(uuid, getBackendBaseUrl) {
1479
1455
  }
1480
1456
 
1481
1457
  // src/genre-tree/schemas/artist-search.ts
1482
- var import_zod27 = require("zod");
1483
- var ArtistSearchResultSchema = import_zod27.z.object({
1484
- uuid: import_zod27.z.string().uuid(),
1485
- name: import_zod27.z.string(),
1486
- disambiguation: import_zod27.z.string().nullable(),
1487
- type: import_zod27.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1488
- country: import_zod27.z.string().nullable(),
1489
- beginYear: import_zod27.z.number().int().nullable(),
1490
- endYear: import_zod27.z.number().int().nullable(),
1491
- matchedAlias: import_zod27.z.string().nullable(),
1492
- recordingCount: import_zod27.z.number().int()
1458
+ var import_zod26 = require("zod");
1459
+ var ArtistSearchResultSchema = import_zod26.z.object({
1460
+ uuid: import_zod26.z.string().uuid(),
1461
+ name: import_zod26.z.string(),
1462
+ disambiguation: import_zod26.z.string().nullable(),
1463
+ type: import_zod26.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
1464
+ country: import_zod26.z.string().nullable(),
1465
+ beginYear: import_zod26.z.number().int().nullable(),
1466
+ endYear: import_zod26.z.number().int().nullable(),
1467
+ matchedAlias: import_zod26.z.string().nullable(),
1468
+ recordingCount: import_zod26.z.number().int()
1493
1469
  });
1494
- var ArtistSearchResultsSchema = import_zod27.z.array(ArtistSearchResultSchema);
1470
+ var ArtistSearchResultsSchema = import_zod26.z.array(ArtistSearchResultSchema);
1495
1471
 
1496
1472
  // src/genre-tree/useRemoteSearch.ts
1497
1473
  var import_react_query6 = require("@tanstack/react-query");
1498
1474
  var import_react7 = require("react");
1499
1475
  var SEARCH_DEBOUNCE_MS = 250;
1500
1476
  var SEARCH_QUERY_MIN_LENGTH = 2;
1501
- function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "" }) {
1502
- const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1477
+ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "", fetch: fetchOverride }) {
1478
+ const { fetch: plainFetch } = useFetchWrapper(getBackendBaseUrl);
1479
+ const fetch2 = fetchOverride ?? plainFetch;
1503
1480
  const trimmed = text.trim();
1504
1481
  const [query, setQuery] = (0, import_react7.useState)("");
1505
1482
  (0, import_react7.useEffect)(() => {
@@ -1547,6 +1524,94 @@ function useArtistSearch(getBackendBaseUrl, text) {
1547
1524
  // src/genre-tree/useSong.ts
1548
1525
  var import_zod29 = require("zod");
1549
1526
 
1527
+ // src/transport/lib/use-playback-query.ts
1528
+ var import_react10 = require("react");
1529
+
1530
+ // src/transport/PlaybackContext.tsx
1531
+ var import_react8 = require("react");
1532
+ var import_zod27 = require("zod");
1533
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1534
+ var PlaybackContextSchema = import_zod27.z.object({ country: import_zod27.z.string().regex(/^[A-Z]{2}$/).nullable() });
1535
+ var unmanaged = {
1536
+ country: null,
1537
+ key: null,
1538
+ ready: true,
1539
+ error: null,
1540
+ isCurrent: (_key) => true,
1541
+ snapshot: () => ({ key: null, country: null }),
1542
+ refresh: async (_force = false) => null
1543
+ };
1544
+ var PlaybackContext = (0, import_react8.createContext)(unmanaged);
1545
+ var usePlaybackContext = () => (0, import_react8.useContext)(PlaybackContext);
1546
+
1547
+ // src/transport/usePlaybackFetch.ts
1548
+ var import_react9 = require("react");
1549
+ var stale = () => new DOMException("Playback context changed", "AbortError");
1550
+ var usePlaybackFetch = (getBackendBaseUrl) => {
1551
+ const playback = usePlaybackContext();
1552
+ const { request } = useBackendRequest(getBackendBaseUrl);
1553
+ const run = (0, import_react9.useCallback)((adoptRefreshed, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError) => {
1554
+ const perform = async (retryContextChange) => {
1555
+ let requestContext = { key: playback.key, country: playback.country };
1556
+ await playback.refresh();
1557
+ if (adoptRefreshed) requestContext = playback.snapshot();
1558
+ if (!playback.isCurrent(requestContext.key)) throw stale();
1559
+ try {
1560
+ const result = await request(
1561
+ backendEndpointOrUrl,
1562
+ fromBackend,
1563
+ requiresAuth,
1564
+ options,
1565
+ queryParams,
1566
+ expectBinary,
1567
+ skipGlobalError,
1568
+ async (response) => {
1569
+ const responseCountry = response.headers.get("x-playback-country");
1570
+ if (playback.key !== null && responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
1571
+ await playback.refresh(true);
1572
+ throw stale();
1573
+ }
1574
+ if (!playback.isCurrent(requestContext.key)) throw stale();
1575
+ }
1576
+ );
1577
+ if (!playback.isCurrent(requestContext.key)) throw stale();
1578
+ return result;
1579
+ } catch (error) {
1580
+ if (retryContextChange && error instanceof DOMException && error.name === "AbortError" && !playback.isCurrent(requestContext.key)) {
1581
+ return perform(false);
1582
+ }
1583
+ throw error;
1584
+ }
1585
+ };
1586
+ return perform(adoptRefreshed);
1587
+ }, [playback, request]);
1588
+ const fetchBound = (0, import_react9.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(false, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
1589
+ const fetchLatest = (0, import_react9.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(true, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
1590
+ return { fetchBound, fetchLatest };
1591
+ };
1592
+
1593
+ // src/transport/lib/use-playback-query.ts
1594
+ function usePlaybackQuery({
1595
+ queryKey,
1596
+ getBackendBaseUrl,
1597
+ queryFn,
1598
+ enabled = true,
1599
+ retry,
1600
+ ...options
1601
+ }) {
1602
+ const playback = usePlaybackContext();
1603
+ const { fetchBound } = usePlaybackFetch(getBackendBaseUrl);
1604
+ const run = (0, import_react10.useCallback)((context) => queryFn(fetchBound, context), [queryFn, fetchBound]);
1605
+ return useQueryWithParse({
1606
+ ...options,
1607
+ queryKey: [...queryKey, ...playback.key ? [playback.key] : []],
1608
+ queryFn: run,
1609
+ enabled: typeof enabled === "function" ? (query) => playback.ready && enabled(query) : enabled && playback.ready,
1610
+ retry: (failureCount, error) => failureCount < 1 && error instanceof DOMException && error.name === "AbortError" || (retry?.(failureCount, error) ?? false),
1611
+ retryDelay: 0
1612
+ });
1613
+ }
1614
+
1550
1615
  // src/genre-tree/schemas/song/detailed.ts
1551
1616
  var import_zod28 = require("zod");
1552
1617
  var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
@@ -1592,15 +1657,14 @@ function musicBrainzRecordingUrl(song) {
1592
1657
  // src/genre-tree/useSong.ts
1593
1658
  var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
1594
1659
  function useSong(uuid, getBackendBaseUrl) {
1595
- const playback = usePlaybackContext();
1596
- const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1597
1660
  const isUuid = uuid !== null && import_zod29.z.string().uuid().safeParse(uuid).success;
1598
- const { data, isPending, error } = useQueryWithParse({
1599
- queryKey: [...libraryQueryKeys.reference.songs.detail(uuid), ...playback.key ? [playback.key] : []],
1661
+ const { data, isPending, error } = usePlaybackQuery({
1662
+ getBackendBaseUrl,
1663
+ queryKey: libraryQueryKeys.reference.songs.detail(uuid),
1600
1664
  // A missing song is shown in the panel, not raised as an app-wide connectivity error.
1601
- queryFn: ({ signal }) => fetch2(libraryEndpoints.reference.songs.detail(uuid), true, false, { signal }, void 0, false, true),
1665
+ queryFn: (fetchBound, { signal }) => fetchBound(libraryEndpoints.reference.songs.detail(uuid), true, false, { signal }, void 0, false, true),
1602
1666
  schema: SongDetailedSchema,
1603
- enabled: isUuid && playback.ready,
1667
+ enabled: isUuid,
1604
1668
  retry: (failureCount, retryError) => !isNotFound2(retryError) && failureCount < 3,
1605
1669
  context: "useSong"
1606
1670
  });
@@ -1625,11 +1689,11 @@ var SongHistorySchema = import_zod30.z.array(SongHistoryEntrySchema);
1625
1689
 
1626
1690
  // src/genre-tree/useSongHistory.ts
1627
1691
  function useSongHistory(uuid, getBackendBaseUrl, enabled) {
1628
- const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
1629
1692
  const active = enabled && uuid !== null;
1630
- const { data, isPending, error } = useQueryWithParse({
1693
+ const { data, isPending, error } = usePlaybackQuery({
1694
+ getBackendBaseUrl,
1631
1695
  queryKey: libraryQueryKeys.reference.songs.history(uuid),
1632
- queryFn: ({ signal }) => fetch2(libraryEndpoints.reference.songs.history(uuid), true, false, { signal }, void 0, false, true),
1696
+ queryFn: (fetchBound, { signal }) => fetchBound(libraryEndpoints.reference.songs.history(uuid), true, false, { signal }, void 0, false, true),
1633
1697
  schema: SongHistorySchema,
1634
1698
  enabled: active,
1635
1699
  context: "useSongHistory"
@@ -1663,10 +1727,12 @@ function isSongSearchResultPlayable(result) {
1663
1727
  var DEFAULT_RESULT_LIMIT = 8;
1664
1728
  function useSongSearch(getBackendBaseUrl, text, options = {}) {
1665
1729
  const playback = usePlaybackContext();
1730
+ const { fetchBound } = usePlaybackFetch(getBackendBaseUrl);
1666
1731
  const { limit = DEFAULT_RESULT_LIMIT, genre, playable } = options;
1667
1732
  const params = (q) => ({ q, limit, ...genre && { genre }, ...playable !== void 0 && { playable } });
1668
1733
  const { results, isError, settled, pending } = useRemoteSearch(getBackendBaseUrl, {
1669
1734
  queryKey: (q) => [...libraryQueryKeys.reference.songs.search(params(q)), ...playback.key ? [playback.key] : []],
1735
+ fetch: fetchBound,
1670
1736
  endpoint: libraryEndpoints.reference.songs.search(),
1671
1737
  params,
1672
1738
  schema: SongSearchResultsSchema,
@@ -1718,7 +1784,7 @@ function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
1718
1784
  }
1719
1785
 
1720
1786
  // src/genre-tree/useGenreSearch.ts
1721
- var import_react9 = require("react");
1787
+ var import_react12 = require("react");
1722
1788
 
1723
1789
  // src/genre-tree/lib/search-text.ts
1724
1790
  var foldSearchText = (text) => text.normalize("NFD").replace(/\p{M}+/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
@@ -1815,10 +1881,10 @@ function rankNameIndex(index, query, limit = Infinity) {
1815
1881
  }
1816
1882
 
1817
1883
  // src/genre-tree/useSearchQueryState.ts
1818
- var import_react8 = require("react");
1884
+ var import_react11 = require("react");
1819
1885
  function useSearchQueryState({ selectedName = null, onClear } = {}) {
1820
- const [query, setQuery] = (0, import_react8.useState)(selectedName ?? "");
1821
- const [prevSelectedName, setPrevSelectedName] = (0, import_react8.useState)(selectedName);
1886
+ const [query, setQuery] = (0, import_react11.useState)(selectedName ?? "");
1887
+ const [prevSelectedName, setPrevSelectedName] = (0, import_react11.useState)(selectedName);
1822
1888
  if (selectedName !== prevSelectedName) {
1823
1889
  setPrevSelectedName(selectedName);
1824
1890
  setQuery(selectedName ?? "");
@@ -1846,12 +1912,12 @@ function useGenreSearch({
1846
1912
  onClear
1847
1913
  }) {
1848
1914
  const { query, setQuery, isTyping, canClear, clear, notifyPick } = useSearchQueryState({ selectedName, onClear });
1849
- const index = (0, import_react9.useMemo)(
1915
+ const index = (0, import_react12.useMemo)(
1850
1916
  () => createNameIndex(genrePlaylists, (playlist) => playlist.name, (playlist) => playlist.viewsCount ?? 0),
1851
1917
  [genrePlaylists]
1852
1918
  );
1853
- const deferredQuery = (0, import_react9.useDeferredValue)(query);
1854
- const results = (0, import_react9.useMemo)(
1919
+ const deferredQuery = (0, import_react12.useDeferredValue)(query);
1920
+ const results = (0, import_react12.useMemo)(
1855
1921
  () => isTyping ? rankNameIndex(index, deferredQuery) : [],
1856
1922
  [index, deferredQuery, isTyping]
1857
1923
  );
@@ -1929,10 +1995,10 @@ function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
1929
1995
  }
1930
1996
 
1931
1997
  // src/genre-tree/useGenreTreeViewState.ts
1932
- var import_react11 = require("react");
1998
+ var import_react14 = require("react");
1933
1999
 
1934
2000
  // src/genre-tree/useVisibleGenrePlaylists.ts
1935
- var import_react10 = require("react");
2001
+ var import_react13 = require("react");
1936
2002
 
1937
2003
  // src/genre-tree/lib/prune-genre-playlists-for-artist.ts
1938
2004
  var POP_ROOT_NAME = "Mainstream Pop";
@@ -1970,15 +2036,22 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
1970
2036
 
1971
2037
  // src/genre-tree/useVisibleGenrePlaylists.ts
1972
2038
  function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null }) {
1973
- const { data: tree, isPending: isTreePending, isFetching: isTreeFetching } = useListFullGenrePlaylists(scope, getBackendBaseUrl);
2039
+ const { data: tree, isPending: isTreePending, isFetching: isTreeFetching, isError: isTreeError, refetch } = useListFullGenrePlaylists(scope, getBackendBaseUrl);
1974
2040
  const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
1975
2041
  const artistCounts = artistUuid !== null ? counts.data : void 0;
1976
2042
  const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
1977
- const genrePlaylists = (0, import_react10.useMemo)(() => {
2043
+ const genrePlaylists = (0, import_react13.useMemo)(() => {
1978
2044
  if (!tree) return [];
1979
2045
  return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
1980
2046
  }, [tree, artistCounts]);
1981
- return { isLoading: isTreePending, isFetching: isCountsLoading || !isTreePending && isTreeFetching, genrePlaylists };
2047
+ return {
2048
+ isLoading: isTreePending,
2049
+ // The tree failed with nothing cached to show; the host must say so rather than render an empty tree.
2050
+ isError: isTreeError && !tree,
2051
+ refetch,
2052
+ isFetching: isCountsLoading || !isTreePending && isTreeFetching,
2053
+ genrePlaylists
2054
+ };
1982
2055
  }
1983
2056
 
1984
2057
  // src/genre-tree/lib/genre-playlist-helpers.ts
@@ -1998,52 +2071,49 @@ function useGenreTreeViewState({
1998
2071
  getBackendBaseUrl,
1999
2072
  viewMode: controlledViewMode,
2000
2073
  artistUuid,
2001
- selectedNodeId: controlledSelectedNodeId,
2002
- onSelectedNodeIdChange,
2074
+ selectedGenreUuid: controlledSelectedGenreUuid,
2075
+ onSelectedGenreUuidChange,
2003
2076
  criteriaOverviewSchema
2004
2077
  }) {
2005
- const [internalViewMode, setInternalViewMode] = (0, import_react11.useState)("pop-core");
2006
- const [allowWheelRotation, setAllowWheelRotation] = (0, import_react11.useState)(false);
2007
- const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react11.useState)(null);
2008
- const isSelectionControlled = controlledSelectedNodeId !== void 0;
2009
- const requestedSelectedNodeId = isSelectionControlled ? controlledSelectedNodeId : internalSelectedNodeId;
2010
- const setSelectedNodeId = (0, import_react11.useCallback)(
2078
+ const [internalViewMode, setInternalViewMode] = (0, import_react14.useState)("pop-core");
2079
+ const [allowWheelRotation, setAllowWheelRotation] = (0, import_react14.useState)(false);
2080
+ const [internalSelectedGenreUuid, setInternalSelectedGenreUuid] = (0, import_react14.useState)(null);
2081
+ const isSelectionControlled = controlledSelectedGenreUuid !== void 0;
2082
+ const selectedGenreUuid = isSelectionControlled ? controlledSelectedGenreUuid : internalSelectedGenreUuid;
2083
+ const selectGenre = (0, import_react14.useCallback)(
2011
2084
  (nodeId) => {
2012
- if (!isSelectionControlled) setInternalSelectedNodeId(nodeId);
2013
- onSelectedNodeIdChange?.(nodeId);
2085
+ if (!isSelectionControlled) setInternalSelectedGenreUuid(nodeId);
2086
+ onSelectedGenreUuidChange?.(nodeId);
2014
2087
  },
2015
- [isSelectionControlled, onSelectedNodeIdChange]
2088
+ [isSelectionControlled, onSelectedGenreUuidChange]
2016
2089
  );
2017
- const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
2018
- const genrePlaylistByNodeId = (0, import_react11.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
2019
- const selectedGenrePlaylist = (0, import_react11.useMemo)(
2020
- () => genrePlaylists.find((gp) => gp.uuid === requestedSelectedNodeId) ?? // Older shared links stored the criteria UUID in `genre`; resolve that alias while preserving
2021
- // the playlist UUID as the canonical tree selection identity.
2022
- genrePlaylists.find((gp) => gp.criteria?.uuid === requestedSelectedNodeId),
2023
- [genrePlaylists, requestedSelectedNodeId]
2090
+ const { isLoading, isError, refetch, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
2091
+ const genrePlaylistByNodeId = (0, import_react14.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
2092
+ const selectedGenrePlaylist = (0, import_react14.useMemo)(
2093
+ () => genrePlaylists.find((gp) => gp.criteria?.uuid === selectedGenreUuid),
2094
+ [genrePlaylists, selectedGenreUuid]
2024
2095
  );
2025
- const selectedNodeId = selectedGenrePlaylist?.uuid ?? requestedSelectedNodeId;
2026
- (0, import_react11.useEffect)(() => {
2027
- if (!isSelectionControlled || requestedSelectedNodeId == null || selectedGenrePlaylist == null || requestedSelectedNodeId === selectedGenrePlaylist.uuid) {
2028
- return;
2096
+ const selectedNodeId = selectedGenrePlaylist?.uuid ?? null;
2097
+ const selectNode = (0, import_react14.useCallback)((node) => {
2098
+ if (!node) selectGenre(null);
2099
+ else {
2100
+ const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
2101
+ if (genreUuid) selectGenre(genreUuid);
2029
2102
  }
2030
- onSelectedNodeIdChange?.(selectedGenrePlaylist.uuid);
2031
- }, [isSelectionControlled, onSelectedNodeIdChange, requestedSelectedNodeId, selectedGenrePlaylist]);
2032
- const selectNode = (0, import_react11.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
2033
- const clearSelection = (0, import_react11.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
2034
- const selectGenrePlaylist = (0, import_react11.useCallback)(
2035
- (genrePlaylist) => setSelectedNodeId(genrePlaylist.uuid),
2036
- [setSelectedNodeId]
2037
- );
2103
+ }, [selectGenre, genrePlaylistByNodeId]);
2104
+ const clearSelection = (0, import_react14.useCallback)(() => selectGenre(null), [selectGenre]);
2105
+ const selectGenrePlaylist = (0, import_react14.useCallback)((playlist) => {
2106
+ if (playlist.criteria) selectGenre(playlist.criteria.uuid);
2107
+ }, [selectGenre]);
2038
2108
  const prefetchGenreOverview = usePrefetchGenreOverview(scope, getBackendBaseUrl, criteriaOverviewSchema);
2039
- const hoverPrefetchTimerRef = (0, import_react11.useRef)(null);
2040
- (0, import_react11.useEffect)(
2109
+ const hoverPrefetchTimerRef = (0, import_react14.useRef)(null);
2110
+ (0, import_react14.useEffect)(
2041
2111
  () => () => {
2042
2112
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
2043
2113
  },
2044
2114
  []
2045
2115
  );
2046
- const onNodeHover = (0, import_react11.useCallback)(
2116
+ const onNodeHover = (0, import_react14.useCallback)(
2047
2117
  (node) => {
2048
2118
  if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
2049
2119
  const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
@@ -2054,8 +2124,8 @@ function useGenreTreeViewState({
2054
2124
  },
2055
2125
  [genrePlaylistByNodeId, prefetchGenreOverview]
2056
2126
  );
2057
- const groupedGenrePlaylistsByRoot = (0, import_react11.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
2058
- const canShowPopCore = (0, import_react11.useMemo)(
2127
+ const groupedGenrePlaylistsByRoot = (0, import_react14.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
2128
+ const canShowPopCore = (0, import_react14.useMemo)(
2059
2129
  () => hasMainstreamPopRoot(
2060
2130
  genrePlaylists.map((genrePlaylist) => ({
2061
2131
  parentId: genrePlaylist.parent?.uuid ?? null,
@@ -2064,14 +2134,14 @@ function useGenreTreeViewState({
2064
2134
  ),
2065
2135
  [genrePlaylists]
2066
2136
  );
2067
- (0, import_react11.useEffect)(() => {
2068
- if (!isLoading && needsPopCore(internalViewMode) && !canShowPopCore) {
2137
+ (0, import_react14.useEffect)(() => {
2138
+ if (!isLoading && !isError && needsPopCore(internalViewMode) && !canShowPopCore) {
2069
2139
  setInternalViewMode("wheel");
2070
2140
  }
2071
- }, [isLoading, canShowPopCore, internalViewMode]);
2141
+ }, [isLoading, isError, canShowPopCore, internalViewMode]);
2072
2142
  const selectedViewMode = controlledViewMode ?? internalViewMode;
2073
2143
  const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
2074
- const visibleGenrePlaylists = (0, import_react11.useMemo)(() => {
2144
+ const visibleGenrePlaylists = (0, import_react14.useMemo)(() => {
2075
2145
  if (viewMode === "stacked") return genrePlaylists;
2076
2146
  const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
2077
2147
  const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
@@ -2079,11 +2149,15 @@ function useGenreTreeViewState({
2079
2149
  }, [genrePlaylists, viewMode]);
2080
2150
  return {
2081
2151
  isLoading,
2152
+ isError,
2153
+ refetch: () => void refetch(),
2082
2154
  isFetching,
2083
2155
  genrePlaylists,
2084
2156
  genrePlaylistByNodeId,
2085
2157
  visibleGenrePlaylists,
2086
2158
  groupedGenrePlaylistsByRoot,
2159
+ selectedGenreUuid,
2160
+ selectGenre,
2087
2161
  selectedNodeId,
2088
2162
  selectedGenrePlaylist,
2089
2163
  selectNode,
@@ -2100,7 +2174,7 @@ function useGenreTreeViewState({
2100
2174
  }
2101
2175
 
2102
2176
  // src/genre-tree/TrackListContext.tsx
2103
- var import_react14 = require("react");
2177
+ var import_react17 = require("react");
2104
2178
 
2105
2179
  // src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
2106
2180
  var import_zod35 = require("zod");
@@ -2232,16 +2306,16 @@ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
2232
2306
  };
2233
2307
 
2234
2308
  // src/player/PlayerContext.tsx
2235
- var import_react12 = require("react");
2309
+ var import_react15 = require("react");
2236
2310
 
2237
2311
  // src/player/PlaybackFailures.ts
2238
2312
  var TTL_MS = 10 * 6e4;
2239
2313
 
2240
2314
  // src/player/PlayerContext.tsx
2241
2315
  var import_jsx_runtime4 = require("react/jsx-runtime");
2242
- var PlayerContext = (0, import_react12.createContext)(void 0);
2316
+ var PlayerContext = (0, import_react15.createContext)(void 0);
2243
2317
  function usePlayer() {
2244
- const context = (0, import_react12.useContext)(PlayerContext);
2318
+ const context = (0, import_react15.useContext)(PlayerContext);
2245
2319
  if (context === void 0) {
2246
2320
  throw new Error("usePlayer must be used within a PlayerProvider");
2247
2321
  }
@@ -2249,21 +2323,21 @@ function usePlayer() {
2249
2323
  }
2250
2324
 
2251
2325
  // src/genre-tree/TrackListSidebarVisibilityContext.tsx
2252
- var import_react13 = require("react");
2326
+ var import_react16 = require("react");
2253
2327
  var import_jsx_runtime5 = require("react/jsx-runtime");
2254
- var TrackListSidebarVisibilityContext = (0, import_react13.createContext)(void 0);
2328
+ var TrackListSidebarVisibilityContext = (0, import_react16.createContext)(void 0);
2255
2329
  function TrackListSidebarVisibilityProvider({ children }) {
2256
- const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react13.useState)(false);
2257
- const toggleTrackListSidebar = (0, import_react13.useCallback)(() => {
2330
+ const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react16.useState)(false);
2331
+ const toggleTrackListSidebar = (0, import_react16.useCallback)(() => {
2258
2332
  setIsTrackListSidebarVisible((prev) => !prev);
2259
2333
  }, []);
2260
- const showTrackListSidebar = (0, import_react13.useCallback)(() => {
2334
+ const showTrackListSidebar = (0, import_react16.useCallback)(() => {
2261
2335
  setIsTrackListSidebarVisible(true);
2262
2336
  }, []);
2263
- const hideTrackListSidebar = (0, import_react13.useCallback)(() => {
2337
+ const hideTrackListSidebar = (0, import_react16.useCallback)(() => {
2264
2338
  setIsTrackListSidebarVisible(false);
2265
2339
  }, []);
2266
- const value = (0, import_react13.useMemo)(
2340
+ const value = (0, import_react16.useMemo)(
2267
2341
  () => ({
2268
2342
  isTrackListSidebarVisible,
2269
2343
  toggleTrackListSidebar,
@@ -2275,7 +2349,7 @@ function TrackListSidebarVisibilityProvider({ children }) {
2275
2349
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TrackListSidebarVisibilityContext.Provider, { value, children });
2276
2350
  }
2277
2351
  function useTrackListSidebarVisibility() {
2278
- const context = (0, import_react13.useContext)(TrackListSidebarVisibilityContext);
2352
+ const context = (0, import_react16.useContext)(TrackListSidebarVisibilityContext);
2279
2353
  if (context === void 0) {
2280
2354
  throw new Error("useTrackListSidebarVisibility must be used within a TrackListSidebarVisibilityProvider");
2281
2355
  }
@@ -2291,59 +2365,58 @@ function isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure) {
2291
2365
  return !runtimeUnplayableTrackIds.has(track.uuid) && (!isSong(track) || songUnplayableReason(track) === null && (!track.youtubeVideo || !hasPlaybackFailure(track.youtubeVideo.id)));
2292
2366
  }
2293
2367
  function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQueryKey, page = 1, pageSize = 50) {
2294
- const playback = usePlaybackContext();
2295
- const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2296
2368
  const { session, sessionRestored } = useSession();
2297
- return useQueryWithParse({
2298
- queryKey: [...listQueryKey(page), ...playback.key ? [playback.key] : []],
2299
- queryFn: async () => {
2369
+ return usePlaybackQuery({
2370
+ getBackendBaseUrl,
2371
+ queryKey: listQueryKey(page),
2372
+ queryFn: async (fetchBound) => {
2300
2373
  if (scope == null) return null;
2301
- return fetch2(listEndpoint(page), true, scope === "me", {}, { page, pageSize });
2374
+ return fetchBound(listEndpoint(page), true, scope === "me", {}, { page, pageSize });
2302
2375
  },
2303
2376
  schema: PaginatedResponseSchema(schema),
2304
2377
  context: "useListTracks",
2305
- enabled: playback.ready && scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
2378
+ enabled: scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
2306
2379
  });
2307
2380
  }
2308
- var TrackListContext = (0, import_react14.createContext)(void 0);
2381
+ var TrackListContext = (0, import_react17.createContext)(void 0);
2309
2382
  function TrackListProvider({
2310
2383
  children,
2311
2384
  getBackendBaseUrl,
2312
2385
  schema
2313
2386
  }) {
2314
- const [trackList, setTrackList] = (0, import_react14.useState)(null);
2315
- const [selectedTrack, setSelectedTrack] = (0, import_react14.useState)(null);
2316
- const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react14.useState)(null);
2387
+ const [trackList, setTrackList] = (0, import_react17.useState)(null);
2388
+ const [selectedTrack, setSelectedTrack] = (0, import_react17.useState)(null);
2389
+ const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react17.useState)(null);
2317
2390
  const { loadTrackForPlayer, setOnTrackEnd, hasPlaybackFailure, playerTrackObject } = usePlayer();
2318
- const [failureClock, setFailureClock] = (0, import_react14.useState)(0);
2319
- (0, import_react14.useEffect)(() => {
2391
+ const [failureClock, setFailureClock] = (0, import_react17.useState)(0);
2392
+ (0, import_react17.useEffect)(() => {
2320
2393
  const timer = setInterval(() => setFailureClock((tick) => tick + 1), 3e4);
2321
2394
  return () => clearInterval(timer);
2322
2395
  }, []);
2323
- const runtimeUnplayableTrackIds = (0, import_react14.useMemo)(() => new Set(
2396
+ const runtimeUnplayableTrackIds = (0, import_react17.useMemo)(() => new Set(
2324
2397
  (trackList?.tracks ?? []).filter((track) => isSong(track) && track.youtubeVideo && hasPlaybackFailure(track.youtubeVideo.id)).map((track) => track.uuid)
2325
2398
  ), [trackList, hasPlaybackFailure, playerTrackObject, failureClock]);
2326
2399
  const { showTrackListSidebar } = useTrackListSidebarVisibility();
2327
2400
  const playback = usePlaybackContext();
2328
- const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2329
- const pageSchema = (0, import_react14.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
2330
- const latestPlayRequestRef = (0, import_react14.useRef)(0);
2331
- const startingPlaybackRef = (0, import_react14.useRef)(false);
2332
- const loadedContextRef = (0, import_react14.useRef)(playback.key);
2333
- const autoAdvanceScrollRequestIdRef = (0, import_react14.useRef)(0);
2334
- const delayedTrackLoadRef = (0, import_react14.useRef)(null);
2335
- const loadingOriginRef = (0, import_react14.useRef)(null);
2336
- const pendingAdvanceRef = (0, import_react14.useRef)(null);
2337
- const clearDelayedTrackLoad = (0, import_react14.useCallback)(() => {
2401
+ const { fetchBound, fetchLatest } = usePlaybackFetch(getBackendBaseUrl);
2402
+ const pageSchema = (0, import_react17.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
2403
+ const latestPlayRequestRef = (0, import_react17.useRef)(0);
2404
+ const startingPlaybackRef = (0, import_react17.useRef)(false);
2405
+ const loadedContextRef = (0, import_react17.useRef)(playback.key);
2406
+ const autoAdvanceScrollRequestIdRef = (0, import_react17.useRef)(0);
2407
+ const delayedTrackLoadRef = (0, import_react17.useRef)(null);
2408
+ const loadingOriginRef = (0, import_react17.useRef)(null);
2409
+ const pendingAdvanceRef = (0, import_react17.useRef)(null);
2410
+ const clearDelayedTrackLoad = (0, import_react17.useCallback)(() => {
2338
2411
  if (delayedTrackLoadRef.current !== null) {
2339
2412
  clearTimeout(delayedTrackLoadRef.current);
2340
2413
  delayedTrackLoadRef.current = null;
2341
2414
  }
2342
2415
  }, []);
2343
- const requestAutoAdvanceScroll = (0, import_react14.useCallback)((trackUuid) => {
2416
+ const requestAutoAdvanceScroll = (0, import_react17.useCallback)((trackUuid) => {
2344
2417
  setAutoAdvanceScrollRequest({ id: ++autoAdvanceScrollRequestIdRef.current, trackUuid });
2345
2418
  }, []);
2346
- const loadTrackAfterSkipDelay = (0, import_react14.useCallback)(
2419
+ const loadTrackAfterSkipDelay = (0, import_react17.useCallback)(
2347
2420
  (trackUuid) => {
2348
2421
  clearDelayedTrackLoad();
2349
2422
  delayedTrackLoadRef.current = setTimeout(() => {
@@ -2353,12 +2426,12 @@ function TrackListProvider({
2353
2426
  },
2354
2427
  [clearDelayedTrackLoad, loadTrackForPlayer]
2355
2428
  );
2356
- const fetchTracksPage = (0, import_react14.useCallback)(
2429
+ const fetchTracksPage = (0, import_react17.useCallback)(
2357
2430
  async (uuid, scope, page, from, selection, artistUuid) => {
2358
2431
  const endpoint = genrePlaylistEndpoints[scope].tracks(uuid);
2359
2432
  if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
2360
2433
  const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
2361
- const response = await fetch2(endpoint, true, scope === "me", {}, params, false, !!from, page === 1);
2434
+ const response = await (page === 1 ? fetchLatest : fetchBound)(endpoint, true, scope === "me", {}, params, false, !!from);
2362
2435
  const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
2363
2436
  return {
2364
2437
  tracks: parsed.results.map((rel) => rel.track),
@@ -2366,10 +2439,10 @@ function TrackListProvider({
2366
2439
  nextPage: parsed.next ? parsed.page + 1 : null
2367
2440
  };
2368
2441
  },
2369
- [fetch2, pageSchema]
2442
+ [fetchBound, fetchLatest, pageSchema]
2370
2443
  );
2371
- const cataloguePageSchema = (0, import_react14.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2372
- const fetchCatalogueTracksPage = (0, import_react14.useCallback)(
2444
+ const cataloguePageSchema = (0, import_react17.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
2445
+ const fetchCatalogueTracksPage = (0, import_react17.useCallback)(
2373
2446
  async (origin, page) => {
2374
2447
  const params = {
2375
2448
  ...origin instanceof TrackListOriginFromArtist && { artist: origin.uuid },
@@ -2381,7 +2454,7 @@ function TrackListProvider({
2381
2454
  ...origin.genreUuid && { genre: origin.genreUuid },
2382
2455
  ...genreMusicQueryParams(origin.selection)
2383
2456
  };
2384
- const response = await fetch2(
2457
+ const response = await (page === 1 ? fetchLatest : fetchBound)(
2385
2458
  libraryEndpoints.reference.songs.list(),
2386
2459
  true,
2387
2460
  false,
@@ -2389,15 +2462,14 @@ function TrackListProvider({
2389
2462
  params,
2390
2463
  false,
2391
2464
  // A start song that isn't playable 404s; surface it as a rejection, not the global error.
2392
- page === 1 && !!origin.from,
2393
- page === 1
2465
+ page === 1 && !!origin.from
2394
2466
  );
2395
2467
  const parsed = parseWithLog(cataloguePageSchema, response, "fetchCatalogueTracksPage");
2396
2468
  return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
2397
2469
  },
2398
- [fetch2, cataloguePageSchema]
2470
+ [fetchBound, fetchLatest, cataloguePageSchema]
2399
2471
  );
2400
- const advanceAfterTrackEnd = (0, import_react14.useCallback)(
2472
+ const advanceAfterTrackEnd = (0, import_react17.useCallback)(
2401
2473
  (event) => {
2402
2474
  const completedTrackId = event?.trackId ?? selectedTrack?.uuid;
2403
2475
  if (!completedTrackId || !trackList) return;
@@ -2429,11 +2501,11 @@ function TrackListProvider({
2429
2501
  selectedTrack
2430
2502
  ]
2431
2503
  );
2432
- (0, import_react14.useEffect)(() => {
2504
+ (0, import_react17.useEffect)(() => {
2433
2505
  setOnTrackEnd(trackList && selectedTrack ? advanceAfterTrackEnd : null);
2434
2506
  return () => setOnTrackEnd(null);
2435
2507
  }, [advanceAfterTrackEnd, trackList, selectedTrack, setOnTrackEnd]);
2436
- const toTrackAtPosition = (0, import_react14.useCallback)(
2508
+ const toTrackAtPosition = (0, import_react17.useCallback)(
2437
2509
  (position) => {
2438
2510
  if (trackList && position >= 0 && position < trackList.tracks.length) {
2439
2511
  clearDelayedTrackLoad();
@@ -2443,7 +2515,7 @@ function TrackListProvider({
2443
2515
  },
2444
2516
  [clearDelayedTrackLoad, trackList]
2445
2517
  );
2446
- const playNewTrackListFromTrackUuid = (0, import_react14.useCallback)(
2518
+ const playNewTrackListFromTrackUuid = (0, import_react17.useCallback)(
2447
2519
  (track, scope) => {
2448
2520
  latestPlayRequestRef.current++;
2449
2521
  startingPlaybackRef.current = false;
@@ -2459,7 +2531,7 @@ function TrackListProvider({
2459
2531
  },
2460
2532
  [clearDelayedTrackLoad, showTrackListSidebar, loadTrackForPlayer]
2461
2533
  );
2462
- const playNewTrackListFromGenrePlaylist = (0, import_react14.useCallback)(
2534
+ const playNewTrackListFromGenrePlaylist = (0, import_react17.useCallback)(
2463
2535
  async (genrePlaylist, scope, options) => {
2464
2536
  clearDelayedTrackLoad();
2465
2537
  const request = ++latestPlayRequestRef.current;
@@ -2493,7 +2565,7 @@ function TrackListProvider({
2493
2565
  },
2494
2566
  [clearDelayedTrackLoad, fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
2495
2567
  );
2496
- const playCatalogue = (0, import_react14.useCallback)(
2568
+ const playCatalogue = (0, import_react17.useCallback)(
2497
2569
  async (origin) => {
2498
2570
  clearDelayedTrackLoad();
2499
2571
  const request = ++latestPlayRequestRef.current;
@@ -2526,7 +2598,7 @@ function TrackListProvider({
2526
2598
  },
2527
2599
  [clearDelayedTrackLoad, fetchCatalogueTracksPage, showTrackListSidebar, loadTrackForPlayer]
2528
2600
  );
2529
- const playNewTrackListFromArtist = (0, import_react14.useCallback)(
2601
+ const playNewTrackListFromArtist = (0, import_react17.useCallback)(
2530
2602
  async (artist, scope, options) => {
2531
2603
  if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
2532
2604
  if (options.selection && !options.genreUuid) throw new Error("A genre selection requires a genre");
@@ -2534,15 +2606,15 @@ function TrackListProvider({
2534
2606
  },
2535
2607
  [playCatalogue]
2536
2608
  );
2537
- const playNewTrackListFromGenreCatalogue = (0, import_react14.useCallback)(
2609
+ const playNewTrackListFromGenreCatalogue = (0, import_react17.useCallback)(
2538
2610
  async (genre, scope, options) => {
2539
2611
  if (scope !== "reference") throw new Error("Genre catalogues only support the reference scope");
2540
2612
  return playCatalogue(new TrackListOriginFromGenreCatalogue(genre, scope, options?.startSongUuid, options?.selection));
2541
2613
  },
2542
2614
  [playCatalogue]
2543
2615
  );
2544
- const contextKeyRef = (0, import_react14.useRef)(playback.key);
2545
- (0, import_react14.useEffect)(() => {
2616
+ const contextKeyRef = (0, import_react17.useRef)(playback.key);
2617
+ (0, import_react17.useEffect)(() => {
2546
2618
  if (contextKeyRef.current === playback.key) return;
2547
2619
  contextKeyRef.current = playback.key;
2548
2620
  if (loadedContextRef.current === playback.key) return;
@@ -2586,15 +2658,15 @@ function TrackListProvider({
2586
2658
  } else if (origin instanceof TrackListOriginFromTrack && selected) {
2587
2659
  const request = latestPlayRequestRef.current;
2588
2660
  void (async () => {
2589
- const track = isSong(selected) && origin.scope === "reference" ? parseWithLog(schema, await fetch2(libraryEndpoints.reference.songs.detail(selected.uuid), true, false), "refreshSelectedTrack") : selected;
2661
+ const track = isSong(selected) && origin.scope === "reference" ? parseWithLog(schema, await fetchBound(libraryEndpoints.reference.songs.detail(selected.uuid), true, false), "refreshSelectedTrack") : selected;
2590
2662
  if (request !== latestPlayRequestRef.current) return;
2591
2663
  setTrackList(new TrackListFromTrack([track], new TrackListOriginFromTrack(track, origin.scope)));
2592
2664
  setSelectedTrack(track);
2593
2665
  })().catch(() => {
2594
2666
  });
2595
2667
  }
2596
- }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetch2]);
2597
- const updateTrack = (0, import_react14.useCallback)((track) => {
2668
+ }, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetchBound]);
2669
+ const updateTrack = (0, import_react17.useCallback)((track) => {
2598
2670
  setTrackList((prev) => {
2599
2671
  if (!prev || !prev.tracks.some((listed) => listed.uuid === track.uuid)) return prev;
2600
2672
  const tracks = prev.tracks.map((listed) => listed.uuid === track.uuid ? track : listed);
@@ -2602,7 +2674,7 @@ function TrackListProvider({
2602
2674
  });
2603
2675
  setSelectedTrack((prev) => prev?.uuid === track.uuid ? track : prev);
2604
2676
  }, []);
2605
- const loadMore = (0, import_react14.useCallback)(async () => {
2677
+ const loadMore = (0, import_react17.useCallback)(async () => {
2606
2678
  if (!trackList || trackList.nextPage === null) return;
2607
2679
  const origin = trackList.origin;
2608
2680
  if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue)) return;
@@ -2626,7 +2698,7 @@ function TrackListProvider({
2626
2698
  const previousTrack = trackList && selectedTrackIndex > 0 ? trackList.tracks.slice(0, selectedTrackIndex).reverse().find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
2627
2699
  const hasNextTrack = nextTrack !== null || selectedTrackIndex >= 0 && trackList?.nextPage != null;
2628
2700
  const hasPreviousTrack = previousTrack !== null;
2629
- const playNextTrack = (0, import_react14.useCallback)(() => {
2701
+ const playNextTrack = (0, import_react17.useCallback)(() => {
2630
2702
  if (!trackList || !selectedTrack || selectedTrackIndex < 0) return;
2631
2703
  clearDelayedTrackLoad();
2632
2704
  if (nextTrack) {
@@ -2643,7 +2715,7 @@ function TrackListProvider({
2643
2715
  console.error("Failed to load more tracks:", error);
2644
2716
  });
2645
2717
  }, [clearDelayedTrackLoad, trackList, loadMore, loadTrackForPlayer, nextTrack, selectedTrack, selectedTrackIndex]);
2646
- const playPreviousTrack = (0, import_react14.useCallback)(() => {
2718
+ const playPreviousTrack = (0, import_react17.useCallback)(() => {
2647
2719
  if (!previousTrack) return;
2648
2720
  clearDelayedTrackLoad();
2649
2721
  pendingAdvanceRef.current = null;
@@ -2651,7 +2723,7 @@ function TrackListProvider({
2651
2723
  setSelectedTrack(previousTrack);
2652
2724
  loadTrackForPlayer(previousTrack.uuid);
2653
2725
  }, [clearDelayedTrackLoad, loadTrackForPlayer, previousTrack, requestAutoAdvanceScroll]);
2654
- (0, import_react14.useEffect)(() => {
2726
+ (0, import_react17.useEffect)(() => {
2655
2727
  const pending = pendingAdvanceRef.current;
2656
2728
  if (!pending) return;
2657
2729
  if (!trackList || trackList.origin !== pending.origin || selectedTrack?.uuid !== pending.trackId) {
@@ -2685,15 +2757,15 @@ function TrackListProvider({
2685
2757
  hasPlaybackFailure,
2686
2758
  selectedTrack
2687
2759
  ]);
2688
- (0, import_react14.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
2689
- (0, import_react14.useEffect)(() => {
2760
+ (0, import_react17.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
2761
+ (0, import_react17.useEffect)(() => {
2690
2762
  if (!trackList || trackList.nextPage === null || !selectedTrack) return;
2691
2763
  const index = trackList.tracks.findIndex((track) => track.uuid === selectedTrack.uuid);
2692
2764
  if (index !== -1 && trackList.tracks.length - index <= AUTO_LOAD_REMAINING_TRACKS) {
2693
2765
  loadMore().catch((error) => console.error("Failed to load more tracks:", error));
2694
2766
  }
2695
2767
  }, [trackList, selectedTrack, loadMore]);
2696
- const value = (0, import_react14.useMemo)(
2768
+ const value = (0, import_react17.useMemo)(
2697
2769
  () => ({
2698
2770
  trackList,
2699
2771
  selectedTrack,
@@ -2735,7 +2807,7 @@ function TrackListProvider({
2735
2807
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TrackListContext.Provider, { value, children });
2736
2808
  }
2737
2809
  function useTrackList() {
2738
- const context = (0, import_react14.useContext)(TrackListContext);
2810
+ const context = (0, import_react17.useContext)(TrackListContext);
2739
2811
  if (!context) {
2740
2812
  throw new Error("useTrackList must be used within a TrackListProvider");
2741
2813
  }
@@ -2743,14 +2815,14 @@ function useTrackList() {
2743
2815
  }
2744
2816
 
2745
2817
  // src/genre-tree/ArtistNames.tsx
2746
- var import_react15 = require("react");
2818
+ var import_react18 = require("react");
2747
2819
  var import_jsx_runtime7 = require("react/jsx-runtime");
2748
2820
  function ArtistNames({
2749
2821
  artists,
2750
2822
  renderArtistLink
2751
2823
  }) {
2752
2824
  if (!renderArtistLink) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist) => artist.name).join(", ") });
2753
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react15.Fragment, { children: [
2825
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react18.Fragment, { children: [
2754
2826
  index > 0 && ", ",
2755
2827
  renderArtistLink(artist)
2756
2828
  ] }, artist.uuid)) });