-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Profile.tsx
144 lines (138 loc) · 4.45 KB
/
Profile.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { APP_NAME } from '@hey/data/constants';
import type { AnyPublication } from '@hey/lens';
import { Profile } from '@hey/lens';
import getAvatar from '@hey/lib/getAvatar';
import getProfile from '@hey/lib/getProfile';
import truncateByWords from '@hey/lib/truncateByWords';
import type { FC } from 'react';
import { JsonLd } from 'react-schemaorg';
import { BASE_URL } from 'src/constants';
import DefaultTags from './Shared/DefaultTags';
import SinglePublication from './Shared/SinglePublication';
import Tags from './Shared/Tags';
interface ProfileProps {
profile: Profile;
publications: AnyPublication[];
}
const Profile: FC<ProfileProps> = ({ profile, publications }) => {
if (!profile) {
return <DefaultTags />;
}
const title = `${getProfile(profile).displayName} (${
getProfile(profile).slugWithPrefix
}) • ${APP_NAME}`;
const description = truncateByWords(profile.metadata?.bio ?? '', 30);
const image = getAvatar(profile);
return (
<>
<Tags
title={title}
description={description}
image={image}
url={`${BASE_URL}${getProfile(profile).link}`}
schema={
<JsonLd<any>
item={{
'@context': 'https://schema.org',
'@type': 'ProfilePage',
author: {
'@type': 'Person',
additionalName: getProfile(profile).slug,
description: profile.metadata?.bio,
givenName: getProfile(profile).displayName,
identifier: profile.id,
image: {
'@type': 'ImageObject',
contentUrl: image,
thumbnailUrl: image
},
interactionStatistic: [
{
'@type': 'InteractionCounter',
interactionType: 'https://schema.org/FollowAction',
name: 'Follows',
userInteractionCount: profile.stats.followers
},
{
'@type': 'InteractionCounter',
interactionType: 'https://schema.org/SubscribeAction',
name: 'Following',
userInteractionCount: profile.stats.following
},
{
'@type': 'InteractionCounter',
interactionType: 'https://schema.org/WriteAction',
name: 'Posts',
userInteractionCount: profile.stats.posts
}
],
url: `https://hey.xyz/${getProfile(profile).slug}}`
}
}}
/>
}
/>
<header>
<img
alt={`${getProfile(profile).slugWithPrefix}'s avatar`}
src={image}
width="64"
/>
<h1>{getProfile(profile).displayName}</h1>
<h2>{getProfile(profile).slugWithPrefix}</h2>
<h3>{truncateByWords(profile.metadata?.bio ?? '', 30)}</h3>
<div>
<div>{profile.stats.posts} Posts</div>
<div>{profile.stats.comments} Replies</div>
<div>{profile.stats.following} Following</div>
<div>{profile.stats.followers} Followers</div>
<div>{profile.stats.mirrors} Mirrors</div>
</div>
<hr />
<nav>
<div>
<a href={`${BASE_URL}${getProfile(profile).link}`}>Feed</a>
</div>
<div>
<a href={`${BASE_URL}${getProfile(profile).link}?type=replies`}>
Replies
</a>
</div>
<div>
<a href={`${BASE_URL}${getProfile(profile).link}?type=media`}>
Media
</a>
</div>
<div>
<a href={`${BASE_URL}${getProfile(profile).link}?type=collects`}>
Collected
</a>
</div>
<div>
<a href={`${BASE_URL}${getProfile(profile).link}?type=gallery`}>
Gallery
</a>
</div>
</nav>
<hr />
</header>
<div>
{publications?.map((publication) => {
const { __typename } = publication;
return (
<div
key={
__typename === 'Mirror'
? publication.mirrorOn.id
: publication.id
}
>
<SinglePublication publication={publication} />
</div>
);
})}
</div>
</>
);
};
export default Profile;