Skip to content

Commit 814d592

Browse files
committed
refactor(app/profile): hide skill insight tab while no data
1 parent 731e4a1 commit 814d592

File tree

7 files changed

+105
-20
lines changed

7 files changed

+105
-20
lines changed

src/domain/profile/repository.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { unwrapBlockData, wrapBlockData } from '@/components/control/block-edito
1818
import httpClient from '@/utils/http';
1919

2020
import { fetchGainedReputationList } from '../reputation/repository';
21+
import { fetchUserSkills } from '../skill/repository';
2122

2223
async function fetchWeb3BioProfile(address) {
2324
return httpClient.get(`https://api.web3.bio/profile/${address}`, {
@@ -39,10 +40,15 @@ async function fetchUser(handle) {
3940
data.web3Bio = web3BioProfile;
4041
}
4142

42-
const { data: reputation } = await fetchGainedReputationList(data?.base.user_id);
43+
const userId = data.base.user_id;
44+
45+
const { data: reputation } = await fetchGainedReputationList(userId);
46+
const { data: skill } = await fetchUserSkills(userId);
47+
4348
data.extra = {
4449
...data.extra,
4550
reputationList: reputation.list,
51+
skill,
4652
};
4753

4854
return { ...others, data, success: true };

src/domain/profile/views/individual-profile/IndividualProfile.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import clsx from 'clsx';
1718
import { useState } from 'react';
1819

1920
import AppliedBountyListView from '../../../bounty/views/applied-bounty-list';
@@ -70,25 +71,45 @@ const tabs = [
7071
},
7172
];
7273

73-
function IndividualProfileView({ data }) {
74-
const [tabActive, setTabActive] = useState(2);
75-
const userId = data?.base.user_id;
74+
function resolveBasicTabGroup(data) {
75+
const { reputationList, skill } = data?.extra || {};
7676

77+
const tabLabels = ['Info', 'Reputation'];
7778
const tabContent = [
7879
<SocialInfoWidget key="social" data={data} />,
79-
<GainedReputationListView key="reputation" data={data?.extra.reputationList} />,
80-
<SkillOverviewView key="skill" userId={userId} />,
80+
<GainedReputationListView key="reputation" data={reputationList} />,
8181
];
8282

83+
if (skill) {
84+
tabLabels.push('Skill insight');
85+
tabContent.push(<SkillOverviewView key="skill" data={skill} />);
86+
}
87+
88+
return {
89+
tabLabels,
90+
tabContent,
91+
hideInDesktop: !skill,
92+
};
93+
}
94+
95+
function IndividualProfileView({ data }) {
96+
const [tabActive, setTabActive] = useState(data?.extra.skill ? 2 : 1);
97+
98+
const userId = data?.base.user_id;
99+
const { tabLabels, tabContent, hideInDesktop } = resolveBasicTabGroup(data);
100+
83101
return (
84102
<div className="md:pl-[410px] md:pb-14 md:pr-14">
85103
<TabBarWidget
86-
tabs={['Info', 'Reputation', 'Skill insight']}
87-
tabClassName={`h-14 md:h-9 md:w-[119px] ${style.Tab}`}
104+
className={clsx({ 'md:hidden': hideInDesktop })}
105+
tabs={tabLabels}
106+
tabClassName={clsx('h-14 md:h-9 md:w-[119px]', style.Tab)}
88107
current={tabActive}
89108
onChange={setTabActive}
90109
/>
91-
{tabContent[tabActive]}
110+
<div className={clsx('mb-9', { 'md:hidden': hideInDesktop })}>
111+
{tabContent[tabActive]}
112+
</div>
92113
<ActivityTabListWidget userId={userId} tabs={tabs} />
93114
</div>
94115
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ function SocialInfoWidget({ className, data }) {
9797
</>
9898
)}
9999
{data?.extra?.reputationList?.length > 0 && (
100-
<>
101-
<p className="mt-6 uppercase text-xs opacity-60 font-bold">Reputation</p>
100+
<div className="mt-6 max-md:hidden">
101+
<p className="uppercase text-xs opacity-60 font-bold">Reputation</p>
102102
<GainedReputationListView data={data?.extra?.reputationList} compact />
103-
</>
103+
</div>
104104
)}
105105
<Web3BioProfile data={data} />
106106
{data.base?.user_show_email && data?.social?.user_email !== '' && (

src/domain/skill/typing.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/**
3+
* Copyright 2024 OpenBuild
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import type { DataValue, ListValue } from '@/types';
19+
20+
type SkillResponseData = {
21+
skill_datas?: ListValue;
22+
aspecta_show?: boolean;
23+
skill_user?: Record<string, DataValue>;
24+
}
25+
26+
export type { SkillResponseData };

src/domain/skill/views/skill-overview/SkillOverview.js renamed to src/domain/skill/views/skill-overview/SkillOverview.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,44 @@ import { useState } from 'react';
1919
import { NoData } from '@/components/NoData';
2020
import useMounted from '@/hooks/useMounted';
2121

22+
import type { SkillResponseData } from '../../typing';
23+
import type { SkillOverviewViewWidgetProps } from './typing';
24+
2225
import { fetchUserSkills } from '../../repository';
2326
import SkillInsight from '../../widgets/skill-insight';
2427
import SkillLevel from '../../widgets/skill-level';
2528

26-
function SkillOverviewView({ userId }) {
27-
const [data, setData] = useState({});
29+
function SkillOverviewView({ userId, data = {} }: SkillOverviewViewWidgetProps) {
30+
const [internalData, setInternalData] = useState<SkillResponseData>(data);
2831

2932
useMounted(() => {
33+
if (!userId) {
34+
return;
35+
}
36+
3037
fetchUserSkills(userId)
3138
.then(res => {
32-
setData(res?.data);
39+
setInternalData(res?.data);
3340
});
3441
});
3542

3643
return (
3744
<div>
3845
<div className="mt-6">
39-
{data?.skill_datas && data?.skill_datas.length > 0 ? (
46+
{internalData?.skill_datas && internalData?.skill_datas.length > 0 ? (
4047
<>
4148
<div className="flex items-center justify-between mb-4">
4249
<h3 className="text-sm font-semibold">Skills</h3>
4350
</div>
44-
<SkillLevel data={data} />
51+
<SkillLevel data={internalData} />
4552
</>
4653
) : (
4754
<NoData />
4855
)}
4956
</div>
50-
{data?.aspecta_show && (
57+
{internalData?.aspecta_show && (
5158
<SkillInsight
52-
data={data?.skill_user.user_extra_skills}
59+
data={internalData?.skill_user?.user_extra_skills}
5360
headerClassName="mt-9"
5461
titleClassName="text-sm font-semibold"
5562
/>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 type { SkillResponseData } from '../../typing';
18+
import type { EntityId } from '@/types';
19+
20+
type SkillOverviewViewWidgetProps = {
21+
userId?: EntityId;
22+
data?: SkillResponseData;
23+
}
24+
25+
export type { SkillOverviewViewWidgetProps };

src/domain/skill/widgets/skill-insight/SkillInsight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function CustomizedContent(props) {
5959
}
6060

6161
function SkillInsight({
62-
className,
62+
className = undefined,
6363
headerClassName,
6464
titleClassName,
6565
data,

0 commit comments

Comments
 (0)