Skip to content

Commit

Permalink
feat: useMyBookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
reecejohnson committed Oct 16, 2023
1 parent 09d9325 commit 30ccf19
Show file tree
Hide file tree
Showing 10 changed files with 418 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/honest-drinks-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/api-bindings": minor
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

adds publication bookmarks
2 changes: 2 additions & 0 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import { UseCreateComment } from './publications/UseCreateComment';
import { UseCreatePost } from './publications/UseCreatePost';
import { UseHidePublication } from './publications/UseHidePublication';
import { UseMyBookmarks } from './publications/UseMyBookmarks';

const { publicClient, webSocketPublicClient } = configureChains(
[polygonMumbai],
Expand Down Expand Up @@ -103,6 +104,7 @@ export function App() {
<Route path="useHidePublication" element={<UseHidePublication />} />
<Route path="useReportPublication" element={<UseReportPublication />} />
<Route path="useReactionToggle" element={<UseReactionToggle />} />
<Route path="useMyBookmarks" element={<UseMyBookmarks />} />
</Route>

<Route path="/profiles">
Expand Down
5 changes: 5 additions & 0 deletions examples/web/src/publications/PublicationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const publicationHooks = [
description: `Add or remove a reaction to a publication.`,
path: '/publications/useReactionToggle',
},
{
label: 'useMyBookmarks',
description: `Fetch a list of publications that the current user has bookmarked.`,
path: '/publications/useMyBookmarks',
},
];

export function PublicationsPage() {
Expand Down
45 changes: 45 additions & 0 deletions examples/web/src/publications/UseMyBookmarks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Profile, 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 }) {
const {
data: publications,
error,
loading,
hasMore,
observeRef,
} = useInfiniteScroll(useMyBookmarks({ where: {} }));

if (loading) return <Loading />;

if (error) return <ErrorMessage error={error} />;

if (publications.length === 0) return <p>No bookmarks yet.</p>;

return (
<div>
{publications.map((publication) => (
<PublicationCard key={publication.id} publication={publication} />
))}
{hasMore && <p ref={observeRef}>Loading more...</p>}
</div>
);
}

export function UseMyBookmarks() {
return (
<div>
<h1>
<code>useMyBookmarks</code>
</h1>

<WhenLoggedIn>{({ profile }) => <MyBookmarks profile={profile} />}</WhenLoggedIn>
<UnauthenticatedFallback message="Log in to run this demo." />
</div>
);
}
19 changes: 19 additions & 0 deletions packages/api-bindings/src/lens/__helpers__/queries/publication.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
PaginatedResultInfo,
PublicationBookmarksDocument,
PublicationBookmarksVariables,
PublicationDocument,
PublicationVariables,
PublicationsDocument,
Expand Down Expand Up @@ -62,3 +64,20 @@ export function mockSearchPublicationsResponse({
query: SearchPublicationsDocument,
});
}

export function mockProfileBookmarksResponse({
variables,
items,
info = mockPaginatedResultInfo(),
}: {
variables: PublicationBookmarksVariables;
items: AnyPublication[];
info?: PaginatedResultInfo;
}) {
return mockAnyPaginatedResponse({
variables,
items,
info,
query: PublicationBookmarksDocument,
});
}
213 changes: 213 additions & 0 deletions packages/api-bindings/src/lens/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ export enum LensProfileManagerRelayErrorReasonType {
RequiresSignature = 'REQUIRES_SIGNATURE',
}

export enum LensProtocolVersion {
V1 = 'V1',
V2 = 'V2',
}

