Skip to content

Commit

Permalink
react: add useProfileActionHistory and useWhoReactedToPublication
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Oct 6, 2023
1 parent 5ee1bee commit 3257f88
Show file tree
Hide file tree
Showing 17 changed files with 733 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ProfilesPage,
UseMutualFollowers,
UseProfile,
UseProfileActionHistory,
UseProfileFollowers,
UseProfileFollowing,
UseProfiles,
Expand Down Expand Up @@ -77,6 +78,7 @@ export function App() {
<Route path="useMutualFollowers" element={<UseMutualFollowers />} />
<Route path="useRecommendedProfiles" element={<UseRecommendedProfiles />} />
<Route path="useWhoActedOnPublication" element={<UseWhoActedOnPublication />} />
<Route path="useProfileActionHistory" element={<UseProfileActionHistory />} />
</Route>

<Route path="/search">
Expand Down
5 changes: 5 additions & 0 deletions examples/web/src/profiles/ProfilesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const profileHooks = [
description: `Fetch a list of profiles who acted on a publication.`,
path: '/profiles/useWhoActedOnPublication',
},
{
label: 'useProfileActionHistory',
description: `Fetch profile action history.`,
path: '/profiles/useProfileActionHistory',
},
];

export function ProfilesPage() {
Expand Down
37 changes: 37 additions & 0 deletions examples/web/src/profiles/UseProfileActionHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useProfileActionHistory } from '@lens-protocol/react';

import { ErrorMessage } from '../components/error/ErrorMessage';
import { Loading } from '../components/loading/Loading';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';

// TODO requires authenticated profile
export function UseProfileActionHistory() {
const {
data: history,
error,
loading,
hasMore,
observeRef,
} = useInfiniteScroll(useProfileActionHistory());

if (loading) return <Loading />;

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

return (
<div>
<h1>
<code>useProfileActionHistory</code>
</h1>
<div>
{history.map((item) => (
<div key={item.id}>
{item.actionType} {item.actionedOn}
</div>
))}

{hasMore && <p ref={observeRef}>Loading more...</p>}
</div>
</div>
);
}
1 change: 1 addition & 0 deletions examples/web/src/profiles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './ProfilesPage';
export * from './UseMutualFollowers';
export * from './UseProfile';
export * from './UseProfileActionHistory';
export * from './UseProfileFollowers';
export * from './UseProfileFollowing';
export * from './UseProfiles';
Expand Down
4 changes: 4 additions & 0 deletions packages/api-bindings/src/apollo/cache/createTypePolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
createFollowersFieldPolicy,
createFollowingFieldPolicy,
createMutualFollowersFieldPolicy,
createProfileActionHistoryFieldPolicy,
createProfileRecommendationsFieldPolicy,
createProfilesFieldPolicy,
createPublicationsFieldPolicy,
createSearchProfilesFieldPolicy,
createSearchPublicationsFieldPolicy,
createWhoActedOnPublicationFieldPolicy,
createWhoReactedPublicationFieldPolicy,
} from './field-policies';
import { notNormalizedType } from './utils/notNormalizedType';

Expand All @@ -34,12 +36,14 @@ export function createTypePolicies(): StrictTypedTypePolicies & InheritedTypePol
followers: createFollowersFieldPolicy(),
following: createFollowingFieldPolicy(),
mutualFollowers: createMutualFollowersFieldPolicy(),
profileActionHistory: createProfileActionHistoryFieldPolicy(),
profileRecommendations: createProfileRecommendationsFieldPolicy(),
profiles: createProfilesFieldPolicy(),
publications: createPublicationsFieldPolicy(),
searchProfiles: createSearchProfilesFieldPolicy(),
searchPublications: createSearchPublicationsFieldPolicy(),
whoActedOnPublication: createWhoActedOnPublicationFieldPolicy(),
whoReactedPublication: createWhoReactedPublicationFieldPolicy(),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cursorBasedPagination } from '../utils/cursorBasedPagination';

export function createProfileActionHistoryFieldPolicy() {
return cursorBasedPagination([]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cursorBasedPagination } from '../utils/cursorBasedPagination';

export function createWhoReactedPublicationFieldPolicy() {
return cursorBasedPagination([['request', ['for', 'where', ['anyOf']]]]);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export * from './createFollowersFieldPolicy';
export * from './createFollowingFieldPolicy';
export * from './createMutualFollowersFieldPolicy';
export * from './createProfileActionHistoryFieldPolicy';
export * from './createProfileRecommendationsFieldPolicy';
export * from './createProfilesFieldPolicy';
export * from './createPublicationsFieldPolicy';
export * from './createSearchProfilesFieldPolicy';
export * from './createSearchPublicationsFieldPolicy';
export * from './createProfileRecommendationsFieldPolicy';
export * from './createWhoActedOnPublicationFieldPolicy';
export * from './createWhoReactedPublicationFieldPolicy';
16 changes: 16 additions & 0 deletions packages/api-bindings/src/lens/__helpers__/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
PaginatedResultInfo,
Post,
Profile,
ProfileActionHistory,
ProfileActionHistoryType,
ProfileStats,
PublicationOperations,
PublicationStats,
Expand Down Expand Up @@ -222,3 +224,17 @@ export function mockProfileStatsFragment(overrides: Partial<ProfileStats> = {}):
...overrides,
};
}

export function mockProfileActionHistoryFragment(
overrides: Partial<ProfileActionHistory> = {},
): ProfileActionHistory {
return {
id: faker.datatype.number(),
actionType: ProfileActionHistoryType.LoggedIn,
who: mockEvmAddress(),
txHash: mockTransactionHash(),
actionedOn: faker.date.past().toISOString(),

...overrides,
};
}
28 changes: 28 additions & 0 deletions packages/api-bindings/src/lens/__helpers__/queries/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
MutualFollowersVariables,
PaginatedResultInfo,
Profile,
ProfileActionHistory,
ProfileActionHistoryDocument,
ProfileActionHistoryVariables,
ProfileRecommendationsDocument,
ProfileRecommendationsVariables,
ProfilesData,
Expand Down Expand Up @@ -177,3 +180,28 @@ export function mockWhoActedOnPublicationResponse({
query: WhoActedOnPublicationDocument,
});
}

export function mockProfileActionHistoryResponse({
variables,
items,
info = mockPaginatedResultInfo(),
}: {
variables: ProfileActionHistoryVariables;
items: ProfileActionHistory[];
info?: PaginatedResultInfo;
}) {
return {
request: {
query: ProfileActionHistoryDocument,
variables,
},
result: {
data: {
result: {
items,
pageInfo: info,
},
},
},
};
}
Loading

0 comments on commit 3257f88

Please sign in to comment.