@wix/headless-bookings 0.0.45 → 0.0.46

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.
@@ -5,6 +5,7 @@ import type { Service } from '@wix/auto_sdk_bookings_services';
5
5
  import type { ServiceServiceConfig } from '../services/service/service.js';
6
6
  import type { ServiceListServiceConfig } from '../services/service-list/service-list.js';
7
7
  import type { PagingMetadata } from '../api/query-services/index.js';
8
+ import type { Category } from '../api/query-categories/index.js';
8
9
  /**
9
10
  * Booking app ID constant
10
11
  */
@@ -73,3 +74,23 @@ export declare const mockServiceConfig: ServiceServiceConfig;
73
74
  * Helper to create a large list of services for pagination tests
74
75
  */
75
76
  export declare function createLargeServiceList(count: number): Service[];
77
+ /**
78
+ * Mock categories for filter tests
79
+ */
80
+ export declare const mockCategories: Category[];
81
+ /**
82
+ * Empty categories array
83
+ */
84
+ export declare const mockEmptyCategories: Category[];
85
+ /**
86
+ * Service list config with categories for filter testing
87
+ */
88
+ export declare const mockServiceListConfigWithCategories: ServiceListServiceConfig;
89
+ /**
90
+ * Service list config with categories and hasNext for pagination + filter testing
91
+ */
92
+ export declare const mockServiceListConfigWithCategoriesAndMore: ServiceListServiceConfig;
93
+ /**
94
+ * Empty service list config with categories
95
+ */
96
+ export declare const mockEmptyServiceListConfigWithCategories: ServiceListServiceConfig;
@@ -306,3 +306,57 @@ export function createLargeServiceList(count) {
306
306
  },
307
307
  }));
308
308
  }
309
+ /**
310
+ * Mock categories for filter tests
311
+ */
312
+ export const mockCategories = [
313
+ {
314
+ _id: 'category-1',
315
+ name: 'Wellness',
316
+ },
317
+ {
318
+ _id: 'category-2',
319
+ name: 'Fitness',
320
+ },
321
+ {
322
+ _id: 'category-3',
323
+ name: 'Beauty',
324
+ },
325
+ ];
326
+ /**
327
+ * Empty categories array
328
+ */
329
+ export const mockEmptyCategories = [];
330
+ /**
331
+ * Service list config with categories for filter testing
332
+ */
333
+ export const mockServiceListConfigWithCategories = {
334
+ services: mockServices,
335
+ categories: mockCategories,
336
+ options: {
337
+ appId: BOOKING_APP_ID,
338
+ pagingMetadata: mockPagingMetadata,
339
+ },
340
+ };
341
+ /**
342
+ * Service list config with categories and hasNext for pagination + filter testing
343
+ */
344
+ export const mockServiceListConfigWithCategoriesAndMore = {
345
+ services: mockServices,
346
+ categories: mockCategories,
347
+ options: {
348
+ appId: BOOKING_APP_ID,
349
+ pagingMetadata: mockPagingMetadataWithMore,
350
+ },
351
+ };
352
+ /**
353
+ * Empty service list config with categories
354
+ */
355
+ export const mockEmptyServiceListConfigWithCategories = {
356
+ services: [],
357
+ categories: mockCategories,
358
+ options: {
359
+ appId: BOOKING_APP_ID,
360
+ pagingMetadata: mockPagingMetadataEmpty,
361
+ },
362
+ };
@@ -9,6 +9,7 @@ export { fetchAvailability } from './fetch-availability/index.js';
9
9
  export { createBooking, type CreateBookingOptions, type Booking, type CreateBookingRequest, type CreateBookingResponse, type ParticipantNotification, type ContactDetails, } from './create-booking/index.js';
10
10
  export { createCheckout, ChannelType, type CreateCheckoutRequest, type CreateCheckoutResponse, } from './create-checkout/index.js';
11
11
  export { queryLocations, type QueryLocationsResult, type LocationData, } from './query-locations/index.js';
