ChemPal Documentation - v1.6.0
    Preparing search index...

    Function countActiveSearchFilters

    • Count how many of the advanced search drawer's filters are set to a non-default value: the selected-suppliers, country, shipping, and availability lists when non-empty, plus the price range when either bound is set. A price min and max count as a single filter (the price range), mirroring how the drawer groups them. Boolean behavior toggles and the results limit are intentionally excluded — this counts the discrete filter categories, matching the drawer's sections.

      Parameters

      • params: {
            selectedSuppliers?: readonly string[];
            searchFilters: Pick<
                SearchFilters,
                "availability"
                | "country"
                | "shippingType",
            >;
            userSettings: Pick<UserSettings, "priceMin" | "priceMax">;
        }

        The current advanced-search filter state (from the app context).

      Returns number

      The number of active filters; 0 when every filter is at its default.

      countActiveSearchFilters({
      selectedSuppliers: ['Loudwolf'],
      searchFilters: { availability: [], country: [], shippingType: [] },
      userSettings: { priceMin: 10 },
      }); // => 2 (suppliers + price range)
      export function countActiveSearchFilters(params: {
      selectedSuppliers?: readonly string[];
      searchFilters: Pick<SearchFilters, 'availability' | 'country' | 'shippingType'>;
      userSettings: Pick<UserSettings, 'priceMin' | 'priceMax'>;
      }): number {
      const { selectedSuppliers = [], searchFilters, userSettings } = params;
      let count = 0;
      if (selectedSuppliers.length > 0) count += 1;
      if (searchFilters.country.length > 0) count += 1;
      if (searchFilters.shippingType.length > 0) count += 1;
      if (searchFilters.availability.length > 0) count += 1;
      if (userSettings.priceMin != null || userSettings.priceMax != null) count += 1;
      return count;
      }