export enum LensTransactionFailureType {
MetadataError = 'METADATA_ERROR',
Reverted = 'REVERTED',
Expand Down Expand Up @@ -4056,6 +4061,32 @@ export type RefreshPublicationMetadataData = {
result: { result: RefreshPublicationMetadataResultType };
};

export type PublicationBookmarksVariables = Exact<{
request: PublicationBookmarksRequest;
imageSmallSize?: InputMaybe<ImageTransform>;
imageMediumSize?: InputMaybe<ImageTransform>;
profileCoverSize?: InputMaybe<ImageTransform>;
profilePictureSize?: InputMaybe<ImageTransform>;
activityOn?: InputMaybe<Array<Scalars['AppId']> | Scalars['AppId']>;
fxRateFor?: InputMaybe<SupportedFiatType>;
}>;

export type PublicationBookmarksData = {
result: { items: Array<Comment | Mirror | Post | Quote>; pageInfo: PaginatedResultInfo };
} & InjectCommonQueryParams;

export type AddPublicationBookmarkVariables = Exact<{
request: PublicationBookmarkRequest;
}>;

export type AddPublicationBookmarkData = { result: void | null };

export type RemovePublicationBookmarkVariables = Exact<{
request: PublicationBookmarkRequest;
}>;

export type RemovePublicationBookmarkData = { result: void | null };

export type AddReactionVariables = Exact<{
request: ReactionRequest;
}>;
Expand Down Expand Up @@ -11862,6 +11893,188 @@ export type RefreshPublicationMetadataMutationOptions = Apollo.BaseMutationOptio
RefreshPublicationMetadataData,
RefreshPublicationMetadataVariables
>;
export const PublicationBookmarksDocument = /*#__PURE__*/ gql`
query PublicationBookmarks(
$request: PublicationBookmarksRequest!
$imageSmallSize: ImageTransform = {}
$imageMediumSize: ImageTransform = {}
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$fxRateFor: SupportedFiatType = USD
) {
...InjectCommonQueryParams
result: publicationBookmarks(request: $request) {
items {
... on Post {
...Post
}
... on Comment {
...Comment
}
... on Mirror {
...Mirror
}
... on Quote {
...Quote
}
}
pageInfo {
...PaginatedResultInfo
}
}
}
${FragmentInjectCommonQueryParams}
${FragmentPost}
${FragmentComment}
${FragmentMirror}
${FragmentQuote}
${FragmentPaginatedResultInfo}
`;

/**
* __usePublicationBookmarks__
*
* To run a query within a React component, call `usePublicationBookmarks` and pass it any options that fit your needs.
* When your component renders, `usePublicationBookmarks` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = usePublicationBookmarks({
* variables: {
* request: // value for 'request'
* imageSmallSize: // value for 'imageSmallSize'
* imageMediumSize: // value for 'imageMediumSize'
* profileCoverSize: // value for 'profileCoverSize'
* profilePictureSize: // value for 'profilePictureSize'
* activityOn: // value for 'activityOn'
* fxRateFor: // value for 'fxRateFor'
* },
* });
*/
export function usePublicationBookmarks(
baseOptions: Apollo.QueryHookOptions<PublicationBookmarksData, PublicationBookmarksVariables>,
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useQuery<PublicationBookmarksData, PublicationBookmarksVariables>(
PublicationBookmarksDocument,
options,
);
}
export function usePublicationBookmarksLazyQuery(
baseOptions?: Apollo.LazyQueryHookOptions<
PublicationBookmarksData,
PublicationBookmarksVariables
>,
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useLazyQuery<PublicationBookmarksData, PublicationBookmarksVariables>(
PublicationBookmarksDocument,
options,
);
}
export type PublicationBookmarksHookResult = ReturnType<typeof usePublicationBookmarks>;
export type PublicationBookmarksLazyQueryHookResult = ReturnType<
typeof usePublicationBookmarksLazyQuery
>;
export type PublicationBookmarksQueryResult = Apollo.QueryResult<
PublicationBookmarksData,
PublicationBookmarksVariables
>;
export const AddPublicationBookmarkDocument = /*#__PURE__*/ gql`
mutation AddPublicationBookmark($request: PublicationBookmarkRequest!) {
result: addPublicationBookmark(request: $request)
}
`;
export type AddPublicationBookmarkMutationFn = Apollo.MutationFunction<
AddPublicationBookmarkData,
AddPublicationBookmarkVariables
>;

/**
* __useAddPublicationBookmark__
*
* To run a mutation, you first call `useAddPublicationBookmark` within a React component and pass it any options that fit your needs.
* When your component renders, `useAddPublicationBookmark` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [addPublicationBookmark, { data, loading, error }] = useAddPublicationBookmark({
* variables: {
* request: // value for 'request'
* },
* });
*/
export function useAddPublicationBookmark(
baseOptions?: Apollo.MutationHookOptions<
AddPublicationBookmarkData,
AddPublicationBookmarkVariables
>,
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useMutation<AddPublicationBookmarkData, AddPublicationBookmarkVariables>(
AddPublicationBookmarkDocument,
options,
);
}
export type AddPublicationBookmarkHookResult = ReturnType<typeof useAddPublicationBookmark>;
export type AddPublicationBookmarkMutationResult =
Apollo.MutationResult<AddPublicationBookmarkData>;
export type AddPublicationBookmarkMutationOptions = Apollo.BaseMutationOptions<
AddPublicationBookmarkData,
AddPublicationBookmarkVariables
>;
export const RemovePublicationBookmarkDocument = /*#__PURE__*/ gql`
mutation RemovePublicationBookmark($request: PublicationBookmarkRequest!) {
result: removePublicationBookmark(request: $request)
}
`;
export type RemovePublicationBookmarkMutationFn = Apollo.MutationFunction<
RemovePublicationBookmarkData,
RemovePublicationBookmarkVariables
>;

/**
* __useRemovePublicationBookmark__
*
* To run a mutation, you first call `useRemovePublicationBookmark` within a React component and pass it any options that fit your needs.
* When your component renders, `useRemovePublicationBookmark` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [removePublicationBookmark, { data, loading, error }] = useRemovePublicationBookmark({
* variables: {
* request: // value for 'request'
* },
* });
*/
export function useRemovePublicationBookmark(
baseOptions?: Apollo.MutationHookOptions<
RemovePublicationBookmarkData,
RemovePublicationBookmarkVariables
>,
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useMutation<RemovePublicationBookmarkData, RemovePublicationBookmarkVariables>(
RemovePublicationBookmarkDocument,
options,
);
}
export type RemovePublicationBookmarkHookResult = ReturnType<typeof useRemovePublicationBookmark>;
export type RemovePublicationBookmarkMutationResult =
Apollo.MutationResult<RemovePublicationBookmarkData>;
export type RemovePublicationBookmarkMutationOptions = Apollo.BaseMutationOptions<
RemovePublicationBookmarkData,
RemovePublicationBookmarkVariables
>;
export const AddReactionDocument = /*#__PURE__*/ gql`
mutation AddReaction($request: ReactionRequest!) {
addReaction(request: $request)
Expand Down
39 changes: 39 additions & 0 deletions packages/api-bindings/src/lens/graphql/publication.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,42 @@ mutation RefreshPublicationMetadata($request: RefreshPublicationMetadataRequest!
result
}
}

query PublicationBookmarks(
$request: PublicationBookmarksRequest!
$imageSmallSize: ImageTransform = {}
$imageMediumSize: ImageTransform = {}
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$fxRateFor: SupportedFiatType = USD
) {
...InjectCommonQueryParams
result: publicationBookmarks(request: $request) {
items {
... on Post {
...Post
}
... on Comment {
...Comment
}
... on Mirror {
...Mirror
}
... on Quote {
...Quote
}
}
pageInfo {
...PaginatedResultInfo
}
}
}

mutation AddPublicationBookmark($request: PublicationBookmarkRequest!) {
result: addPublicationBookmark(request: $request)
}

mutation RemovePublicationBookmark($request: PublicationBookmarkRequest!) {
result: removePublicationBookmark(request: $request)
}
Loading

0 comments on commit 30ccf19

Please sign in to comment.