-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #907 from lens-protocol/T-19927/useLatestPaidActions
feat: adds useLatestPaidActions hook
- Loading branch information
Showing
25 changed files
with
35,286 additions
and
19,140 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,8 @@ | ||
--- | ||
"@lens-protocol/react": minor | ||
"@lens-protocol/react-native": minor | ||
"@lens-protocol/react-web": minor | ||
"@lens-protocol/api-bindings": patch | ||
--- | ||
|
||
**feat:** adds `useLatestPaidActions` hook |
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useLatestPaidActions } from '@lens-protocol/react-web'; | ||
|
||
import { RequireProfileSession } from '../components/auth'; | ||
import { ErrorMessage } from '../components/error/ErrorMessage'; | ||
import { Loading } from '../components/loading/Loading'; | ||
import { useInfiniteScroll } from '../hooks/useInfiniteScroll'; | ||
import { PaidActionItem } from './components/PaidActionItem'; | ||
|
||
function UseLatestPaidActionsInner() { | ||
const { data, error, loading, hasMore, observeRef } = useInfiniteScroll(useLatestPaidActions()); | ||
|
||
if (loading) return <Loading />; | ||
|
||
if (error) return <ErrorMessage error={error} />; | ||
|
||
return ( | ||
<div> | ||
{data.length === 0 && <p>No paid actions found.</p>} | ||
|
||
{data.map((item) => ( | ||
<PaidActionItem key={item.latestActed[0].actedAt} action={item} /> | ||
))} | ||
|
||
{hasMore && <p ref={observeRef}>Loading more...</p>} | ||
</div> | ||
); | ||
} | ||
|
||
export function UseLatestPaidActions() { | ||
return ( | ||
<div> | ||
<h1> | ||
<code>useLatestPaidActions</code> | ||
</h1> | ||
|
||
<RequireProfileSession message="Log in to view this example."> | ||
<UseLatestPaidActionsInner /> | ||
</RequireProfileSession> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AnyPaidAction, FollowPaidAction, OpenActionPaidAction } from '@lens-protocol/react-web'; | ||
|
||
import { formatProfileIdentifier } from '../../utils/formatProfileIdentifier'; | ||
|
||
function FollowPaidActionItem({ action }: { action: FollowPaidAction }) { | ||
return ( | ||
<div> | ||
Followed {formatProfileIdentifier(action.followed)} on {action.latestActed[0].actedAt} | ||
</div> | ||
); | ||
} | ||
|
||
function OpenActionPaidActionItem({ action }: { action: OpenActionPaidAction }) { | ||
return ( | ||
<div> | ||
Acted on publication {action.actedOn.id} on {action.latestActed[0].actedAt} | ||
</div> | ||
); | ||
} | ||
|
||
type PaidActionItemProps = { | ||
action: AnyPaidAction; | ||
}; | ||
|
||
export function PaidActionItem({ action }: PaidActionItemProps) { | ||
switch (action.__typename) { | ||
case 'FollowPaidAction': | ||
return <FollowPaidActionItem action={action} />; | ||
case 'OpenActionPaidAction': | ||
return <OpenActionPaidActionItem action={action} />; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { HandleInfo, Profile } from '@lens-protocol/react-web'; | ||
|
||
function formatHandle(handle: HandleInfo): string { | ||
return `@${handle.fullHandle}`; | ||
} | ||
|
||
export function formatProfileIdentifier(profile: Profile): string { | ||
return ( | ||
profile?.metadata?.displayName ?? (profile.handle ? formatHandle(profile.handle) : profile.id) | ||
); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
packages/api-bindings/src/apollo/cache/field-policies/createLatestPaidActionsFieldPolicy.ts
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,5 @@ | ||
import { cursorBasedPagination } from '../utils/cursorBasedPagination'; | ||
|
||
export function createLatestPaidActionsFieldPolicy() { | ||
return cursorBasedPagination(['where', 'filter']); | ||
} |
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
Oops, something went wrong.