Skip to content

Commit d8ab62d

Browse files
authored
Merge branch 'tjtanjin:main' into main
2 parents 815cde5 + 5cabfac commit d8ab62d

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/hooks/useFetchThemes.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,26 @@ const useFetchThemes = (
2828
const fetchData = async () => {
2929
setLoading(true);
3030
try {
31-
let apiThemes;
31+
let apiThemes = null;
3232
if (url.startsWith("http")) {
3333
let finalUrl = `${url}?pageSize=${pageSize}&pageNum=${pageNum}`;
3434
if (searchQuery) {
3535
finalUrl += `&searchQuery=${encodeURIComponent(searchQuery)}`;
3636
}
3737

3838
const response = await galleryApiFetch(finalUrl);
39-
apiThemes = await response.json();
39+
const result = await response.json();
40+
apiThemes = result.data;
4041
} else {
4142
apiThemes = Placeholders.themes;
4243
}
4344

44-
const themes = await fetchThemesFromGitHub(apiThemes);
45-
setThemes(themes);
45+
if (apiThemes) {
46+
const themes = await fetchThemesFromGitHub(apiThemes);
47+
setThemes(themes);
48+
} else {
49+
setError(Error("Failed to fetch theme."));
50+
}
4651
} catch (err: unknown) {
4752
setError(err as Error);
4853
} finally {

src/hooks/useFetchUserData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const useLoginUser = (url: string, provider: string, key: string) => {
2626
try {
2727
const response = await galleryApiFetch(`${url}?provider=${provider}&key=${key}`);
2828
const result = await response.json();
29-
setData(result);
29+
setData(result.data);
3030
} catch (err: unknown) {
3131
setError(err as Error);
3232
} finally {

src/interfaces/UserData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export interface UserData {
88
name: string;
99
email: string;
1010
handle: string;
11-
avatar_url: string;
11+
avatarUrl: string;
1212
status: string;
1313
location: string;
14-
profile_url: string;
14+
profileUrl: string;
1515
provider: string;
16-
provider_user_id: string;
16+
providerUserId: string;
1717
}

src/pages/UserProfile.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const UserProfilePage: React.FC = () => {
2222
const refreshUserData = async () => {
2323
try {
2424
const response = await galleryApiFetch(Endpoints.fetchUserProfile);
25-
const result = await response.json();
26-
setUserData(result);
25+
if (response.ok) {
26+
const result = await response.json();
27+
setUserData(result.data);
28+
}
2729
} catch {
2830
// no update if error
2931
}
@@ -40,7 +42,7 @@ const UserProfilePage: React.FC = () => {
4042
<div className="flex items-center">
4143
<div className="rounded-full w-32 h-32 bg-gray-700 overflow-hidden mr-6">
4244
<img
43-
src={userData?.avatar_url || botAvatar}
45+
src={userData?.avatarUrl || botAvatar}
4446
alt={userData?.name || 'Bot Avatar'}
4547
className="w-full h-full object-cover"
4648
/>
@@ -56,7 +58,7 @@ const UserProfilePage: React.FC = () => {
5658
<div className="mt-6">
5759
<div className="flex items-center mb-4">
5860
<Github className="mr-2" />
59-
<Link to={userData?.profile_url as string} className="text-sm">
61+
<Link to={userData?.profileUrl as string} className="text-sm">
6062
{userData?.handle}
6163
</Link>
6264
</div>

0 commit comments

Comments
 (0)