Skip to content

feat: add loading spinner during API calls#291

Open
bh462007 wants to merge 8 commits into
aryandas2911:mainfrom
bh462007:fix/loading-spinner-api-calls
Open

feat: add loading spinner during API calls#291
bh462007 wants to merge 8 commits into
aryandas2911:mainfrom
bh462007:fix/loading-spinner-api-calls

Conversation

@bh462007
Copy link
Copy Markdown

Closes #1

What Changed

  • Added loading state handling in useTasks.js
  • Created a reusable Spinner component
  • Displayed spinner on the Tasks page while fetching data
  • Added loading state management in AuthContext for login/signup flows
  • Added loading spinner to Login and Signup buttons during API requests
  • Disabled auth buttons during requests to prevent duplicate submissions

Files Changed

  • src/hooks/useTasks.js
  • src/components/Spinner.jsx
  • src/pages/Tasks.jsx
  • src/context/AuthContext.jsx
  • src/pages/Login.jsx
  • src/pages/Signup.jsx

Copilot AI review requested due to automatic review settings May 15, 2026 16:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors authentication and task flows to centralize async logic and surface loading state via a shared Spinner component.

Changes:

  • Adds login/signup to AuthContext with a shared loading state, and consumes them from Login/Signup pages.
  • Adds loading to useTasks hook and renders a Spinner in the Tasks list while fetching.
  • Introduces a new reusable Spinner component.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
frontend/src/components/Spinner.jsx New reusable spinner component.
frontend/src/context/AuthContext.jsx Adds login, signup, and shared loading state to context.
frontend/src/hooks/useTasks.js Tracks loading state across fetch/add/update/delete.
frontend/src/pages/Login.jsx Uses context login; shows spinner; disables button while loading.
frontend/src/pages/Signup.jsx Uses context signup; shows spinner; disables button while loading.
frontend/src/pages/Tasks.jsx Renders Spinner while tasks are loading.
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/hooks/useTasks.js Outdated
Comment on lines 23 to 26
setLoading(true);
await api.post("/tasks", taskData);
getTasks();
await getTasks();
};
Comment on lines 22 to 26
const addTask = async (taskData) => {
setLoading(true);
await api.post("/tasks", taskData);
getTasks();
await getTasks();
};
Comment thread frontend/src/pages/Tasks.jsx Outdated
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-2 space-y-4 animate-in delay-200">
{tasks.length ? (
{loading ? (
logout();
});
}
}, [token]);

return (
<AuthContext.Provider value={{ user, token, setUser, setToken, logout }}>
<AuthContext.Provider value={{ user, token, setUser, setToken, logout, login, signup, loading }}>
Comment on lines +20 to +30
const login = async (email, password) => {
setLoading(true);
try {
const res = await api.post("/auth/login", { email, password });
setToken(res.data.token);
setUser(res.data.user);
localStorage.setItem("token", res.data.token);
} finally {
setLoading(false);
}
};
Comment thread frontend/src/pages/Login.jsx Outdated
Comment on lines 16 to 21
await login(email, password);
navigate("/dashboard");
} catch (error) {
// handle error
console.log("Login failed");
console.log(error.response?.data || error.message);
}
const Spinner = () => {
return (
<div className="flex justify-center items-center py-8">
<div className="w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
Comment on lines +1 to +4
const Spinner = () => {
return (
<div className="flex justify-center items-center py-8">
<div className="w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
// restore session on app load
useEffect(() => {
if (token) {
// fetch logged-in user
api
.get("/auth/me")
.then((res) => {
setUser(res.data.user);
@aryandas2911
Copy link
Copy Markdown
Owner

@bh462007 pls fix the linting errors and dont use AI for your task or else you will be banned from the competition

@bh462007
Copy link
Copy Markdown
Author

Hi @aryandas2911, thanks for pointing it out. I will fix the linting errors and go through the changes properly before updating the PR.

@bh462007
Copy link
Copy Markdown
Author

Hi @aryandas2911, I’ve fixed the AuthContext linting issue by separating the context and provider into different files. For TaskFormModal.jsx, I noticed that issue was already there and I haven’t modified that file yet. Would you like me to fix it in this PR as well, or keep it for a separate PR?

@aryandas2911
Copy link
Copy Markdown
Owner

@bh462007 kindly check the merge conflicts and fix them

@bh462007
Copy link
Copy Markdown
Author

Hi @aryandas2911, I noticed that issue #1 has been closed while my PR #291 is still open. I’ve been working on the requested changes, including resolving merge conflicts and checking the linting issues. Could you please let me know whether the PR is still being considered or if I should close it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Loading Spinner During API Calls

3 participants