Skip to content

Commit b226381

Browse files
authored
refactor: separate creator identify from normal user
1 parent f246497 commit b226381

File tree

5 files changed

+107
-108
lines changed

5 files changed

+107
-108
lines changed

src/app/u/[handle]/creator/page.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2024 OpenBuild
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { get } from '@/utils/request';
18+
19+
import ProjectOwner from '../ProjectOwner';
20+
21+
export default async function CreatorProfile({ params }) {
22+
const config = { isServer: true };
23+
const { data } = await get(`ts/v1/user/info/handle/${params.handle}`, config);
24+
if (data?.social.user_wallet && data?.base.user_show_wallet) {
25+
data.web3Bio = await get(`https://api.web3.bio/profile/${data?.social.user_wallet}`, {
26+
...config,
27+
headers: {
28+
'X-API-KEY': process.env.NEXT_PUBLIC_WEB3BIO,
29+
},
30+
});
31+
}
32+
if (!data?.base?.user_project_owner) {
33+
return <div>This user is not a creator.</div>;
34+
}
35+
const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config);
36+
return <ProjectOwner data={data} activities={activityData?.list || []} />;
37+
}

src/app/u/[handle]/page.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
import { get } from '@/utils/request';
1818

19-
import ProjectOwner from './ProjectOwner';
2019
import ProjectPersonal from './ProjectPersonal';
2120

22-
export default async function UserProfile({params}) {
21+
export default async function UserProfile({ params }) {
2322
const config = { isServer: true };
2423
const { data } = await get(`ts/v1/user/info/handle/${params.handle}`, config);
2524

@@ -31,12 +30,5 @@ export default async function UserProfile({params}) {
3130
},
3231
});
3332
}
34-
35-
if (!data?.base?.user_project_owner) {
36-
return <ProjectPersonal data={data} />;
37-
}
38-
39-
const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config);
40-
41-
return <ProjectOwner data={data} activities={activityData?.list || []} />;
33+
return <ProjectPersonal data={data} />;
4234
}

src/domain/profile/views/team-profile/TeamProfile.js

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,50 @@ import TabBarWidget from '../../widgets/tab-bar';
3333
import CustomContent from './CustomContent';
3434
import LatestActivityList from './LatestActivityList';
3535

36-
const tabs = [
37-
{
38-
text: 'Open Course',
39-
node: (
40-
<>
41-
<span className="inline md:hidden">Courses</span>
42-
<span className="hidden md:inline">Open Course</span>
43-
</>
44-
),
45-
view: PublishedCourseListView,
46-
},
47-
{
48-
text: 'Challenges',
49-
node: (
50-
<>
51-
<span className="inline md:hidden">Challenge</span>
52-
<span className="hidden md:inline">Challenges</span>
53-
</>
54-
),
55-
view: PublishedChallengeListView,
56-
},
57-
{
58-
text: 'Bounty',
59-
node: (
60-
<>
61-
<span className="inline md:hidden">Bounty</span>
62-
<span className="hidden md:inline">Bounty</span>
63-
</>
64-
),
65-
view: PublishedBountyListView,
66-
},
67-
{
68-
text: 'Quiz',
69-
node: (
70-
<>
71-
<span className="inline md:hidden">Quiz</span>
72-
<span className="hidden md:inline">Quiz</span>
73-
</>
74-
),
75-
view: PublishedQuizListView,
76-
},
77-
];
36+
const resolveTabs = published => {
37+
return [
38+
{
39+
text: 'Open Course',
40+
node: (
41+
<>
42+
<span className="inline md:hidden">Courses</span>
43+
<span className="hidden md:inline">Open Course({published?.['open_course_num'] ?? 0})</span>
44+
</>
45+
),
46+
view: PublishedCourseListView,
47+
},
48+
{
49+
text: 'Challenges',
50+
node: (
51+
<>
52+
<span className="inline md:hidden">Challenge</span>
53+
<span className="hidden md:inline">Challenges({published?.['challenge_num'] ?? 0})</span>
54+
</>
55+
),
56+
view: PublishedChallengeListView,
57+
},
58+
{
59+
text: 'Bounty',
60+
node: (
61+
<>
62+
<span className="inline md:hidden">Bounty</span>
63+
<span className="hidden md:inline">Bounty({published?.['bounty_num'] ?? 0})</span>
64+
</>
65+
),
66+
view: PublishedBountyListView,
67+
},
68+
{
69+
text: 'Quiz',
70+
node: (
71+
<>
72+
<span className="inline md:hidden">Quiz</span>
73+
<span className="hidden md:inline">Quiz({published?.['quiz_num'] ?? 0})</span>
74+
</>
75+
),
76+
view: PublishedQuizListView,
77+
},
78+
];
79+
};
7880

