Skip to content

Commit ddd9184

Browse files
committed
refactor: refactor logic of NFT list
1 parent 5e1bba1 commit ddd9184

File tree

7 files changed

+71
-83
lines changed

7 files changed

+71
-83
lines changed

src/domain/profile/repository.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ async function fetchUser(handle) {
3939
data.web3Bio = web3BioProfile;
4040
}
4141

42-
if (data?.base.user_id) {
43-
const { data: reputation } = await fetchGainedReputationList(data?.base.user_id);
44-
data.reputationList = reputation.list;
45-
}
42+
const { data: reputation } = await fetchGainedReputationList(data?.base.user_id);
43+
data.extra = {
44+
...data.extra,
45+
reputationList: reputation.list,
46+
};
4647

4748
return { ...others, data, success: true };
4849
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function IndividualProfileView({ data }) {
7676

7777
const tabContent = [
7878
<SocialInfoWidget key="social" data={data} />,
79-
<GainedReputationListView key="reputation" userId={userId} data={data?.reputationList} />,
79+
<GainedReputationListView key="reputation" data={data?.extra.reputationList} />,
8080
<SkillOverviewView key="skill" userId={userId} />,
8181
];
8282

@@ -89,7 +89,6 @@ function IndividualProfileView({ data }) {
8989
onChange={setTabActive}
9090
/>
9191
{tabContent[tabActive]}
92-
<div className="md:h-4" />
9392
<ActivityTabListWidget userId={userId} tabs={tabs} />
9493
</div>
9594
);

src/domain/profile/views/individual-profile/style.module.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
.Tab {
1818
@media (min-width: 768px) {
19-
&:nth-child(1) {
20-
display: none;
21-
}
19+
&:nth-child(1),
2220
&:nth-child(2) {
2321
display: none;
2422
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ function SocialInfoWidget({ className, data }) {
9696
</div>
9797
</>
9898
)}
99-
{data?.reputationList.length > 0 && (
99+
{data?.extra?.reputationList?.length > 0 && (
100100
<>
101101
<p className="mt-6 uppercase text-xs opacity-60 font-bold">Reputation</p>
102-
<GainedReputationListView key="reputation" data={data?.reputationList} />
102+
<GainedReputationListView data={data?.extra?.reputationList} compact />
103103
</>
104104
)}
105105
<Web3BioProfile data={data} />

src/domain/reputation/views/gained-reputation-list/GainedReputationItem.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ import { formatTime } from '@/utils/date';
1919

2020
function GainedReputationItem({
2121
data,
22+
compact = false,
2223
}: {
2324
data: {
2425
img: string;
2526
title: string;
2627
updated_at: number;
2728
};
29+
compact?: boolean;
2830
}) {
29-
return (
30-
<>
31-
<Avatar src={data.img} alt={data.title} size={55} className="max-md:hidden" />
32-
<div className="md:hidden w-full aspect-square text-center p-4 border border-gray-600 rounded">
33-
<div className="flex justify-center">
34-
<Avatar src={data.img} alt={data.title} size={100} />
35-
</div>
36-
<h3 className="text-sm truncate leading-5 flex-1 mt-2">{data.title}</h3>
37-
<p className="text-xs opacity-40">{formatTime(data.updated_at * 1000, 'MMM D, YYYY')}</p>
31+
return compact ? (
32+
<Avatar src={data.img} alt={data.title} size={55} />
33+
) : (
34+
<div className="w-full aspect-square md:w-[180px] text-center p-4 border border-gray-600 rounded">
35+
<div className="flex justify-center">
36+
<Avatar src={data.img} alt={data.title} size={100} />
3837
</div>
39-
</>
38+
<h3 className="text-sm truncate leading-5 flex-1 mt-2">{data.title}</h3>
39+
<p className="text-xs opacity-40">{formatTime(data.updated_at * 1000, 'MMM D, YYYY')}</p>
40+
</div>
4041
);
4142
}
4243

src/domain/reputation/views/gained-reputation-list/GainedReputationList.js

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 clsx from 'clsx';
18+
19+
import { NoData } from '@/components/NoData';
20+
21+
import GainedReputationItem from './GainedReputationItem';
22+
23+
function GainedReputationListView({
24+
data,
25+
compact = false,
26+
}: {
27+
data?: Array<{
28+
img: string;
29+
title: string;
30+
updated_at: number;
31+
id: string;
32+
}>;
33+
compact?: boolean;
34+
}) {
35+
return data && data.length > 0 ? (
36+
<div
37+
className={clsx({
38+
'grid grid-cols-5 gap-2 mt-4': compact,
39+
'grid grid-cols-2 gap-5 md:flex md:gap-6 mt-6': !compact,
40+
})}
41+
>
42+
{data.map(item => (
43+
<GainedReputationItem key={`reputation-${item.id}`} data={item} compact={compact} />
44+
))}
45+
</div>
46+
) : (
47+
<NoData className="mt-6" />
48+
);
49+
}
50+
51+
export default GainedReputationListView;

0 commit comments

Comments
 (0)