12
+ export { queryCategories, type QueryCategoriesResult, type Category, } from './query-categories/index.js';
12
13
  /**
13
14
  * PagingMetadata includes:
14
15
  * - limit: Number of items per page
@@ -9,6 +9,7 @@ export { fetchAvailability } from './fetch-availability/index.js';
9
9
  export { createBooking, } from './create-booking/index.js';
10
10
  export { createCheckout, ChannelType, } from './create-checkout/index.js';
11
11
  export { queryLocations, } from './query-locations/index.js';
12
+ export { queryCategories, } from './query-categories/index.js';
12
13
  /**
13
14
  * PagingMetadata includes:
14
15
  * - limit: Number of items per page
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Query Categories API
3
+ * Fetches booking service categories from Wix Bookings
4
+ *
5
+ * @module API/QueryCategories
6
+ */
7
+ import { categoriesV2 } from '@wix/bookings';
8
+ /**
9
+ * Category type from the Wix Bookings Categories V2 API
10
+ */
11
+ export type Category = categoriesV2.Category;
12
+ /**
13
+ * Result from querying categories
14
+ */
15
+ export interface QueryCategoriesResult {
16
+ /** Array of booking service categories */
17
+ categories: Category[];
18
+ }
19
+ /**
20
+ * Query all booking service categories.
21
+ * Returns an array of categories sorted by creation date (ascending).
22
+ *
23
+ * @returns Promise resolving to categories array
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const { categories } = await queryCategories();
28
+ *
29
+ * categories.forEach(category => {
30
+ * console.log(category.name, category._id);
31
+ * });
32
+ * ```
33
+ */
34
+ export declare function queryCategories(): Promise<QueryCategoriesResult>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Query Categories API
3
+ * Fetches booking service categories from Wix Bookings
4
+ *
5
+ * @module API/QueryCategories
6
+ */
7
+ import { categoriesV2 } from '@wix/bookings';
8
+ /**
9
+ * Query all booking service categories.
10
+ * Returns an array of categories sorted by creation date (ascending).
11
+ *
12
+ * @returns Promise resolving to categories array
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { categories } = await queryCategories();
17
+ *
18
+ * categories.forEach(category => {
19
+ * console.log(category.name, category._id);
20
+ * });
21
+ * ```
22
+ */
23
+ export async function queryCategories() {
24
+ const result = await categoriesV2.queryCategories().find();
25
+ return {
26
+ categories: result.items || [],
27
+ };
28
+ }
@@ -74,8 +74,15 @@ const buildServicesQueryRequest = ({ appId, filters, paging, sort, }) => {
74
74
  if (filters?.serviceIds && filters.serviceIds.length > 0) {
75
75
  filter['_id'] = { $in: filters.serviceIds };
76
76
  }
77
- // Add other filters as they are implemented in future phases
78
- // categoryIds, locationIds, staffMemberIds to be added later
77
+ // Add categoryIds filter if provided
78
+ if (filters?.categoryIds && filters.categoryIds.length > 0) {
79
+ filter['category.id'] = { $in: filters.categoryIds };
80
+ }
81
+ // Add locationIds filter if provided
82
+ if (filters?.locationIds && filters.locationIds.length > 0) {
83
+ filter['locations.business.id'] = { $hasSome: filters.locationIds };
84
+ }
85
+ // staffMemberIds to be added later
79
86
  const query = {
80
87
  filter: Object.keys(filter).length > 0 ? filter : undefined,
81
88
  paging: paging || {
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Core ServiceListFilter Components
3
+ * Provides render props for filter data from ServiceListService and BookingService
4
+ */
5
+ import React from 'react';
6
+ import type { FilterOption } from '@wix/headless-components/react';
7
+ import { type ServiceListFilters } from '../../../services/service-list/service-list.js';
8
+ /**
9
+ * Render props for the Root component
10
+ */
11
+ export interface RootRenderProps {
12
+ /** Filter options configuration derived from categories */
13
+ filterOptions: FilterOption[];
14
+ /** Current filter state */
15
+ currentFilter: ServiceListFilters | null;
16
+ /** Function to update filter (includes location from BookingService) */
17
+ updateFilter: (filter: ServiceListFilters) => void;
18
+ /** Function to clear all filters */
19
+ clearFilters: () => void;
20
+ /** Whether any filters are active */
21
+ isFiltered: boolean;
22
+ }
23
+ /**
24
+ * Props for the Root component
25
+ */
26
+ export interface RootProps {
27
+ /** Render function that receives filter data */
28
+ children: (props: RootRenderProps) => React.ReactNode;
29
+ }
30
+ /**
31
+ * Core render props component that provides filter data from services.
32
+ * Reads categories from ServiceListService and location from BookingService.
33
+ *
34
+ * @component
35
+ * @example
36
+ * ```tsx
37
+ * <ServiceListFilter.Root>
38
+ * {({ filterOptions, currentFilter, updateFilter, clearFilters, isFiltered }) => (
39
+ * <Filter.Root
40
+ * value={currentFilter}
41
+ * onChange={updateFilter}
42
+ * filterOptions={filterOptions}
43
+ * >
44
+ * <Filter.FilterOptions>
45
+ * <Filter.FilterOptionRepeater>
46
+ * <Filter.FilterOption.Label />
47
+ * <Filter.FilterOption.SingleFilter />
48
+ * </Filter.FilterOptionRepeater>
49
+ * </Filter.FilterOptions>
50
+ * </Filter.Root>
51
+ * )}
52
+ * </ServiceListFilter.Root>
53
+ * ```
54
+ */
55
+ export declare function Root(props: RootProps): React.ReactNode;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Core ServiceListFilter Components
3
+ * Provides render props for filter data from ServiceListService and BookingService
4
+ */
5
+ import { useService } from '@wix/services-manager-react';
6
+ import { ServiceListServiceDefinition, } from '../../../services/service-list/service-list.js';
7
+ import { BookingServiceDefinition } from '../../../services/booking/booking.js';
8
+ /**
9
+ * Core render props component that provides filter data from services.
10
+ * Reads categories from ServiceListService and location from BookingService.
11
+ *
12
+ * @component
13
+ * @example
14
+ * ```tsx
15
+ * <ServiceListFilter.Root>
16
+ * {({ filterOptions, currentFilter, updateFilter, clearFilters, isFiltered }) => (
17
+ * <Filter.Root
18
+ * value={currentFilter}
19
+ * onChange={updateFilter}
20
+ * filterOptions={filterOptions}
21
+ * >
22
+ * <Filter.FilterOptions>
23
+ * <Filter.FilterOptionRepeater>
24
+ * <Filter.FilterOption.Label />
25
+ * <Filter.FilterOption.SingleFilter />
26
+ * </Filter.FilterOptionRepeater>
27
+ * </Filter.FilterOptions>
28
+ * </Filter.Root>
29
+ * )}
30
+ * </ServiceListFilter.Root>
31
+ * ```
32
+ */
33
+ export function Root(props) {
34
+ const serviceListService = useService(ServiceListServiceDefinition);
35
+ const bookingService = useService(BookingServiceDefinition);
36
+ // Get reactive data from signals
37
+ const filterOptions = serviceListService.filterOptionsSignal.get();
38
+ const currentFilter = serviceListService.filterSignal.get();
39
+ const isFiltered = serviceListService.isFilteredSignal.get();
40
+ const selectedLocation = bookingService.location.get();
41
+ const updateFilter = (newFilter) => {
42
+ // Include locationId from BookingService in the filter
43
+ const locationId = selectedLocation?.business?._id;
44
+ serviceListService.actions.setFilter({
45
+ ...newFilter,
46
+ ...(locationId ? { locationIds: [locationId] } : {}),
47
+ });
48
+ };
49
+ const clearFilters = () => {
50
+ serviceListService.actions.resetFilter();
51
+ };
52
+ return props.children({
53
+ filterOptions,
54
+ currentFilter,
55
+ updateFilter,
56
+ clearFilters,
57
+ isFiltered,
58
+ });
59
+ }
@@ -3,7 +3,7 @@
3
3
  * Provides components for displaying services list with pagination
4
4
  */
5
5
  import React from 'react';
6
- import { ListVariant, GenericListLoadMoreRenderProps } from '@wix/headless-components/react';
6
+ import { ListVariant, GenericListLoadMoreRenderProps, Filter as FilterPrimitive } from '@wix/headless-components/react';
7
7
  import { AsChildChildren } from '@wix/headless-utils/react';
8
8
  import type { ServiceListServiceConfig } from '../../services/service-list/service-list.js';
9
9
  import type { Service as ServiceType } from '@wix/auto_sdk_bookings_services';
@@ -185,3 +185,64 @@ export declare const LoadMore: React.ForwardRefExoticComponent<LoadMoreProps & R
185
185
  export declare const Actions: {
186
186
  LoadMore: React.ForwardRefExoticComponent<LoadMoreProps & React.RefAttributes<HTMLButtonElement>>;
187
187
  };
188
+ /**
189
+ * Data available through asChild pattern
190
+ */
191
+ export interface FilterAsChildProps {
192
+ /** Filter options configuration derived from categories */
193
+ filterOptions: FilterPrimitive.FilterOption[];
194
+ /** Current filter state */
195
+ currentFilter: FilterPrimitive.Filter;
196
+ /** Function to update filter */
197
+ updateFilter: (filter: FilterPrimitive.Filter) => void;
198
+ /** Function to clear all active filters */
199
+ clearFilters: () => void;
200
+ /** Whether any filters are currently active */
201
+ isFiltered: boolean;
202
+ }
203
+ /**
204
+ * Props for ServiceList Filter component
205
+ */
206
+ export interface FilterProps {
207
+ /** Child components that will have access to filter functionality */
208
+ children: React.ReactNode | ((props: FilterAsChildProps) => React.ReactNode);
209
+ /** When true, the component will not render its own div wrapper */
210
+ asChild?: boolean;
211
+ /** CSS classes to apply to the filter container */
212
+ className?: string;
213
+ }
214
+ /**
215
+ * Filter component that provides filtering functionality for service lists.
216
+ * Integrates with ServiceListService for categories and BookingService for location.
217
+ *
218
+ * @component
219
+ * @example
220
+ * ```tsx
221
+ * import { Filter } from '@wix/headless-components/react';
222
+ *
223
+ * <ServiceList.Filter className="filter-sidebar">
224
+ * <Filter.FilterOptions>
225
+ * <Filter.FilterOptionRepeater>
226
+ * <Filter.FilterOption.Label />
227
+ * <Filter.FilterOption.SingleFilter />
228
+ * </Filter.FilterOptionRepeater>
229
+ * </Filter.FilterOptions>
230
+ * <Filter.Filtered>
231
+ * <Filter.Action.Clear label="Clear Filters" />
232
+ * </Filter.Filtered>
233
+ * </ServiceList.Filter>
234
+ *
235
+ * // With asChild pattern
236
+ * <ServiceList.Filter asChild>
237
+ * <aside className="filter-sidebar">
238
+ * <Filter.FilterOptions>
239
+ * <Filter.FilterOptionRepeater>
240
+ * <Filter.FilterOption.Label />
241
+ * <Filter.FilterOption.SingleFilter />
242
+ * </Filter.FilterOptionRepeater>
243
+ * </Filter.FilterOptions>
244
+ * </aside>
245
+ * </ServiceList.Filter>
246
+ * ```
247
+ */
248
+ export declare const Filter: React.ForwardRefExoticComponent<FilterProps & React.RefAttributes<HTMLElement>>;
@@ -4,8 +4,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  * Provides components for displaying services list with pagination
5
5
  */
6
6
  import React from 'react';
7
- import { GenericList, } from '@wix/headless-components/react';
7
+ import { GenericList, Filter as FilterPrimitive, } from '@wix/headless-components/react';
8
+ import { AsChildSlot } from '@wix/headless-utils/react';
8
9
  import * as CoreServiceList from '../core/service-list/ServiceList.js';
10
+ import * as CoreServiceListFilter from '../core/service-list/ServiceListFilter.js';
9
11
  import * as Service from '../service/Service.js';
10
12
  /**
11
13
  * Booking app ID constant
@@ -17,6 +19,7 @@ var TestIds;
17
19
  TestIds["serviceListServices"] = "service-list-services";
18
20
  TestIds["serviceListService"] = "service-list-service";
19
21
  TestIds["serviceListLoadMore"] = "service-list-load-more";
22
+ TestIds["serviceListFilter"] = "service-list-filter";
20
23
  })(TestIds || (TestIds = {}));
21
24
  /**
22
25
  * Root component that provides the ServiceList service context for rendering services lists.
@@ -170,3 +173,52 @@ LoadMore.displayName = 'ServiceList.Actions.LoadMore';
170
173
  export const Actions = {
171
174
  LoadMore,
172
175
  };
176
+ /**
177
+ * Filter component that provides filtering functionality for service lists.
178
+ * Integrates with ServiceListService for categories and BookingService for location.
179
+ *
180
+ * @component
181
+ * @example
182
+ * ```tsx
183
+ * import { Filter } from '@wix/headless-components/react';
184
+ *
185
+ * <ServiceList.Filter className="filter-sidebar">
186
+ * <Filter.FilterOptions>
187
+ * <Filter.FilterOptionRepeater>
188
+ * <Filter.FilterOption.Label />
189
+ * <Filter.FilterOption.SingleFilter />
190
+ * </Filter.FilterOptionRepeater>
191
+ * </Filter.FilterOptions>
192
+ * <Filter.Filtered>
193
+ * <Filter.Action.Clear label="Clear Filters" />
194
+ * </Filter.Filtered>
195
+ * </ServiceList.Filter>
196
+ *
197
+ * // With asChild pattern
198
+ * <ServiceList.Filter asChild>
199
+ * <aside className="filter-sidebar">
200
+ * <Filter.FilterOptions>
201
+ * <Filter.FilterOptionRepeater>
202
+ * <Filter.FilterOption.Label />
203
+ * <Filter.FilterOption.SingleFilter />
204
+ * </Filter.FilterOptionRepeater>
205
+ * </Filter.FilterOptions>
206
+ * </aside>
207
+ * </ServiceList.Filter>
208
+ * ```
209
+ */
210
+ export const Filter = React.forwardRef((props, ref) => {
211
+ const { children, asChild, className, ...otherProps } = props;
212
+ return (_jsx(CoreServiceListFilter.Root, { children: ({ filterOptions, currentFilter, updateFilter, clearFilters, isFiltered, }) => {
213
+ // Prepare asChildProps for function children
214
+ const asChildProps = {
215
+ filterOptions,
216
+ currentFilter: currentFilter,
217
+ updateFilter: (value) => updateFilter(value),
218
+ clearFilters,
219
+ isFiltered,
220
+ };
221
+ return (_jsx(FilterPrimitive.Root, { value: currentFilter, onChange: (value) => updateFilter(value), filterOptions: filterOptions, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.serviceListFilter, "data-is-filtered": isFiltered, customElement: children, customElementProps: asChildProps, ...otherProps, children: children }) }));
222
+ } }));
223
+ });
224
+ Filter.displayName = 'ServiceList.Filter';
@@ -4,7 +4,9 @@
4
4
  */
5
5
  import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
6
6
  import type { Service } from '@wix/auto_sdk_bookings_services';
7
- import type { QueryServicesRequest, PagingMetadata } from '../../api/query-services/index.js';
7
+ import type { QueryServicesRequest, PagingMetadata, ServiceListFilters } from '../../api/query-services/index.js';
8
+ import { type Category } from '../../api/query-categories/index.js';
9
+ import type { FilterOption } from '@wix/headless-components/react';
8
10
  export type { ServiceListFilters } from '../../api/query-services/index.js';
9
11
  /**
10
12
  * Query options without paging metadata (user-controlled request params)
@@ -16,6 +18,7 @@ export type QueryOptions = Omit<QueryServicesRequest, 'pagingMetadata'>;
16
18
  */
17
19
  export interface ServiceListServiceConfig {
18
20
  services?: Service[];
21
+ categories?: Category[];
19
22
  options?: QueryServicesRequest;
20
23
  }
21
24
  /**
@@ -24,6 +27,8 @@ export interface ServiceListServiceConfig {
24
27
  export interface ServiceListActions {
25
28
  loadMore: (count: number) => Promise<void>;
26
29
  setQueryOptions: (options: QueryOptions) => void;
30
+ setFilter: (filter: ServiceListFilters) => void;
31
+ resetFilter: () => void;
27
32
  }
28
33
  /**
29
34
  * API interface for the ServiceList service
@@ -39,6 +44,14 @@ export interface ServiceListServiceAPI {
39
44
  isLoadingSignal: Signal<boolean>;
40
45
  /** Reactive signal containing any error message, or null if no error */
41
46
  errorSignal: Signal<string | null>;
47
+ /** Reactive signal containing available categories for filtering */
48
+ categoriesSignal: Signal<Category[]>;
49
+ /** Reactive signal containing current filter state */
50
+ filterSignal: Signal<ServiceListFilters | null>;
51
+ /** Computed signal containing filter options derived from categories */
52
+ filterOptionsSignal: ReadOnlySignal<FilterOption[]>;
53
+ /** Computed signal indicating if any filters are active */
54
+ isFilteredSignal: ReadOnlySignal<boolean>;
42
55
  /** Actions object containing query actions */
43
56
  actions: ServiceListActions;
44
57
  /** Reactive signal indicating if there are more services to load */
@@ -5,6 +5,8 @@
5
5
  import { defineService, implementService } from '@wix/services-definitions';
6
6
  import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
7
7
  import { queryServices } from '../../api/query-services/index.js';
8
+ import { queryCategories, } from '../../api/query-categories/index.js';
9
+ import { BookingServiceDefinition } from '../booking/booking.js';
8
10
  /**
9
11
  * Booking app ID constant
10
12
  */
@@ -73,6 +75,7 @@ export const ServiceListServiceDefinition = defineService('service-list');
73
75
  export const ServiceListService = implementService.withConfig()(ServiceListServiceDefinition, ({ getService, config }) => {
74
76
  let firstRun = true;
75
77
  const signalsService = getService(SignalsServiceDefinition);
78
+ const bookingService = getService(BookingServiceDefinition);
76
79
  // Default appId to BOOKING_APP_ID if not provided
77
80
  const appId = config.options?.appId ?? BOOKING_APP_ID;
78
81
  // Check if services are provided (showcase mode vs query mode)
@@ -111,13 +114,59 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
111
114
  const pagingMetadataSignal = signalsService.signal(initialPagingMetadata);
112
115
  const isLoadingSignal = signalsService.signal(false);
113
116
  const errorSignal = signalsService.signal(null);
117
+ // Categories signal - initialized from config
118
+ const categoriesSignal = signalsService.signal(config.categories || []);
119
+ // Filter signal - current filter state (separate from queryOptions for UI)
120
+ const filterSignal = signalsService.signal(config.options?.filters || null);
121
+ // Computed filter options from categories
122
+ const filterOptionsSignal = signalsService.computed(() => {
123
+ const categories = categoriesSignal.get();
124
+ if (!categories.length)
125
+ return [];
126
+ return [
127
+ {
128
+ key: 'category',
129
+ label: 'Category',
130
+ type: 'single',
131
+ displayType: 'text',
132
+ fieldName: 'categoryIds',
133
+ validValues: categories
134
+ .map((c) => c._id)
135
+ .filter((id) => Boolean(id)),
136
+ valueFormatter: (id) => {
137
+ const cat = categories.find((c) => c._id === id);
138
+ return cat?.name || String(id);
139
+ },
140
+ },
141
+ ];
142
+ });
143
+ // Computed signal for filtered state
144
+ const isFilteredSignal = signalsService.computed(() => {
145
+ const filter = filterSignal.get();
146
+ return !!(filter?.categoryIds?.length || filter?.locationIds?.length);
147
+ });
148
+ // Helper to get effective filters including location from BookingService
149
+ const getEffectiveFilters = (baseFilters) => {
150
+ const selectedLocation = bookingService.location.get();
151
+ const locationId = selectedLocation?.business?._id;
152
+ if (!baseFilters && !locationId) {
153
+ return undefined;
154
+ }
155
+ return {
156
+ ...baseFilters,
157
+ ...(locationId ? { locationIds: [locationId] } : {}),
158
+ };
159
+ };
114
160
  // Auto-query on queryOptions changes (client-side only)
115
- // IMPORTANT: Only subscribes to queryOptionsSignal, NOT pagingMetadataSignal
161
+ // IMPORTANT: Only subscribes to queryOptionsSignal and bookingService.location
116
162
  if (typeof window !== 'undefined') {
117
163
  signalsService.effect(async () => {
118
164
  // CRITICAL: Read queryOptionsSignal to establish dependency
119
165
  // Do NOT read pagingMetadataSignal here to avoid infinite loop
120
166
  const queryOptions = queryOptionsSignal.get();
167
+ // Also subscribe to location changes from BookingService
168
+ // Reading the signal here establishes the dependency
169
+ bookingService.location.get();
121
170
  if (firstRun) {
122
171
  firstRun = false;
123
172
  // If we have initial services (showcase mode), don't query on first run
@@ -126,13 +175,15 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
126
175
  }
127
176
  }
128
177
  // Read paging metadata outside of dependency tracking for the fetch
129
- const currentPaging = pagingMetadataSignal.get();
178
+ const currentPaging = pagingMetadataSignal.peek();
179
+ // Get effective filters including location from BookingService
180
+ const effectiveFilters = getEffectiveFilters(queryOptions.filters);
130
181
  try {
131
182
  isLoadingSignal.set(true);
132
183
  errorSignal.set(null);
133
184
  const result = await queryServices({
134
185
  appId: queryOptions.appId,
135
- filters: queryOptions.filters,
186
+ filters: effectiveFilters,
136
187
  pagingMetadata: {
137
188
  limit: currentPaging.limit,
138
189
  offset: 0, // Reset to first page when query options change
@@ -162,12 +213,14 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
162
213
  offset: nextOffset,
163
214
  hasNext: false, // Will be updated after query
164
215
  };
216
+ // Get effective filters including location from BookingService
217
+ const effectiveFilters = getEffectiveFilters(currentQueryOptions.filters);
165
218
  try {
166
219
  isLoadingSignal.set(true);
167
220
  errorSignal.set(null);
168
221
  const result = await queryServices({
169
222
  appId: currentQueryOptions.appId,
170
- filters: currentQueryOptions.filters,
223
+ filters: effectiveFilters,
171
224
  pagingMetadata: nextPaging,
172
225
  sort: currentQueryOptions.sort,
173
226
  });
@@ -189,6 +242,10 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
189
242
  pagingMetadataSignal,
190
243
  isLoadingSignal,
191
244
  errorSignal,
245
+ categoriesSignal,
246
+ filterSignal,
247
+ filterOptionsSignal,
248
+ isFilteredSignal,
192
249
  actions: {
193
250
  loadMore: async (count) => {
194
251
  await loadMoreCursor(count);
@@ -204,6 +261,26 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
204
261
  });
205
262
  queryOptionsSignal.set(options);
206
263
  },
264
+ setFilter: (filter) => {
265
+ // Update filter signal
266
+ filterSignal.set(filter);
267
+ // Update query options with new filters (triggers re-fetch)
268
+ const currentOptions = queryOptionsSignal.get();
269
+ queryOptionsSignal.set({
270
+ ...currentOptions,
271
+ filters: filter,
272
+ });
273
+ },
274
+ resetFilter: () => {
275
+ // Clear filter signal
276
+ filterSignal.set(null);
277
+ // Clear filters from query options (triggers re-fetch)
278
+ const currentOptions = queryOptionsSignal.get();
279
+ queryOptionsSignal.set({
280
+ ...currentOptions,
281
+ filters: undefined,
282
+ });
283
+ },
207
284
  },
208
285
  hasMoreServicesSignal: signalsService.computed(() => {
209
286
  const paging = pagingMetadataSignal.get();
@@ -247,19 +324,24 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
247
324
  */
248
325
  export async function loadServiceListServiceInitialData(options) {
249
326
  try {
250
- const result = await queryServices({
251
- appId: options.appId,
252
- filters: options.filters,
253
- pagingMetadata: options.pagingMetadata,
254
- sort: options.sort,
255
- });
327
+ // Fetch services and categories in parallel
328
+ const [servicesResult, categoriesResult] = await Promise.all([
329
+ queryServices({
330
+ appId: options.appId,
331
+ filters: options.filters,
332
+ pagingMetadata: options.pagingMetadata,
333
+ sort: options.sort,
334
+ }),
335
+ queryCategories(),
336
+ ]);
256
337
  return {
257
338
  type: 'success',
258
339
  config: {
259
- services: result.services,
340
+ services: servicesResult.services,
341
+ categories: categoriesResult.categories,
260
342
  options: {
261
343
  ...options,
262
- pagingMetadata: result.pagingMetadata,
344
+ pagingMetadata: servicesResult.pagingMetadata,
263
345
  },
264
346
  },
265
347
  };