Skip to content

Fix: #2 : Text and form are now more visible in dark and light modes #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion client/src/chakra/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
const theme = extendTheme({
config,
styles: {
global: (props: any) => ({

Check failure on line 13 in client/src/chakra/theme.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

Unexpected any. Specify a different type

Check failure on line 13 in client/src/chakra/theme.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

Unexpected any. Specify a different type
body: {
backgroundColor: mode("gray.500", "")(props),
backgroundColor: mode("gray.300", "")(props),
},
}),
},
Expand Down
110 changes: 57 additions & 53 deletions client/src/components/TodoForm.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Button, Flex, Input, Spinner } from "@chakra-ui/react";
import { Button, Flex, Input, Spinner, useColorMode } from "@chakra-ui/react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { IoMdAdd } from "react-icons/io";
import { BASE_URL } from "../App";

const TodoForm = () => {
const [newTodo, setNewTodo] = useState("");
const [newTodo, setNewTodo] = useState("");
const { colorMode } = useColorMode(); // Chakra UI hook to get the current color mode

const queryClient = useQueryClient();
const queryClient = useQueryClient();

const { mutate: createTodo, isPending: isCreating } = useMutation({
mutationKey: ["createTodo"],
mutationFn: async (e: React.FormEvent) => {
e.preventDefault();
try {
const res = await fetch(BASE_URL + `/todos`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: newTodo }),
});
const data = await res.json();
const { mutate: createTodo, isPending: isCreating } = useMutation({
mutationKey: ["createTodo"],
mutationFn: async (e: React.FormEvent) => {
e.preventDefault();
try {
const res = await fetch(BASE_URL + `/todos`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: newTodo }),
});
const data = await res.json();

if (!res.ok) {
throw new Error(data.error || "Something went wrong");
}
if (!res.ok) {
throw new Error(data.error || "Something went wrong");
}

setNewTodo("");
return data;
} catch (error: any) {
throw new Error(error);
}
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["todos"] });
},
onError: (error: any) => {
alert(error.message);
},
});
setNewTodo("");
return data;
} catch (error: any) {
throw new Error(error);
}
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["todos"] });
},
onError: (error: any) => {
alert(error.message);
},
});

return (
<form onSubmit={createTodo}>
<Flex gap={2}>
<Input
type='text'
value={newTodo}
onChange={(e) => setNewTodo(e.target.value)}
ref={(input) => input && input.focus()}
/>
<Button
mx={2}
type='submit'
_active={{
transform: "scale(.97)",
}}
>
{isCreating ? <Spinner size={"xs"} /> : <IoMdAdd size={30} />}
</Button>
</Flex>
</form>
);
return (
<form onSubmit={createTodo}>
<Flex gap={2}>
<Input
type="text"
value={newTodo}
onChange={(e) => setNewTodo(e.target.value)}
ref={(input) => input && input.focus()}
style={{
border: `1px solid ${colorMode === "dark" ? "white" : "black"}`, // Change border color based on mode
}}
/>
<Button
mx={2}
type="submit"
_active={{
transform: "scale(.97)",
}}
>
{isCreating ? <Spinner size={"xs"} /> : <IoMdAdd size={30} />}
</Button>
</Flex>
</form>
);
};
export default TodoForm;

Expand Down
Loading