Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Add code to prevent double submission #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/pages/Todo/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const Todo = ({ user, dispatch }) => {
const [stale, setStale] = useState({ stale: false });
const [{ todos, isLoading, isError }] = useGetTodos(stale);
const [currentTodo, setCurrentTodo] = useState("");
const [isFormDisabled, setIsFormDisabled] = useState(false);

const handleAddTodo = async (e) => {
e.preventDefault();
setIsFormDisabled(true);
console.log("Adding Todo");
const data = {
content: currentTodo,
Expand All @@ -30,6 +32,7 @@ const Todo = ({ user, dispatch }) => {
} catch (e) {
console.log("Error in adding todo");
}
setIsFormDisabled(false);
};


Expand All @@ -53,13 +56,15 @@ const Todo = ({ user, dispatch }) => {
</div>

<form onSubmit={handleAddTodo}>
<fieldset disabled={isFormDisabled}>
<input
type="text"
className="w-full my-8 px-6 py-4 text-xl rounded-lg border-0 focus:ring-2 focus:ring-gray-800 transition duration-200 ease-in-out transform hover:-translate-y-1 hover:scale-110 hover:shadow-xl shadow-md"
placeholder="🤔 What to do today?"
value={currentTodo}
onChange={(e) => setCurrentTodo(e.target.value)}
></input>
</fieldset>
</form>

{isLoading && <h1> Loading .... </h1>}
Expand Down