7981
function TeamProfileView({ data, activities }) {
8082
const [tabActive, setTabActive] = useState(1);
@@ -83,11 +85,12 @@ function TeamProfileView({ data, activities }) {
8385
const devPlazaEnabled = useAppConfig('devPlaza.enabled');
8486

8587
useMounted(() => {
86-
devPlazaEnabled && fetchBlockContent(data?.base.user_id).then(res => {
87-
if (res.success) {
88-
setBlockContent(res.data);
89-
}
90-
});
88+
devPlazaEnabled &&
89+
fetchBlockContent(data?.base.user_id).then(res => {
90+
if (res.success) {
91+
setBlockContent(res.data);
92+
}
93+
});
9194
});
9295

9396
const handleBlockChange = useDebouncedCallback(updateBlockContent, 3000);
@@ -121,7 +124,7 @@ function TeamProfileView({ data, activities }) {
121124
onChange={setTabActive}
122125
/>
123126
{tabContent[tabActive]}
124-
<ActivityTabListWidget userId={data?.base.user_id} tabs={tabs} />
127+
<ActivityTabListWidget userId={data?.base.user_id} tabs={resolveTabs(data?.num)} />
125128
</div>
126129
);
127130
}

src/domain/profile/widgets/social-info/PublishedCountList.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/domain/profile/widgets/social-info/SocialInfo.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ import { useMemo } from 'react';
1818

1919
import { SvgIcon } from '@/components/Image';
2020

21-
import PublishedCountList from './PublishedCountList';
2221
import SocialLink from './SocialLink';
2322
import Web3BioProfile from './Web3BioProfile';
2423

2524
function socialsInfo(type, link) {
26-
switch(type) {
25+
switch (type) {
2726
case 'user_github':
2827
return {
2928
name: 'GitHub',
@@ -51,15 +50,21 @@ function socialsInfo(type, link) {
5150
}
5251

5352
function SocialInfoWidget({ className, data }) {
54-
const socials = useMemo(() => Object.keys(data.social).map(i => socialsInfo(i, data.social[i])).filter(s => {
55-
if (!s) {
56-
return false;
57-
}
53+
const socials = useMemo(
54+
() =>
55+
Object.keys(data.social)
56+
.map(i => socialsInfo(i, data.social[i]))
57+
.filter(s => {
58+
if (!s) {
59+
return false;
60+
}
5861

59-
const enabled = s.enableKey ? data.base[s.enableKey] : true;
62+
const enabled = s.enableKey ? data.base[s.enableKey] : true;
6063

61-
return enabled && !!s.link;
62-
}), [data]);
64+
return enabled && !!s.link;
65+
}),
66+
[data],
67+
);
6368

6469
return (
6570
<div className={className}>
@@ -68,15 +73,14 @@ function SocialInfoWidget({ className, data }) {
6873
<p className="mt-6 uppercase text-xs opacity-60 font-bold">Social Profiles</p>
6974
<div className="border border-gray-600 rounded overflow-hidden mt-2">
7075
{socials.map(i => (
71-
<SocialLink key={`user-social-${i.name}`} url={i.link} icon={i.icon} extra={i.extra}>{i.name}</SocialLink>
76+
<SocialLink key={`user-social-${i.name}`} url={i.link} icon={i.icon} extra={i.extra}>
77+
{i.name}
78+
</SocialLink>
7279
))}
7380
</div>
7481
</>
7582
)}
7683
<Web3BioProfile data={data} />
77-
{data.base?.user_project_owner && (
78-
<PublishedCountList published={data?.num} />
79-
)}
8084
{data.base?.user_show_email && data?.social?.user_email !== '' && (
8185
<>
8286
<hr className="border-t border-gray-600 mt-6 mb-4" />

0 commit comments

Comments
 (0)