Skip to content

Commit

Permalink
fix: lens detail, lens feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlysxw committed Nov 10, 2023
1 parent ab428f4 commit ca0c79f
Show file tree
Hide file tree
Showing 37 changed files with 1,037 additions and 430 deletions.
10 changes: 5 additions & 5 deletions apps/u3/src/components/layout/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
import styled from 'styled-components';
import { useNavigate } from 'react-router-dom';
import { useActiveProfile } from '@lens-protocol/react-web';
import { useState } from 'react';
import LoginButton from './LoginButton';
import Nav, { NavWrapper, PcNavItem, PcNavItemIconBox } from './Nav';
Expand All @@ -29,15 +28,16 @@ import NotificationModal from '../notification/NotificationModal';
import NotificationModalNoLens from '../notification/NotificationModal_NoLens';
import useFarcasterCurrFid from '../../hooks/social/farcaster/useFarcasterCurrFid';
import { useNav } from '../../contexts/NavCtx';
import { useLensCtx } from '../../contexts/social/AppLensCtx';

export default function Menu() {
// const { logout } = useLogin();
const [isOpen, setIsOpen] = useState(false);
const navigate = useNavigate();
// const [openLogoutConfirm, setOpenLogoutConfirm] = useState(false);

const { data: lensProfile } = useActiveProfile();
const lensProfileId = lensProfile?.id;
const { sessionProfile: lensSessionProfile } = useLensCtx();
const { id: lensSessionProfileId } = lensSessionProfile || {};
const fid = Number(useFarcasterCurrFid());

return (
Expand All @@ -61,11 +61,11 @@ export default function Menu() {
Profile的情况下,无法使用Lens的useUnreadLensNotificationCount,所以这里使用了两套Notification组件,
等Lens Hooks V2这里需要重构 */}
<NavWrapper>
{lensProfileId ? (
{lensSessionProfileId ? (
<NotificationStoreProvider
config={{
fid,
lensProfileId,
lensProfileId: lensSessionProfileId,
}}
>
<NotificationButton />
Expand Down
28 changes: 13 additions & 15 deletions apps/u3/src/components/profile/ProfileSocial.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { useCallback, useEffect } from 'react';
import styled from 'styled-components';
import { useActiveProfile } from '@lens-protocol/react-web';
import { Comment, Mirror, Post, 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/LensPostCard';
import FCast from '../social/farcaster/FCast';
import { useFarcasterCtx } from '../../contexts/social/FarcasterCtx';
import { ProfileFeedsGroups } from '../../services/social/api/feeds';
import {
LensComment,
LensMirror,
LensPost,
} from '../../services/social/api/lens';
import Rss3Content from '../fren/Rss3Content';
import { NoActivity } from '../../container/Activity';
import { useLensCtx } from '../../contexts/social/AppLensCtx';

export function ProfileSocialPosts({
lensProfileId,
Expand All @@ -26,8 +22,10 @@ export function ProfileSocialPosts({
group: ProfileFeedsGroups;
}) {
const { openFarcasterQR, farcasterUserData } = useFarcasterCtx();
const { data: activeLensProfile, loading: activeLensProfileLoading } =
useActiveProfile();
const { loading: activeLensProfileLoading } = useSession();
const { sessionProfile: lensSessionProfile } = useLensCtx();

const { id: lensSessionProfileId } = lensSessionProfile || {};

const {
firstLoading,
Expand All @@ -40,21 +38,21 @@ export function ProfileSocialPosts({

const loadFirstSocialFeeds = useCallback(() => {
loadFirstFeeds({
activeLensProfileId: activeLensProfile?.id,
activeLensProfileId: lensSessionProfileId,
lensProfileId,
fid,
group,
});
}, [loadFirstFeeds, activeLensProfile?.id, fid, group, lensProfileId]);
}, [loadFirstFeeds, lensSessionProfileId, fid, group, lensProfileId]);

const loadMoreSocialFeeds = useCallback(() => {
loadMoreFeeds({
activeLensProfileId: activeLensProfile?.id,
activeLensProfileId: lensSessionProfileId,
lensProfileId,
fid,
group,
});
}, [loadMoreFeeds, activeLensProfile?.id, fid, group, lensProfileId]);
}, [loadMoreFeeds, lensSessionProfileId, fid, group, lensProfileId]);

useEffect(() => {
if (activeLensProfileLoading) return;
Expand Down Expand Up @@ -95,13 +93,13 @@ export function ProfileSocialPosts({
let d;
switch (group) {
case ProfileFeedsGroups.POSTS:
d = data as LensPost;
d = data as Post;
break;
case ProfileFeedsGroups.REPOSTS:
d = (data as LensMirror).mirrorOf;
d = (data as Mirror).mirrorOn;
break;
case ProfileFeedsGroups.REPLIES:
d = (data as LensComment).commentOn;
d = (data as Comment).commentOn;
break;
default:
break;
Expand Down
47 changes: 20 additions & 27 deletions apps/u3/src/components/profile/lens/LensFollowProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {
Profile,
ProfileOwnedByMe,
useActiveProfile,
useFollow,
useUnfollow,
} from '@lens-protocol/react-web';
import { Profile, useFollow, useUnfollow } from '@lens-protocol/react-web';
import { useMemo } from 'react';
import { StyledComponentPropsWithRef } from 'styled-components';
import FollowProfileCard from '../FollowProfileCard';
import { useLensCtx } from '../../../contexts/social/AppLensCtx';
import { SocialPlatform } from '../../../services/social/types';
import getAvatar from '../../../utils/social/lens/getAvatar';
import {
getBio,
getHandle,
getName,
getOwnedByAddress,
} from '../../../utils/social/lens/profile';
import { isFollowedByMe } from '../../../utils/social/lens/operations';

type LensFollowProfileCardProps = StyledComponentPropsWithRef<'div'> & {
profile?: Profile;
Expand All @@ -22,26 +23,18 @@ export default function LensFollowProfileCard({
...wrapperProps
}: LensFollowProfileCardProps) {
const { isLogin: isLoginLens, setOpenLensLoginModal } = useLensCtx();
const { data: lensActiveProfile } = useActiveProfile();
const { execute: lensFollow, isPending: lensFollowIsPending } = useFollow({
followee: profile,
follower: (lensActiveProfile || { ownedBy: '' }) as ProfileOwnedByMe,
});
const { execute: lensUnfollow, isPending: lensUnfollowPending } = useUnfollow(
{
followee: profile,
follower: (lensActiveProfile || { ownedBy: '' }) as ProfileOwnedByMe,
}
);

const { execute: follow, loading: followLoading } = useFollow();
const { execute: unfollow, loading: unfollowLoading } = useUnfollow();
const viewData = useMemo(
() => ({
handle: profile.handle,
address: profile.ownedBy,
name: profile.name,
handle: getHandle(profile),
address: getOwnedByAddress(profile),
name: getName(profile),
avatar: getAvatar(profile),
bio: profile.bio,
bio: getBio(profile),
isFollowed:
isFollowingCard && !isLoginLens ? true : profile.isFollowedByMe,
isFollowingCard && !isLoginLens ? true : isFollowedByMe(profile),
platforms: [SocialPlatform.Lens],
}),
[profile, isFollowingCard, isLoginLens]
Expand All @@ -50,21 +43,21 @@ export default function LensFollowProfileCard({
return (
<FollowProfileCard
data={viewData}
followPending={lensFollowIsPending}
unfollowPending={lensUnfollowPending}
followPending={followLoading}
unfollowPending={unfollowLoading}
followAction={() => {
if (!isLoginLens) {
setOpenLensLoginModal(true);
return;
}
lensFollow();
follow({ profile });
}}
unfollowAction={() => {
if (!isLoginLens) {
setOpenLensLoginModal(true);
return;
}
lensUnfollow();
unfollow({ profile });
}}
{...wrapperProps}
/>
Expand Down
184 changes: 184 additions & 0 deletions apps/u3/src/components/profile/v1/ProfileSocial.tsx
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;
}
`;
Loading

0 comments on commit ca0c79f

Please sign in to comment.