Skip to content

Commit

Permalink
chore: linting and exmaple
Browse files Browse the repository at this point in the history
  • Loading branch information
reecejohnson committed Oct 16, 2023
1 parent 30ccf19 commit 7f3784c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 4 additions & 4 deletions examples/web/src/publications/UseMyBookmarks.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Profile, useMyBookmarks } from '@lens-protocol/react-web';
import { useMyBookmarks } from '@lens-protocol/react-web';

import { UnauthenticatedFallback, WhenLoggedIn } from '../components/auth';
import { ErrorMessage } from '../components/error/ErrorMessage';
import { Loading } from '../components/loading/Loading';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';
import { PublicationCard } from './components/PublicationCard';

export function MyBookmarks({ profile }: { profile: Profile }) {
export function MyBookmarks() {
const {
data: publications,
error,
loading,
hasMore,
observeRef,
} = useInfiniteScroll(useMyBookmarks({ where: {} }));
} = useInfiniteScroll(useMyBookmarks());

if (loading) return <Loading />;

Expand All @@ -38,7 +38,7 @@ export function UseMyBookmarks() {
<code>useMyBookmarks</code>
</h1>

<WhenLoggedIn>{({ profile }) => <MyBookmarks profile={profile} />}</WhenLoggedIn>
<WhenLoggedIn>{() => <MyBookmarks />}</WhenLoggedIn>
<UnauthenticatedFallback message="Log in to run this demo." />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LimitType, SafeApolloClient } from '@lens-protocol/api-bindings';
import { SafeApolloClient } from '@lens-protocol/api-bindings';
import {
mockLensApolloClient,
mockPostFragment,
Expand Down Expand Up @@ -31,10 +31,7 @@ describe(`Given the ${useMyBookmarks.name} hook`, () => {
const client = mockLensApolloClient([
mockProfileBookmarksResponse({
variables: {
request: {
where: {},
limit: LimitType.Ten,
},
request: {},
},
items: publications,
}),
Expand All @@ -43,7 +40,7 @@ describe(`Given the ${useMyBookmarks.name} hook`, () => {
it('should settle with the bookmarked publications', async () => {
const { renderHook } = setupTestScenario({ client });

const { result } = renderHook(() => useMyBookmarks({ where: {}, limit: LimitType.Ten }));
const { result } = renderHook(() => useMyBookmarks());

await waitFor(() => expect(result.current.loading).toBeFalsy());
expect(result.current.data).toMatchObject(expectations);
Expand Down
27 changes: 20 additions & 7 deletions packages/react/src/publication/useMyBookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AnyPublication,
PublicationBookmarksRequest,
usePublicationBookmarks as useGetProfileBookmarks
usePublicationBookmarks as useGetProfileBookmarks,
} from '@lens-protocol/api-bindings';

import { useLensApolloClient } from '../helpers/arguments';
Expand All @@ -12,17 +12,30 @@ export type UseMyBookmarksArgs = PaginatedArgs<PublicationBookmarksRequest>;
/**
* `useMyBookmarks` is a paginated hook that lets you fetch the bookmarks of a profile owned by the logged in wallet.
*
* You MUST be authenticated via {@link useWalletLogin} to use this hook.
* By default it will fetch the bookmarks of the Active Profile.
* You MUST be authenticated via {@link useLogin} to use this hook.
*
* @category Bookmarks
* @group Hooks
* @param args - {@link UseMyBookmarksArgs}
*
* @example
* ```tsx
* const { data, loading, error } = useMyBookmarks();
*
* if (loading) return <p>Loading...</p>;
*
* return (
* <div>
* {data.map((publication) => (
* <PublicationCard publication={publication} key={publication.id} />
* ))}
* </div>
* );
* ```
*/
export function useMyBookmarks({
where,
limit,
}: UseMyBookmarksArgs): PaginatedReadResult<AnyPublication[]> {
export function useMyBookmarks({ where, limit }: UseMyBookmarksArgs = {}): PaginatedReadResult<
AnyPublication[]
> {
return usePaginatedReadResult(
useGetProfileBookmarks(
useLensApolloClient({
Expand Down

0 comments on commit 7f3784c

Please sign in to comment.