Skip to content

Commit fc10282

Browse files
authored
Merge pull request #109 from fariqueparammel/fix-view-profile-loading
fix profile loading
2 parents 7d95e97 + 6b67e3f commit fc10282

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

www/components/github-modal/client.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ export default function GitHubModal({ onClose }: GitHubModalProps) {
4141
const [error, setError] = useState("");
4242
const [profile, setProfile] = useState<GitHubProfile | null>(null);
4343
const router = useRouter();
44+
const [loading, setLoading] = useState(false);
4445

46+
const redirectToProfilePage = async () => {
47+
if (!profile) return;
48+
setLoading(true);
49+
await router.push(`/${profile?.login}?ref=modal`);
50+
51+
// no need to setLoading(false) because navigation will replace this page
52+
};
4553
// Debounce the username input to prevent excessive API calls
4654
const debouncedUsername = useDebounce(username, 500);
4755

@@ -58,7 +66,7 @@ export default function GitHubModal({ onClose }: GitHubModalProps) {
5866

5967
try {
6068
const response = await fetch(
61-
`https://api.github.com/users/${usernameToValidate}`,
69+
`https://api.github.com/users/${usernameToValidate}`
6270
);
6371
if (!response.ok) {
6472
throw new Error("GitHub user not found");
@@ -78,7 +86,7 @@ export default function GitHubModal({ onClose }: GitHubModalProps) {
7886
setIsValidating(false);
7987
}
8088
},
81-
[],
89+
[]
8290
);
8391

8492
// Effect to trigger validation when debounced username changes
@@ -162,14 +170,19 @@ export default function GitHubModal({ onClose }: GitHubModalProps) {
162170

163171
<div className="flex gap-3">
164172
<button
165-
disabled={!profile}
166-
onClick={() => router.push(`/${profile?.login}?ref=modal`)}
173+
disabled={!profile || loading}
174+
onClick={redirectToProfilePage}
167175
className={cn(
168-
"flex-1 bg-[#CCFF00] text-black px-6 py-3 rounded-lg font-semibold hover:bg-[#b8e600] transition-colors",
169-
!profile && "opacity-50 cursor-not-allowed",
176+
"flex-1 bg-[#CCFF00] text-black px-6 py-3 rounded-lg font-semibold hover:bg-[#b8e600] transition-colors flex items-center justify-center gap-2",
177+
(!profile || loading) && "opacity-50 cursor-not-allowed"
170178
)}
171179
>
172-
View Profile
180+
{loading ? (
181+
// 🔹 Tailwind-only spinner (no external libs)
182+
<div className="h-5 w-5 border-2 border-black border-t-transparent rounded-full animate-spin" />
183+
) : (
184+
"View Profile"
185+
)}
173186
</button>
174187
<button
175188
onClick={onClose}

0 commit comments

Comments
 (0)