Skip to content

Commit

Permalink
feat: supports 'for you' feed
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed May 23, 2024
1 parent e9a2882 commit ddd810a
Show file tree
Hide file tree
Showing 21 changed files with 52,149 additions and 23,829 deletions.
8 changes: 8 additions & 0 deletions .changeset/thirty-games-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lens-protocol/react": minor
"@lens-protocol/react-native": minor
"@lens-protocol/react-web": minor
"@lens-protocol/api-bindings": patch
---

**fear:** adds `usePublicationsForYou` hook
5 changes: 5 additions & 0 deletions .changeset/wise-books-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lens-protocol/client": minor
---

**feat:** adds `client.feed.forYou` method
2 changes: 2 additions & 0 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
UseExplorePublications,
UseFeed,
UseFeedHighlights,
UsePublicationsForYou,
UseRecommendedProfiles,
UseSearchProfiles,
UseSearchPublications,
Expand Down Expand Up @@ -165,6 +166,7 @@ export function App() {
<Route index element={<DiscoveryPage />} />
<Route path="useFeed" element={<UseFeed />} />
<Route path="useFeedHighlights" element={<UseFeedHighlights />} />
<Route path="usePublicationsForYou" element={<UsePublicationsForYou />} />
<Route path="useSearchPublications" element={<UseSearchPublications />} />
<Route path="useSearchProfiles" element={<UseSearchProfiles />} />
<Route path="useExploreProfiles" element={<UseExploreProfiles />} />
Expand Down
5 changes: 5 additions & 0 deletions examples/web/src/discovery/DiscoveryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const discoveryHooks = [
description: `Fetch the highlights of a feed for a profile matching given filters.`,
path: '/discovery/useFeedHighlights',
},
{
label: 'usePublicationsForYou',
description: `Fetch personalized feed of Quotes and Posts for a profile.`,
path: '/discovery/usePublicationsForYou',
},
{
label: 'useSearchPublications',
description: 'Search for publications using filters.',
Expand Down
6 changes: 1 addition & 5 deletions examples/web/src/discovery/UseFeedHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Loading } from '../components/loading/Loading';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';

function UseFeedHighlightsInner({ profileId }: { profileId: ProfileId }) {
const { data, error, loading, hasMore, beforeCount, observeRef, prev } = useInfiniteScroll(
const { data, error, loading, hasMore, observeRef } = useInfiniteScroll(
useFeedHighlights({
where: {
for: profileId,
Expand All @@ -23,10 +23,6 @@ function UseFeedHighlightsInner({ profileId }: { profileId: ProfileId }) {

{error && <ErrorMessage error={error} />}

<button disabled={loading || beforeCount === 0} onClick={prev}>
Fetch newer
</button>

{data?.map((item) => (
<PublicationCard key={`${item.id}`} publication={item} />
))}
Expand Down
38 changes: 38 additions & 0 deletions examples/web/src/discovery/UsePublicationsForYou.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { profileId, usePublicationsForYou } from '@lens-protocol/react-web';

import { RequireProfileSession } from '../components/auth';
import { PublicationCard } from '../components/cards';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';

function UsePublicationsForYouInner() {
const { data, hasMore, observeRef } = useInfiniteScroll(
usePublicationsForYou({
for: profileId('0x0a'),
suspense: true,
}),
);

return (
<div>
<h1>
<code>usePublicationsForYou</code>
</h1>

{data?.length === 0 && <p>No items</p>}

{data?.map((item) => (
<PublicationCard key={item.publication.id} publication={item.publication} />
))}

{hasMore && <p ref={observeRef}>Loading more...</p>}
</div>
);
}

export function UsePublicationsForYou() {
return (
<RequireProfileSession message="Log in to view this example.">
{() => <UsePublicationsForYouInner />}
</RequireProfileSession>
);
}
1 change: 1 addition & 0 deletions examples/web/src/discovery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './UseExploreProfiles';
export * from './UseExplorePublications';
export * from './UseFeed';
export * from './UseFeedHighlights';
export * from './UsePublicationsForYou';
export * from './UseRecommendedProfiles';
export * from './UseSearchProfiles';
export * from './UseSearchPublications';
50 changes: 7 additions & 43 deletions packages/api-bindings/src/lens/graphql/feed.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,20 @@ query FeedHighlights(
}
}

fragment LatestActed on LatestActed {
__typename
profile {
...Profile
}
actedAt
txHash
}

fragment FollowPaidAction on FollowPaidAction {
__typename
latestActed {
...LatestActed
}
followed {
...Profile
}
}

fragment OpenActionPaidAction on OpenActionPaidAction {
__typename
latestActed {
...LatestActed
}
actedOn {
fragment ForYouResult on ForYouResult {
publication {
... on Post {
...Post
}
... on Comment {
...Comment
}
... on Quote {
...Quote
}
}
source
}

query LatestPaidActions(
$where: LatestPaidActionsWhere
$filter: LatestPaidActionsFilter
query ForYou(
$for: ProfileId
$limit: LimitType
$cursor: Cursor
$imageSmallSize: ImageTransform!
Expand All @@ -133,19 +107,9 @@ query LatestPaidActions(
$fxRateFor: SupportedFiatType!
$profileMetadataSource: AppId
) {
result: latestPaidActions(
filter: $filter
where: $where
request: { limit: $limit, cursor: $cursor }
) {
result: forYou(request: { for: $for, limit: $limit, cursor: $cursor }) {
items {
... on FollowPaidAction {
...FollowPaidAction
}

... on OpenActionPaidAction {
...OpenActionPaidAction
}
...ForYouResult
}
pageInfo {
...PaginatedResultInfo
Expand Down
Loading

0 comments on commit ddd810a

Please sign in to comment.