Skip to content

Commit 087f6ce

Browse files
committed
refactor(app): use new way for profile HTTP requests
1 parent 3603f07 commit 087f6ce

File tree

5 files changed

+23
-43
lines changed

5 files changed

+23
-43
lines changed

src/app/profile/page.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import Switch from '@/components/Switch';
2727
import { BASE_INPUT_STYLE } from '@/constants/config';
2828
import { classNames } from '@/utils';
2929

30+
import { updateUser } from '#/domain/profile/repository';
3031
import SocialSettingsFormView from '#/domain/profile/views/social-settings-form';
3132
import { ProfileTitle, ProfileLabel } from '#/domain/profile/widgets/blocks';
3233
import { upload } from '#/services/common';
33-
import { postUserInfo } from '#/services/user';
3434
import { useUser } from '#/state/application/hooks';
3535
import { useConfig } from '#/state/application/hooks';
3636

@@ -149,7 +149,7 @@ export default function Profile() {
149149
) {
150150
setFromError(true);
151151
} else {
152-
const res = await postUserInfo({
152+
const res = await updateUser({
153153
user_avatar: forms.avatar,
154154
user_bio: forms.bio,
155155
user_city: forms.city,
@@ -170,12 +170,10 @@ export default function Profile() {
170170
user_show_email: forms.emailVisible,
171171
user_show_github: forms.githubVisible,
172172
});
173-
if (res.code === 200) {
173+
if (res.success) {
174174
toast.success('Saved successfully');
175175
setShowSave(false);
176176
// doFetch()
177-
} else {
178-
toast.error(res.message);
179177
}
180178
}
181179
};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { toast } from 'react-toastify';
2323
import Image from '@/components/Image';
2424

2525
import { revalidatePathAction } from '#/app/actions';
26+
import { updateBanner } from '#/domain/profile/repository';
2627
import { upload } from '#/services/common';
27-
import { changeBanner } from '#/services/user';
2828
import { useUser } from '#/state/application/hooks';
2929

3030
export function Banner({data}) {
@@ -47,7 +47,7 @@ export function Banner({data}) {
4747
setLoading(true);
4848
upload({ file: formData })
4949
.then(async res => {
50-
await changeBanner(res.data.user_upload_path);
50+
await updateBanner(res.data.user_upload_path);
5151
setLoading(false);
5252
revalidatePathAction();
5353
})

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

-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import { useSession } from 'next-auth/react';
2020
import { usePathname, useRouter } from 'next/navigation';
2121
import { useState, useCallback, useEffect } from 'react';
22-
import { toast } from 'react-toastify';
2322

2423
import Avatar from '@/components/Avatar';
2524
import { Button } from '@/components/Button';
@@ -77,8 +76,6 @@ export default function Follow({ params }) {
7776
const _prevList = [...list];
7877
_prevList[index].mutual = type;
7978
setList(_prevList);
80-
} else {
81-
toast.error(res.message);
8279
}
8380
}
8481
};
@@ -94,8 +91,6 @@ export default function Follow({ params }) {
9491
const _prevList = [...list];
9592
_prevList[index].mutual = type;
9693
setList(_prevList);
97-
} else {
98-
toast.error(res.message);
9994
}
10095
}
10196
};

src/domain/profile/repository.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
import { unwrapBlockData, wrapBlockData } from '@/components/block-editor/helper';
1818
import httpClient from '@/utils/http';
1919

20+
async function fetchWeb3BioProfile(address) {
21+
return httpClient.get(`https://api.web3.bio/profile/${address}`, {
22+
headers: { 'X-API-KEY': process.env.NEXT_PUBLIC_WEB3BIO },
23+
});
24+
}
25+
2026
async function fetchUser(handle) {
2127
const res = await httpClient.get(`/user/info/handle/${handle}`);
2228

@@ -27,16 +33,17 @@ async function fetchUser(handle) {
2733
const { data, ...others } = res;
2834

2935
if (data?.social.user_wallet && data?.base.user_show_wallet) {
30-
data.web3Bio = await httpClient.get(`https://api.web3.bio/profile/${data?.social.user_wallet}`, {
31-
headers: {
32-
'X-API-KEY': process.env.NEXT_PUBLIC_WEB3BIO,
33-
},
34-
});
36+
const { data: web3BioProfile } = await fetchWeb3BioProfile(data?.social.user_wallet);
37+
data.web3Bio = web3BioProfile;
3538
}
3639

3740
return { ...others, data, success: true };
3841
}
3942

43+
async function updateUser(data) {
44+
return httpClient.post('/user/info', data);
45+
}
46+
4047
async function fetchUserActivityList(uid) {
4148
return httpClient.get(`/user/info/${uid}/creator/activity`);
4249
}
@@ -70,6 +77,10 @@ async function unfollowUser(uid) {
7077
return httpClient.post(`/user/follow/${uid}/del`);
7178
}
7279

80+
async function updateBanner(url) {
81+
return httpClient.post('/user/info/banner', { background_image: url });
82+
}
83+
7384
async function fetchBlockContent(uid) {
7485
return httpClient.get('/user/devplaza', { params: { uid } }).then(res => res.success ? ({
7586
...res,
@@ -82,7 +93,8 @@ async function updateBlockContent(data) {
8293
}
8394

8495
export {
85-
fetchUser, fetchUserActivityList,
96+
fetchUser, updateUser, fetchUserActivityList,
8697
fetchFollowerList, fetchFollowedList, followUser, unfollowUser,
98+
updateBanner,
8799
fetchBlockContent, updateBlockContent,
88100
};

src/services/user/index.js

-25
This file was deleted.

0 commit comments

Comments
 (0)