@behindthemusictree/app-kit 33.2.0 → 33.3.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.
@@ -3017,6 +3017,7 @@ type GenreSearchTreeName = z.infer<typeof GenreSearchTreeNameSchema>;
3017
3017
  declare const GenreSearchResultSchema: z.ZodObject<{
3018
3018
  uuid: z.core.$ZodBranded<z.ZodString, "GenreUuid", "out">;
3019
3019
  name: z.ZodString;
3020
+ wikidataId: z.ZodNullable<z.ZodString>;
3020
3021
  treeName: z.ZodString;
3021
3022
  genrePlaylistUuid: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "GenrePlaylistUuid", "out">>;
3022
3023
  root: z.ZodObject<{
@@ -3029,6 +3030,7 @@ declare const GenreSearchResultSchema: z.ZodObject<{
3029
3030
  declare const GenreSearchResultsSchema: z.ZodArray<z.ZodObject<{
3030
3031
  uuid: z.core.$ZodBranded<z.ZodString, "GenreUuid", "out">;
3031
3032
  name: z.ZodString;
3033
+ wikidataId: z.ZodNullable<z.ZodString>;
3032
3034
  treeName: z.ZodString;
3033
3035
  genrePlaylistUuid: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "GenrePlaylistUuid", "out">>;
3034
3036
  root: z.ZodObject<{
@@ -3093,8 +3095,11 @@ interface UseRemoteSearchOptions<TSchema extends z.ZodTypeAny> {
3093
3095
  text: string;
3094
3096
  /** Extra gate besides the minimum length, e.g. playback readiness. */
3095
3097
  enabled?: boolean;
3096
- /** Keep the previous results while the next query loads. */
3097
- keepPrevious?: boolean;
3098
+ /**
3099
+ * Previous results stay visible while the next query loads, but only while this scope is unchanged. Pass what
3100
+ * makes old results wrong for the new query (e.g. the playback key); omit it to always keep them.
3101
+ */
3102
+ scope?: string;
3098
3103
  }
3099
3104
  interface UseRemoteSearchResult<T> {
3100
3105
  results: T[];
@@ -3105,7 +3110,7 @@ interface UseRemoteSearchResult<T> {
3105
3110
  pending: boolean;
3106
3111
  }
3107
3112
  /** Debounced typeahead against a search endpoint; the shared core of the artist, song and genre searches. */
3108
- declare function useRemoteSearch<TSchema extends z.ZodType<unknown[]>>(getBackendBaseUrl: () => string, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled, keepPrevious }: UseRemoteSearchOptions<TSchema>): UseRemoteSearchResult<z.infer<TSchema>[number]>;
3113
+ declare function useRemoteSearch<TSchema extends z.ZodType<unknown[]>>(getBackendBaseUrl: () => string, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled, scope }: UseRemoteSearchOptions<TSchema>): UseRemoteSearchResult<z.infer<TSchema>[number]>;
3109
3114
 
3110
3115
  interface UseSearchQueryStateOptions {
3111
3116
  /** Name of the currently selected item; fills the query whenever it changes. */
@@ -108,7 +108,7 @@ import {
108
108
  useTrackListSidebarVisibility,
109
109
  useUpdateGenre,
110
110
  useVisibleGenrePlaylists
111
- } from "../chunk-727PIKKR.js";
111
+ } from "../chunk-HHE6VK67.js";
112
112
  import "../chunk-4TE4OSOM.js";
113
113
  import "../chunk-T5D5T52J.js";
114
114
  import "../chunk-4MEK3CNF.js";
package/dist/index.cjs CHANGED
@@ -2640,7 +2640,7 @@ var import_react_query6 = require("@tanstack/react-query");
2640
2640
  var import_react14 = require("react");
2641
2641
  var SEARCH_DEBOUNCE_MS = 250;
2642
2642
  var SEARCH_QUERY_MIN_LENGTH = 2;
2643
- function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, keepPrevious = true }) {
2643
+ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "" }) {
2644
2644
  const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
2645
2645
  const trimmed = text.trim();
2646
2646
  const [query, setQuery] = (0, import_react14.useState)("");
@@ -2648,15 +2648,19 @@ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema
2648
2648
  const timer = setTimeout(() => setQuery(trimmed), SEARCH_DEBOUNCE_MS);
2649
2649
  return () => clearTimeout(timer);
2650
2650
  }, [trimmed]);
2651
+ const dataScope = (0, import_react14.useRef)(null);
2651
2652
  const enabled = query.length >= SEARCH_QUERY_MIN_LENGTH && extraEnabled;
2652
- const { data, isFetching, isError } = useQueryWithParse({
2653
+ const { data, isFetching, isError, isPlaceholderData } = useQueryWithParse({
2653
2654
  queryKey: queryKey(query),
2654
2655
  queryFn: ({ signal }) => fetch2(endpoint, true, false, { signal }, params(query)),
2655
2656
  schema,
2656
2657
  context,
2657
2658
  enabled,
2658
- placeholderData: keepPrevious ? import_react_query6.keepPreviousData : void 0
2659
+ placeholderData: (previous) => dataScope.current === scope ? (0, import_react_query6.keepPreviousData)(previous) : void 0
2659
2660
  });
2661
+ (0, import_react14.useEffect)(() => {
2662
+ if (data !== void 0 && !isPlaceholderData) dataScope.current = scope;
2663
+ }, [data, isPlaceholderData, scope]);
2660
2664
  const settled = enabled && !isFetching && query === trimmed;
2661
2665
  const failed = enabled && isError;
2662
2666
  const long = trimmed.length >= SEARCH_QUERY_MIN_LENGTH;
@@ -2811,7 +2815,7 @@ function useSongSearch(getBackendBaseUrl, text, options = {}) {
2811
2815
  context: "useSongSearch",
2812
2816
  text,
2813
2817
  enabled: playback.ready,
2814
- keepPrevious: playback.key === null
2818
+ scope: playback.key ?? ""
2815
2819
  });
2816
2820
  return { songs: results, isError, settled, pending };
2817
2821
  }
@@ -2948,6 +2952,8 @@ var GenreSearchResultSchema = import_zod33.z.object({
2948
2952
  /** Criteria (genre) uuid. */
2949
2953
  uuid: GenreUuidSchema,
2950
2954
  name: import_zod33.z.string(),
2955
+ /** Null for app-created genres, which the Wikidata-keyed region index does not reference. */
2956
+ wikidataId: import_zod33.z.string().nullable(),
2951
2957
  treeName: import_zod33.z.string(),
2952
2958
  /** Null when the genre has no playlist in the tree, so it cannot be opened there. */
2953
2959
  genrePlaylistUuid: GenrePlaylistUuidSchema.nullable(),