Skip to content

Commit

Permalink
followloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuaige1234567 committed Dec 13, 2023
1 parent 8f7162a commit 7f0cce9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
14 changes: 12 additions & 2 deletions frontend/src/actors/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class User {
}

async batchGetProfile(who: Principal[]): Promise<Profile[]> {
// async batchGetProfile(who: Principal[]): Promise<unknown> {
// async batchGetProfile(who: Principal[]): Promise<unknown> {
const actor = await User.getActor();
try {
return await actor.batchGetProfile(who) as Profile[]
// return await actor.batchGetProfile(who)
} catch(e) {
} catch (e) {
console.log("batchGetProfile", e)
throw e
}
Expand Down Expand Up @@ -75,6 +75,16 @@ class User {
throw e
}
}

async isFollowed(A: Principal, B: Principal) {//判断 A 是否是 B的粉丝
const actor = await User.getActor()
try {
return await actor.isFollowed(A, B) as boolean
} catch (e) {
console.log("isFollowed", e)
throw e
}
}
}


Expand Down
20 changes: 16 additions & 4 deletions frontend/src/routes/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {rootFeedApi} from "../actors/rootFeed";
import Feed from "../actors/feed";
import {useAllDataStore, useProfileStore} from "../redux";
import {useAuth} from "../utils/useAuth";
import { LoadingOutlined, CheckOutlined } from '@ant-design/icons';
import {LoadingOutlined, CheckOutlined} from '@ant-design/icons';


export default function UserProfile() {
Expand All @@ -25,6 +25,7 @@ export default function UserProfile() {
const [following, setFollowing] = useState(0)
const [followers, setFollowers] = useState(0)
const [allPosts, setAllPosts] = useState<PostImmutable[]>()
const [isFollowed, setIsFollowed] = useState(true)
const [api, contextHolder] = notification.useNotification();
const {userid} = useParams()
const [commentProfiles, setCommentProfiles] = useState<Profile[]>()
Expand All @@ -43,6 +44,7 @@ export default function UserProfile() {
getAllCommentProfiles()
}, [postItem])


const principal = React.useMemo(() => {
try {
return Principal.from(userid)
Expand All @@ -52,6 +54,14 @@ export default function UserProfile() {
}
}, [userid])

useEffect(() => {

me && principal && userApi.isFollowed(me, principal).then(e => {
setIsFollowed(e)
})
}, [me, principal])


const isMe: boolean = React.useMemo(() => {
if (!me) return false
if (!principal) return false
Expand Down Expand Up @@ -112,14 +122,14 @@ export default function UserProfile() {
key: 'follow',
duration: null,
description: '',
icon: <LoadingOutlined />
icon: <LoadingOutlined/>
})
await userApi.follow(principal);
api.success({
message: 'Follow Successful !',
key: 'follow',
description: '',
icon: <CheckOutlined />
icon: <CheckOutlined/>
});
}
}
Expand All @@ -134,6 +144,7 @@ export default function UserProfile() {
scrollbarWidth: 'thin',
borderRight: '1px solid rgba(0,0,0,0.2)',
}}>
{contextHolder}
<Image
style={{borderRadius: "5px", maxHeight: '100px', maxWidth: '100%'}}
src={userProfile?.backImgUrl ? userProfile.backImgUrl : 'https://infura-ipfs.mora.host/ipfs/QmbEN76wm4PExViLVmUbKf4vDfx3XkpnYvm6qr3JKCSPDT'}
Expand All @@ -159,7 +170,8 @@ export default function UserProfile() {
/>
<Typography.Text strong>{userProfile?.name}</Typography.Text>
</Space>
<Button onClick={handleFollow}> {isMe ? "Edit Profile" : "Follow"} </Button>
<Button style={{display: !isMe && isFollowed ? "none" : "flex"}}
onClick={handleFollow}> {isMe ? "Edit Profile" : "Follow"} </Button>
<Modal
title="Edit Profile Information"
open={isModalOpen}
Expand Down

0 comments on commit 7f0cce9

Please sign in to comment.