Skip to content

Commit

Permalink
feat: Add and export isQueriesLoading and hasQueriesBeenLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Oct 31, 2023
1 parent b170d2e commit d22c713
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
44 changes: 44 additions & 0 deletions docs/api/cozy-client/README.md
Expand Up @@ -449,6 +449,28 @@ Array of the reference found

***

### hasQueriesBeenLoaded

**hasQueriesBeenLoaded**(`queriesResults`): `boolean`

Returns whether queries have been loaded at least once

*Parameters*

| Name | Type |
| :------ | :------ |
| `queriesResults` | `any` |

*Returns*

`boolean`

*Defined in*

[packages/cozy-client/src/utils.js:66](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/utils.js#L66)

***

### hasQueryBeenLoaded

**hasQueryBeenLoaded**(`col`): `any`
Expand All @@ -471,6 +493,28 @@ Returns whether a query has been loaded at least once

***

### isQueriesLoading

**isQueriesLoading**(`queriesResults`): `boolean`

Returns whether the result of queries are loading

*Parameters*

| Name | Type |
| :------ | :------ |
| `queriesResults` | `any` |

*Returns*

`boolean`

*Defined in*

[packages/cozy-client/src/utils.js:57](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/utils.js#L57)

***

### isQueryLoading

**isQueryLoading**(`col`): `boolean`
Expand Down
8 changes: 7 additions & 1 deletion packages/cozy-client/src/index.js
Expand Up @@ -35,7 +35,13 @@ export {
InvalidProtocolError,
BlockedCozyError
} from './helpers'
export { cancelable, isQueryLoading, hasQueryBeenLoaded } from './utils'
export {
cancelable,
isQueryLoading,
hasQueryBeenLoaded,
isQueriesLoading,
hasQueriesBeenLoaded
} from './utils'
export { getQueryFromState } from './store'
export { default as Registry } from './registry'
export { default as RealTimeQueries } from './RealTimeQueries'
Expand Down
18 changes: 18 additions & 0 deletions packages/cozy-client/src/utils.js
Expand Up @@ -50,3 +50,21 @@ export const isQueryLoading = col => {
export const hasQueryBeenLoaded = col => {
return col.lastFetch
}

/**
* Returns whether the result of queries are loading
*/
export const isQueriesLoading = queriesResults => {
return Object.values(queriesResults).some(queryResult =>
isQueryLoading(queryResult)
)
}

/**
* Returns whether queries have been loaded at least once
*/
export const hasQueriesBeenLoaded = queriesResults => {
return Object.values(queriesResults).some(queryResult =>
hasQueryBeenLoaded(queryResult)
)
}
2 changes: 1 addition & 1 deletion packages/cozy-client/types/index.d.ts
Expand Up @@ -20,5 +20,5 @@ export { QueryDefinition, Q, Mutations, MutationTypes, getDoctypeFromOperation }
export { Association, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTriggers } from "./associations";
export { isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./associations/helpers";
export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, dehydrate, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidRedirectLinkError, InvalidCozyUrlError, InvalidProtocolError, BlockedCozyError } from "./helpers";
export { cancelable, isQueryLoading, hasQueryBeenLoaded } from "./utils";
export { cancelable, isQueryLoading, hasQueryBeenLoaded, isQueriesLoading, hasQueriesBeenLoaded } from "./utils";
export { queryConnect, queryConnectFlat, withClient } from "./hoc";
2 changes: 2 additions & 0 deletions packages/cozy-client/types/utils.d.ts
@@ -1,5 +1,7 @@
export function isQueryLoading(col: any): boolean;
export function hasQueryBeenLoaded(col: any): any;
export function isQueriesLoading(queriesResults: any): boolean;
export function hasQueriesBeenLoaded(queriesResults: any): boolean;
export type CancelablePromise = Promise<any>;
/**
* @typedef {Promise} CancelablePromise
Expand Down

0 comments on commit d22c713

Please sign in to comment.