New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: better tipping data display #4779
Changes from 6 commits
6363ae9
fd53efe
3a782f3
b0c97ed
a9e8362
29bd91d
2a4305a
b969531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import type { | ||
AnyPublication, | ||
UnknownOpenActionModuleSettings | ||
} from '@hey/lens'; | ||
import type { FC } from 'react'; | ||
|
||
import { PUBLICATION } from '@hey/data/tracking'; | ||
import { VerifiedOpenActionModules } from '@hey/data/verified-openaction-modules'; | ||
import { TipIcon } from '@hey/icons'; | ||
import { TipIconSolid } from '@hey/icons/src/TipIconSolid'; | ||
import { | ||
type AnyPublication, | ||
type UnknownOpenActionModuleSettings, | ||
useUnknownOpenActionDataQuery | ||
} from '@hey/lens'; | ||
import nFormatter from '@hey/lib/nFormatter'; | ||
import { isMirrorPublication } from '@hey/lib/publicationHelpers'; | ||
import { Modal, Tooltip } from '@hey/ui'; | ||
import cn from '@hey/ui/cn'; | ||
import { Leafwatch } from '@lib/leafwatch'; | ||
import { motion } from 'framer-motion'; | ||
import { useState } from 'react'; | ||
|
@@ -29,6 +33,13 @@ const TipOpenAction: FC<TipOpenActionProps> = ({ | |
? publication?.mirrorOn | ||
: publication; | ||
|
||
const { data: tipData } = useUnknownOpenActionDataQuery({ | ||
variables: { | ||
module: VerifiedOpenActionModules.Tip, | ||
pubId: targetPublication.id | ||
} | ||
}); | ||
|
||
const module = targetPublication.openActionModules.find( | ||
(module) => module.contract.address === VerifiedOpenActionModules.Tip | ||
); | ||
|
@@ -37,13 +48,27 @@ const TipOpenAction: FC<TipOpenActionProps> = ({ | |
return null; | ||
} | ||
|
||
const hasTipped = | ||
tipData?.publication?.__typename === 'Post' && | ||
Boolean(tipData.publication.operations.actedOn.length); | ||
|
||
const countTips = | ||
(tipData?.publication?.__typename === 'Post' && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why only post? why not comments, mirrors and quotes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of a mirror we're looking at the target publication ID, so it's still be true here if the original post has tips. I don't think |
||
tipData.publication.stats.countOpenActions) || | ||
0; | ||
|
||
const iconClassName = isFullPublication | ||
? 'w-[17px] sm:w-[20px]' | ||
: 'w-[15px] sm:w-[18px]'; | ||
|
||
return ( | ||
<> | ||
<div className="ld-text-gray-500"> | ||
<div | ||
className={cn( | ||
hasTipped ? 'text-brand-500' : 'ld-text-gray-500', | ||
'flex items-center space-x-1' | ||
)} | ||
> | ||
<motion.button | ||
aria-label="Tip" | ||
className="rounded-full p-1.5 outline-offset-2 hover:bg-gray-300/20" | ||
|
@@ -56,9 +81,18 @@ const TipOpenAction: FC<TipOpenActionProps> = ({ | |
whileTap={{ scale: 0.9 }} | ||
> | ||
<Tooltip content="Tip" placement="top" withDelay> | ||
<TipIcon className={iconClassName} /> | ||
{hasTipped ? ( | ||
<TipIconSolid className={iconClassName} /> | ||
) : ( | ||
<TipIcon className={iconClassName} /> | ||
)} | ||
</Tooltip> | ||
</motion.button> | ||
{countTips > 0 && !isFullPublication ? ( | ||
<span className="text-[11px] sm:text-xs"> | ||
{nFormatter(countTips)} | ||
</span> | ||
) : null} | ||
</div> | ||
<Modal | ||
icon={<TipIcon className="size-5" />} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import type { Profile, WhoActedOnPublicationRequest } from '@hey/lens'; | ||
import type { FC } from 'react'; | ||
|
||
import ProfileListShimmer from '@components/Shared/Shimmer/ProfileListShimmer'; | ||
import UserProfile from '@components/Shared/UserProfile'; | ||
import { ArrowLeftIcon } from '@heroicons/react/24/outline'; | ||
import { ProfileLinkSource } from '@hey/data/tracking'; | ||
import { VerifiedOpenActionModules } from '@hey/data/verified-openaction-modules'; | ||
import { TipIcon } from '@hey/icons'; | ||
import { LimitType, useWhoActedOnPublicationQuery } from '@hey/lens'; | ||
import { Card, EmptyState, ErrorMessage } from '@hey/ui'; | ||
import Link from 'next/link'; | ||
import { Virtuoso } from 'react-virtuoso'; | ||
import { useProfileStore } from 'src/store/persisted/useProfileStore'; | ||
|
||
interface TippersProps { | ||
publicationId: string; | ||
} | ||
|
||
const Tippers: FC<TippersProps> = ({ publicationId }) => { | ||
const { currentProfile } = useProfileStore(); | ||
|
||
// Variables | ||
const request: WhoActedOnPublicationRequest = { | ||
limit: LimitType.TwentyFive, | ||
on: publicationId, | ||
where: { | ||
anyOf: [{ address: VerifiedOpenActionModules.Tip }] | ||
} | ||
}; | ||
|
||
const { data, error, fetchMore, loading } = useWhoActedOnPublicationQuery({ | ||
skip: !publicationId, | ||
variables: { request } | ||
}); | ||
|
||
const profiles = data?.whoActedOnPublication?.items; | ||
const pageInfo = data?.whoActedOnPublication?.pageInfo; | ||
const hasMore = pageInfo?.next; | ||
|
||
const onEndReached = async () => { | ||
if (!hasMore) { | ||
return; | ||
} | ||
|
||
await fetchMore({ | ||
variables: { request: { ...request, cursor: pageInfo?.next } } | ||
}); | ||
}; | ||
|
||
if (loading) { | ||
return <ProfileListShimmer />; | ||
} | ||
|
||
if (profiles?.length === 0) { | ||
return ( | ||
<div className="p-5"> | ||
<EmptyState | ||
hideCard | ||
icon={<TipIcon className="size-8" />} | ||
message="No tippers." | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<ErrorMessage | ||
className="m-5" | ||
error={error} | ||
title="Failed to load tippers" | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Card> | ||
<div className="flex items-center space-x-3 p-5"> | ||
<Link href={`/posts/${publicationId}`}> | ||
<ArrowLeftIcon className="size-5" /> | ||
</Link> | ||
<b className="text-lg">Tipped by</b> | ||
</div> | ||
<div className="divider" /> | ||
<Virtuoso | ||
className="virtual-divider-list-window" | ||
computeItemKey={(index, profile) => `${profile.id}-${index}`} | ||
data={profiles} | ||
endReached={onEndReached} | ||
itemContent={(_, profile) => { | ||
return ( | ||
<div className="p-5"> | ||
<UserProfile | ||
hideFollowButton={currentProfile?.id === profile.id} | ||
hideUnfollowButton={currentProfile?.id === profile.id} | ||
profile={profile as Profile} | ||
showBio | ||
showUserPreview={false} | ||
source={ProfileLinkSource.Tips} | ||
/> | ||
</div> | ||
); | ||
}} | ||
useWindowScroll | ||
/> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default Tippers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ViewPublication from '@components/Publication'; | ||
|
||
export default ViewPublication; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is interesting, just found out that it gonna rate limit users. When someone opens a feed and keeps scrolling, it gonna makes 1 extra API call per post. This need to be fixed by somehow using GraphQL alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to switch this PR to a draft since the current approach is not feasible due to rate limiting and partial alias support in graphql-codegen. (more here)