-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Suspense support to useExplorePublications, useExploreProfiles,…
… useRecommendedProfiles hooks
- Loading branch information
1 parent
980e327
commit 697eca1
Showing
13 changed files
with
276 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@lens-protocol/react": minor | ||
"@lens-protocol/react-native": minor | ||
"@lens-protocol/react-web": minor | ||
--- | ||
|
||
**feat:** add React Suspense support to `useExplorePublications`, `useExploreProfiles`, `useRecommendedProfiles` hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,101 @@ | ||
import { | ||
ExploreProfilesDocument, | ||
ExploreProfilesOrderByType, | ||
ExploreProfilesRequest, | ||
ExploreProfilesWhere, | ||
Profile, | ||
useExploreProfiles as useBaseExploreProfilesQuery, | ||
} from '@lens-protocol/api-bindings'; | ||
|
||
import { useLensApolloClient } from '../helpers/arguments'; | ||
import { PaginatedArgs, PaginatedReadResult, usePaginatedReadResult } from '../helpers/reads'; | ||
import { PaginatedArgs, PaginatedReadResult } from '../helpers/reads'; | ||
import { | ||
SuspendablePaginatedResult, | ||
SuspenseEnabled, | ||
SuspensePaginatedResult, | ||
useSuspendablePaginatedQuery, | ||
} from '../helpers/suspense'; | ||
import { useFragmentVariables } from '../helpers/variables'; | ||
|
||
/** | ||
* {@link useExploreProfiles} hook arguments | ||
*/ | ||
export type UseExploreProfilesArgs = PaginatedArgs<ExploreProfilesRequest>; | ||
|
||
export type { ExploreProfilesRequest, ExploreProfilesWhere }; | ||
|
||
/** | ||
* `useExploreProfiles` is a paginated hook that lets you discover new profiles based on a defined criteria | ||
* | ||
* @category Discovery | ||
* @group Hooks | ||
* @param args - {@link UseExploreProfilesArgs} | ||
* {@link useExploreProfiles} hook arguments with Suspense support | ||
*/ | ||
export type UseSuspenseExploreProfilesArgs = SuspenseEnabled<UseExploreProfilesArgs>; | ||
|
||
/** | ||
* Discover new profiles based on a defined criteria. | ||
* | ||
* @example | ||
* Explore the latest created profiles | ||
* ```tsx | ||
* import { useExploreProfiles, ExploreProfilesOrderByType } from '@lens-protocol/react'; | ||
* const { data, error, loading } = useExploreProfiles({ | ||
* orderBy: ExploreProfilesOrderByType.LatestCreated, | ||
* }); | ||
* | ||
* if (loading) return <Loader />; | ||
* | ||
* if (error) return <Error message={error.message} />; | ||
* | ||
* function ExploreProfiles() { | ||
* const { data, error, loading } = useExploreProfiles({ | ||
* orderBy: ExploreProfilesOrderByType.LatestCreated, | ||
* }); | ||
* return ( | ||
* <> | ||
* {data.map((profile) => ( | ||
* <Profile key={profile.id} profile={profile} /> | ||
* ))} | ||
* </> | ||
* ); | ||
* ``` | ||
* | ||
* @category Discovery | ||
* @group Hooks | ||
*/ | ||
export function useExploreProfiles(args?: UseExploreProfilesArgs): PaginatedReadResult<Profile[]>; | ||
|
||
/** | ||
* Discover new profiles based on a defined criteria. | ||
* | ||
* if (loading) return <p>Loading...</p>; | ||
* This signature supports [React Suspense](https://react.dev/reference/react/Suspense). | ||
* | ||
* if (error) return <p>Error: {error.message}</p>; | ||
* ```ts | ||
* const { data } = useExploreProfiles({ | ||
* orderBy: ExploreProfilesOrderByType.LatestCreated, | ||
* suspense: true, | ||
* ); | ||
* | ||
* return ( | ||
* <ul> | ||
* {data.map((profile) => ( | ||
* <li key={profile.id}>{profile.handle}</li> | ||
* ))} | ||
* </ul> | ||
* ); | ||
* } | ||
* console.log(data); | ||
* ``` | ||
* | ||
* @experimental This API can change without notice | ||
* @category Discovery | ||
* @group Hooks | ||
*/ | ||
export function useExploreProfiles( | ||
{ where, limit, orderBy = ExploreProfilesOrderByType.LatestCreated }: UseExploreProfilesArgs = { | ||
args: UseSuspenseExploreProfilesArgs, | ||
): SuspensePaginatedResult<Profile[]>; | ||
|
||
export function useExploreProfiles( | ||
{ | ||
where, | ||
limit, | ||
orderBy = ExploreProfilesOrderByType.LatestCreated, | ||
suspense = false, | ||
}: UseExploreProfilesArgs & { suspense?: boolean } = { | ||
orderBy: ExploreProfilesOrderByType.LatestCreated, | ||
suspense: false, | ||
}, | ||
): PaginatedReadResult<Profile[]> { | ||
return usePaginatedReadResult( | ||
useBaseExploreProfilesQuery( | ||
useLensApolloClient({ | ||
variables: useFragmentVariables({ | ||
limit, | ||
where, | ||
orderBy, | ||
}), | ||
): SuspendablePaginatedResult<Profile[]> { | ||
return useSuspendablePaginatedQuery({ | ||
suspense, | ||
query: ExploreProfilesDocument, | ||
options: useLensApolloClient({ | ||
variables: useFragmentVariables({ | ||
limit, | ||
where, | ||
orderBy, | ||
}), | ||
), | ||
); | ||
}), | ||
}); | ||
} |
Oops, something went wrong.