Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/simple-animations
Browse files Browse the repository at this point in the history
  • Loading branch information
danieloprado committed Jun 30, 2023
2 parents 8e0043a + 05fb16b commit 3cde74d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@eduzz/houston-workspaces",
"version": "1.9.7",
"version": "1.9.8",
"workspaces": [
"src/pages/*",
"src/dev",
Expand Down
10 changes: 5 additions & 5 deletions src/dev/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@eduzz/houston-dev",
"version": "1.9.7",
"version": "1.9.8",
"private": true,
"dependencies": {
"@eduzz/houston-forms": "1.9.7",
"@eduzz/houston-hooks": "1.9.7",
"@eduzz/houston-icons": "1.9.7",
"@eduzz/houston-ui": "1.9.7",
"@eduzz/houston-forms": "1.9.8",
"@eduzz/houston-hooks": "1.9.8",
"@eduzz/houston-icons": "1.9.8",
"@eduzz/houston-ui": "1.9.8",
"react-dom": "^18",
"react-router-dom": "^6.11.0",
"react-scripts": "^5.0.1",
Expand Down
10 changes: 5 additions & 5 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@eduzz/docs",
"version": "1.9.7",
"version": "1.9.8",
"private": true,
"scripts": {
"start": "next dev",
"build": "next build && next export"
},
"dependencies": {
"@chakra-ui/react": "^1.8.8",
"@eduzz/houston-forms": "1.9.7",
"@eduzz/houston-hooks": "1.9.7",
"@eduzz/houston-icons": "1.9.7",
"@eduzz/houston-ui": "1.9.7",
"@eduzz/houston-forms": "1.9.8",
"@eduzz/houston-hooks": "1.9.8",
"@eduzz/houston-icons": "1.9.8",
"@eduzz/houston-ui": "1.9.8",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"dokz": "2.0.9",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/eslint-config-houston",
"private": false,
"version": "1.9.7",
"version": "1.9.8",
"description": "Eduzz Houston Eslint Config",
"author": "Eduzz Team",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/forms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eduzz/houston-forms",
"version": "1.9.7",
"version": "1.9.8",
"description": "Houston Forms",
"main": "index.js",
"types": "./index.d.ts",
Expand All @@ -19,7 +19,7 @@
"check-update-deps": "yarn ncu -u"
},
"dependencies": {
"@eduzz/houston-hooks": "1.9.7",
"@eduzz/houston-hooks": "1.9.8",
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^3",
"formik": "^2.2.9",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/houston-hooks",
"description": "Eduzz Houston Hooks",
"version": "1.9.7",
"version": "1.9.8",
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
Expand Down
29 changes: 22 additions & 7 deletions src/pages/hooks/useQueryPaginated/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import * as React from 'react';

import { UseQueryOptions, UseQueryResult, useQuery } from '@tanstack/react-query';
Expand All @@ -13,12 +14,15 @@ export type PaginationMergeParams<P> =
export interface UseQueryPaginatedOptions<P extends PaginationParams, R = unknown>
extends Omit<UseQueryOptions<PaginationResponse<R>>, 'queryFn'> {
initialParams?: Partial<P>;
/** set if the date will be cumulative or not */
infintyScroll?: boolean;
queryFn: (params: P) => Promise<PaginationResponse<R>>;
}

export type UseQueryPaginatedResult<P extends PaginationParams = PaginationParams, R = unknown> = {
params: P;
initialParams: Partial<P>;
infinityHasMore?: boolean;
refresh: () => void;
mergeParams: (params: PaginationMergeParams<P>, reset?: boolean) => void;
/** Sintax sugar for `mergeParams` to change page */
Expand All @@ -40,7 +44,7 @@ export default function useQueryPaginated<P extends PaginationParams, R>(
): UseQueryPaginatedResult<P, R> {
const firstRender = React.useRef(true);

const { initialParams: initialParamsOption, queryFn, ...queryOptions } = options;
const { initialParams: initialParamsOption, queryFn, infintyScroll, ...queryOptions } = options;
const [initialParams] = React.useState<P>(
() =>
({
Expand All @@ -56,7 +60,16 @@ export default function useQueryPaginated<P extends PaginationParams, R>(
try {
const sendParams = { ...params } as P & { _refresh?: number };
delete sendParams._refresh;
return await queryFn(sendParams);
const data = await queryFn(sendParams);

const lastTotal: number = result.data?.total ?? 0;
const lastResult: any[] = result.data?.result ?? [];

return {
total: data.total ?? lastTotal,
result:
infintyScroll && params.page !== initialParams.page ? [...lastResult, ...(data.result ?? [])] : data.result
};
} catch (err) {
getConfig().onUnhandledError(err, 'hooks');
throw err;
Expand Down Expand Up @@ -85,10 +98,6 @@ export default function useQueryPaginated<P extends PaginationParams, R>(
newParams = newParams(params);
}

if ((newParams.page ?? 0) > params.page) {
newParams.page = params.page;
}

const newState = { ...(reset ? initialParams : params), ...newParams } as P;

if (isEqual(newState, params)) {
Expand All @@ -102,8 +111,13 @@ export default function useQueryPaginated<P extends PaginationParams, R>(
);

const refresh = React.useCallback(() => {
if (infintyScroll) {
mergeParams({ page: initialParams.page, _refresh: Date.now() } as any);
return;
}

mergeParams({ _refresh: Date.now() } as any);
}, [mergeParams]);
}, [infintyScroll, initialParams.page, mergeParams]);

const handleChangePage = React.useCallback((page: number) => mergeParams({ page } as P), [mergeParams]);
const handleChangePerPage = React.useCallback((perPage: number) => mergeParams({ perPage } as P), [mergeParams]);
Expand All @@ -117,6 +131,7 @@ export default function useQueryPaginated<P extends PaginationParams, R>(
return {
...result,
initialParams,
infinityHasMore: infintyScroll ? (result.data?.result.length ?? 0) < (result.data?.total ?? 0) : undefined,
refresh,
params,
mergeParams,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/icons/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/houston-icons",
"description": "Eduzz Houston Icons",
"version": "1.9.7",
"version": "1.9.8",
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/styles/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/houston-styles",
"description": "Eduzz Houston Style",
"version": "1.9.7",
"version": "1.9.8",
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
Expand All @@ -19,7 +19,7 @@
"check-update-deps": "yarn ncu -u"
},
"dependencies": {
"@eduzz/houston-tokens": "1.9.7",
"@eduzz/houston-tokens": "1.9.8",
"@emotion/cache": "^11",
"@emotion/css": "^11",
"@emotion/react": "^11",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/houston-tokens",
"description": "Eduzz Houston Tokens",
"version": "1.9.7",
"version": "1.9.8",
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
Expand Down
10 changes: 5 additions & 5 deletions src/pages/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eduzz/houston-ui",
"description": "Eduzz Houston Components UI",
"version": "1.9.7",
"version": "1.9.8",
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
Expand All @@ -20,10 +20,10 @@
},
"dependencies": {
"@ant-design/icons": "^5.1.4",
"@eduzz/houston-forms": "1.9.7",
"@eduzz/houston-hooks": "1.9.7",
"@eduzz/houston-icons": "1.9.7",
"@eduzz/houston-styles": "1.9.7",
"@eduzz/houston-forms": "1.9.8",
"@eduzz/houston-hooks": "1.9.8",
"@eduzz/houston-icons": "1.9.8",
"@eduzz/houston-styles": "1.9.8",
"@emotion/cache": "^11",
"@emotion/css": "^11",
"@emotion/react": "^11",
Expand Down

0 comments on commit 3cde74d

Please sign in to comment.