-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab428f4
commit ca0c79f
Showing
37 changed files
with
1,037 additions
and
430 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
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,184 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import styled from 'styled-components'; | ||
import { useSession } from '@lens-protocol/react-web'; | ||
import InfiniteScroll from 'react-infinite-scroll-component'; | ||
import { useLoadProfileFeeds } from '../../../hooks/social/useLoadProfileFeeds'; | ||
import Loading from '../../common/loading/Loading'; | ||
import LensPostCard from '../../social/lens/v1/LensPostCard'; | ||
import FCast from '../../social/farcaster/FCast'; | ||
import { useFarcasterCtx } from '../../../contexts/social/FarcasterCtx'; | ||
import { ProfileFeedsGroups } from '../../../services/social/api/feeds'; | ||
import Rss3Content from '../../fren/Rss3Content'; | ||
import { NoActivity } from '../../../container/Activity'; | ||
import { useLensCtx } from '../../../contexts/social/AppLensCtx'; | ||
|
||
export function ProfileSocialPosts({ | ||
lensProfileId, | ||
fid, | ||
group, | ||
}: { | ||
lensProfileId: string; | ||
fid: string; | ||
group: ProfileFeedsGroups; | ||
}) { | ||
const { openFarcasterQR, farcasterUserData } = useFarcasterCtx(); | ||
const { loading: activeLensProfileLoading } = useSession(); | ||
const { sessionProfile: lensSessionProfile } = useLensCtx(); | ||
|
||
const { id: lensSessionProfileId } = lensSessionProfile || {}; | ||
|
||
const { | ||
firstLoading, | ||
moreLoading, | ||
feeds, | ||
pageInfo, | ||
loadFirstFeeds, | ||
loadMoreFeeds, | ||
} = useLoadProfileFeeds(); | ||
|
||
const loadFirstSocialFeeds = useCallback(() => { | ||
loadFirstFeeds({ | ||
activeLensProfileId: lensSessionProfileId, | ||
lensProfileId, | ||
fid, | ||
group, | ||
}); | ||
}, [loadFirstFeeds, lensSessionProfileId, fid, group, lensProfileId]); | ||
|
||
const loadMoreSocialFeeds = useCallback(() => { | ||
loadMoreFeeds({ | ||
activeLensProfileId: lensSessionProfileId, | ||
lensProfileId, | ||
fid, | ||
group, | ||
}); | ||
}, [loadMoreFeeds, lensSessionProfileId, fid, group, lensProfileId]); | ||
|
||
useEffect(() => { | ||
if (activeLensProfileLoading) return; | ||
loadFirstSocialFeeds(); | ||
}, [activeLensProfileLoading, loadFirstSocialFeeds]); | ||
|
||
return ( | ||
<MainCenter> | ||
{(() => { | ||
if (firstLoading) { | ||
return ( | ||
<LoadingWrapper> | ||
<Loading /> | ||
</LoadingWrapper> | ||
); | ||
} | ||
|
||
return ( | ||
<InfiniteScroll | ||
dataLength={feeds.length} | ||
next={() => { | ||
if (moreLoading) return; | ||
loadMoreSocialFeeds(); | ||
}} | ||
hasMore={!firstLoading && pageInfo.hasNextPage} | ||
loader={ | ||
moreLoading ? ( | ||
<LoadingMoreWrapper> | ||
<Loading /> | ||
</LoadingMoreWrapper> | ||
) : null | ||
} | ||
scrollableTarget="profile-wrapper" | ||
> | ||
<PostList> | ||
{feeds.map(({ platform, data }) => { | ||
if (platform === 'lens') { | ||
let d; | ||
switch (group) { | ||
case ProfileFeedsGroups.POSTS: | ||
d = data as any; | ||
break; | ||
case ProfileFeedsGroups.REPOSTS: | ||
d = (data as any).mirrorOf; | ||
break; | ||
case ProfileFeedsGroups.REPLIES: | ||
d = (data as any).commentOn; | ||
break; | ||
default: | ||
break; | ||
} | ||
if (!d) return null; | ||
return <LensPostCard key={d.id} data={d} />; | ||
} | ||
if (platform === 'farcaster') { | ||
const key = Buffer.from(data.hash.data).toString('hex'); | ||
return ( | ||
<FCast | ||
key={key} | ||
cast={data} | ||
openFarcasterQR={openFarcasterQR} | ||
farcasterUserData={farcasterUserData} | ||
/> | ||
); | ||
} | ||
return null; | ||
})} | ||
</PostList> | ||
</InfiniteScroll> | ||
); | ||
})()} | ||
</MainCenter> | ||
); | ||
} | ||
export function ProfileSocialActivity({ address }: { address: string }) { | ||
return ( | ||
<MainCenter> | ||
<Rss3Content | ||
address={[address]} | ||
empty={ | ||
<NoActivityWrapper> | ||
<NoActivity /> | ||
</NoActivityWrapper> | ||
} | ||
/> | ||
</MainCenter> | ||
); | ||
} | ||
|
||
const MainCenter = styled.div` | ||
width: 100%; | ||
`; | ||
const LoadingWrapper = styled.div` | ||
width: 100%; | ||
height: 80vh; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
const LoadingMoreWrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin-top: 20px; | ||
`; | ||
const PostList = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1px; | ||
border-radius: 20px; | ||
/* border-top-right-radius: 0; | ||
border-top-left-radius: 0; */ | ||
background: #212228; | ||
overflow: hidden; | ||
& > *:not(:first-child) { | ||
border-top: 1px solid #718096; | ||
} | ||
`; | ||
const NoActivityWrapper = styled.div` | ||
.no-item { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
`; |
Oops, something went wrong.