@appcorp/fusion-storybook 0.1.76 → 0.1.78

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.
@@ -115,7 +115,7 @@ export declare const useClassModule: () => {
115
115
  handleEdit: (row?: TableRow) => void;
116
116
  handleFilters: () => void;
117
117
  handleMoreActions: () => void;
118
- handlePageChange: (page: number) => void;
118
+ handlePageChange: (pageOrEvent?: unknown) => void;
119
119
  handlePageLimitChange: (k: string, value: object) => void;
120
120
  handleSearch: (query: string) => void;
121
121
  handleSubmit: () => void;
@@ -272,12 +272,19 @@ export const useClassModule = () => {
272
272
  payload: { drawer: CLASS_DRAWER.MORE_ACTIONS_DRAWER },
273
273
  });
274
274
  }, [dispatch]);
275
- const handlePageChange = useCallback((page) => {
275
+ const handlePageChange = useCallback((pageOrEvent) => {
276
+ // The factory passes handlePageChange directly as the Next button's onClick
277
+ // handler (receiving a MouseEvent), but wraps Previous as () => handlePageChange(currentPage - 1).
278
+ // We detect which case we're in: a valid number means an explicit page target
279
+ // (Previous path); anything else means "advance to next page".
280
+ const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
281
+ ? pageOrEvent
282
+ : state.currentPage + 1;
276
283
  dispatch({
277
284
  type: CLASS_ACTION_TYPES.SET_CURRENT_PAGE,
278
285
  payload: { currentPage: page },
279
286
  });
280
- }, [dispatch]);
287
+ }, [dispatch, state.currentPage]);
281
288
  const handlePageLimitChange = useCallback((k, value) => {
282
289
  const val = Object.assign({}, value);
283
290
  dispatch({
@@ -317,9 +324,8 @@ export const useClassModule = () => {
317
324
  type: CLASS_ACTION_TYPES.SET_CURRENT_PAGE,
318
325
  payload: { currentPage: 1 },
319
326
  });
320
- listFetchNow();
321
327
  closeDrawer();
322
- }, [dispatch, listFetchNow, closeDrawer]);
328
+ }, [dispatch, closeDrawer]);
323
329
  const clearFilters = useCallback(() => {
324
330
  dispatch({
325
331
  type: CLASS_ACTION_TYPES.SET_FILTERS,
@@ -417,23 +423,37 @@ export const useClassModule = () => {
417
423
  // ============================================================================
418
424
  // 1.4.9 EFFECTS
419
425
  // ============================================================================
420
- // Initial load + re-fetch on page/search/filter change via cache
426
+ // Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes
421
427
  useEffect(() => {
422
428
  if (!schoolId)
423
429
  return;
424
- (async () => {
425
- try {
426
- const { count, items } = await getCachedClasses({ params: listParams });
427
- dispatch({
428
- type: CLASS_ACTION_TYPES.SET_ITEMS,
429
- payload: { items: items || [], count: count || 0 },
430
- });
431
- }
432
- catch (_a) {
433
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
434
- }
435
- })();
436
- }, [dispatch, listParams, schoolId, showToast, t]);
430
+ const currentPage = Number(listParams.currentPage) || 1;
431
+ const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
432
+ const isDefaultLoad = currentPage === 1 &&
433
+ currentPageLimit === pageLimit &&
434
+ !listParams.searchQuery &&
435
+ listParams.filterEnabled === undefined;
436
+ if (isDefaultLoad) {
437
+ (async () => {
438
+ try {
439
+ const { count, items } = await getCachedClasses({
440
+ params: listParams,
441
+ });
442
+ dispatch({
443
+ type: CLASS_ACTION_TYPES.SET_ITEMS,
444
+ payload: { items: items || [], count: count || 0 },
445
+ });
446
+ }
447
+ catch (_a) {
448
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
449
+ }
450
+ })();
451
+ }
452
+ else {
453
+ // Bypass cache for pagination, pageLimit, filter and search changes
454
+ listFetchNow();
455
+ }
456
+ }, [dispatch, listFetchNow, listParams, schoolId, showToast, t]);
437
457
  // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
438
458
  useEffect(() => {
439
459
  listFetchNowRef.current = listFetchNow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.1.76",
3
+ "version": "0.1.78",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",