Skip to content

Commit 23fc726

Browse files
committed
Fix: #2 : Text and form are now more visible in dark and light modes
1 parent 4b3202f commit 23fc726

File tree

2 files changed

+58
-54
lines changed

2 files changed

+58
-54
lines changed

client/src/chakra/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const theme = extendTheme({
1212
styles: {
1313
global: (props: any) => ({
1414
body: {
15-
backgroundColor: mode("gray.500", "")(props),
15+
backgroundColor: mode("gray.300", "")(props),
1616
},
1717
}),
1818
},

client/src/components/TodoForm.tsx

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,72 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { Button, Flex, Input, Spinner } from "@chakra-ui/react";
2+
import { Button, Flex, Input, Spinner, useColorMode } from "@chakra-ui/react";
33
import { useMutation, useQueryClient } from "@tanstack/react-query";
44
import { useState } from "react";
55
import { IoMdAdd } from "react-icons/io";
66
import { BASE_URL } from "../App";
77

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

11-
const queryClient = useQueryClient();
12+
const queryClient = useQueryClient();
1213

13-
const { mutate: createTodo, isPending: isCreating } = useMutation({
14-
mutationKey: ["createTodo"],
15-
mutationFn: async (e: React.FormEvent) => {
16-
e.preventDefault();
17-
try {
18-
const res = await fetch(BASE_URL + `/todos`, {
19-
method: "POST",
20-
headers: {
21-
"Content-Type": "application/json",
22-
},
23-
body: JSON.stringify({ body: newTodo }),
24-
});
25-
const data = await res.json();
14+
const { mutate: createTodo, isPending: isCreating } = useMutation({
15+
mutationKey: ["createTodo"],
16+
mutationFn: async (e: React.FormEvent) => {
17+
e.preventDefault();
18+
try {
19+
const res = await fetch(BASE_URL + `/todos`, {
20+
method: "POST",
21+
headers: {
22+
"Content-Type": "application/json",
23+
},
24+
body: JSON.stringify({ body: newTodo }),
25+
});
26+
const data = await res.json();
2627

27-
if (!res.ok) {
28-
throw new Error(data.error || "Something went wrong");
29-
}
28+
if (!res.ok) {
29+
throw new Error(data.error || "Something went wrong");
30+
}
3031

31-
setNewTodo("");
32-
return data;
33-
} catch (error: any) {
34-
throw new Error(error);
35-
}
36-
},
37-
onSuccess: () => {
38-
queryClient.invalidateQueries({ queryKey: ["todos"] });
39-
},
40-
onError: (error: any) => {
41-
alert(error.message);
42-
},
43-
});
32+
setNewTodo("");
33+
return data;
34+
} catch (error: any) {
35+
throw new Error(error);
36+
}
37+
},
38+
onSuccess: () => {
39+
queryClient.invalidateQueries({ queryKey: ["todos"] });
40+
},
41+
onError: (error: any) => {
42+
alert(error.message);
43+
},
44+
});
4445

45-
return (
46-
<form onSubmit={createTodo}>
47-
<Flex gap={2}>
48-
<Input
49-
type='text'
50-
value={newTodo}
51-
onChange={(e) => setNewTodo(e.target.value)}
52-
ref={(input) => input && input.focus()}
53-
/>
54-
<Button
55-
mx={2}
56-
type='submit'
57-
_active={{
58-
transform: "scale(.97)",
59-
}}
60-
>
61-
{isCreating ? <Spinner size={"xs"} /> : <IoMdAdd size={30} />}
62-
</Button>
63-
</Flex>
64-
</form>
65-
);
46+
return (
47+
<form onSubmit={createTodo}>
48+
<Flex gap={2}>
49+
<Input
50+
type="text"
51+
value={newTodo}
52+
onChange={(e) => setNewTodo(e.target.value)}
53+
ref={(input) => input && input.focus()}
54+
style={{
55+
border: `1px solid ${colorMode === "dark" ? "white" : "black"}`, // Change border color based on mode
56+
}}
57+
/>
58+
<Button
59+
mx={2}
60+
type="submit"
61+
_active={{
62+
transform: "scale(.97)",
63+
}}
64+
>
65+
{isCreating ? <Spinner size={"xs"} /> : <IoMdAdd size={30} />}
66+
</Button>
67+
</Flex>
68+
</form>
69+
);
6670
};
6771
export default TodoForm;
6872

0 commit comments

Comments
 (0)