Commit 3fc39fc9 by Madhankumar

apicontext

parent 7bc8167f
...@@ -11,12 +11,6 @@ ...@@ -11,12 +11,6 @@
"title": "helloxxsxsxsxsxsxsxsxsxsxsxsxsxssssssssssssssssssssxssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadddadsdsdsadasasasadasaadadadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyy", "title": "helloxxsxsxsxsxsxsxsxsxsxsxsxsxssssssssssssssssssssxssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadddadsdsdsadasasasadasaadadadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyy",
"isCompleted": false, "isCompleted": false,
"id": 2 "id": 2
},
{
"sId": 1,
"title": "bbb",
"isCompleted": true,
"id": 6
} }
] ]
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ function App() { ...@@ -11,7 +11,7 @@ function App() {
useEffect(() => { useEffect(() => {
getTask(); getTask();
}, []); }, []);
console.log("okpp", task);
return ( return (
<div className="App"> <div className="App">
<Layout count={task?.filter((e) => !e.isCompleted).length}> <Layout count={task?.filter((e) => !e.isCompleted).length}>
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
} from "../lib/api"; } from "../lib/api";
export const TodoContext = createContext(); export const TodoContext = createContext();
export const useAppContext = () => useContext(TodoContext); export const useAppContext = () => useContext(TodoContext);
export function TodoProvider({ children, ...props }) { export function TodoProvider({ children }) {
const [task, setTask] = useState([]); const [task, setTask] = useState([]);
//POST METHOD //POST METHOD
...@@ -24,7 +24,6 @@ export function TodoProvider({ children, ...props }) { ...@@ -24,7 +24,6 @@ export function TodoProvider({ children, ...props }) {
//PATCH METHOD //PATCH METHOD
async function updateremainder(id) { async function updateremainder(id) {
try { try {
console.log("llll", id);
const response = await updateRemainder(id); const response = await updateRemainder(id);
setTask(response); setTask(response);
...@@ -78,9 +77,5 @@ export function TodoProvider({ children, ...props }) { ...@@ -78,9 +77,5 @@ export function TodoProvider({ children, ...props }) {
deleteTask, deleteTask,
updatetitle, updatetitle,
}; };
return ( return <TodoContext.Provider value={value}>{children}</TodoContext.Provider>;
<TodoContext.Provider value={value} {...props}>
{children}
</TodoContext.Provider>
);
} }
import React from "react";
import "./checkbox.css"; import "./checkbox.css";
function Checkbox({ isCompleted, onChange, ...props }) { const Checkbox = React.memo(({ isCompleted, onChange, ...props }) => {
console.log("checkbox");
const handleChange = () => { const handleChange = () => {
isCompleted = !isCompleted; isCompleted = !isCompleted;
onChange(isCompleted ? "checked" : "unchecked"); onChange(isCompleted ? "checked" : "unchecked");
...@@ -15,6 +17,6 @@ function Checkbox({ isCompleted, onChange, ...props }) { ...@@ -15,6 +17,6 @@ function Checkbox({ isCompleted, onChange, ...props }) {
/> />
</div> </div>
); );
} });
export default Checkbox; export default Checkbox;
import { FaTimesCircle } from "react-icons/fa"; import { FaTimesCircle } from "react-icons/fa";
import Checkbox from "../../base/checkbox"; import Checkbox from "../../base/checkbox";
import "./task.css"; import "./task.css";
import { useEffect, useRef, useLayoutEffect, useState } from "react"; import {
useEffect,
useRef,
useLayoutEffect,
useState,
useCallback,
} from "react";
function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) { function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
const [isedit, setIsEdit] = useState(false);
const [debouncetitle, setDebounceTitle] = useState(title); const [debouncetitle, setDebounceTitle] = useState(title);
const [ischeck, setIsCheck] = useState(isCompleted);
const textarea_ref = useRef(null); const textarea_ref = useRef(null);
const handleDelete = (e) => { const handleDelete = (e) => {
...@@ -17,13 +23,12 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) { ...@@ -17,13 +23,12 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
} }
return false; return false;
}; };
const handleChange = () => { const handleChange = useCallback(() => {
isCompleted = !isCompleted; setIsCheck(!ischeck);
onChange({ id, isCompleted: isCompleted ? true : false }); onChange({ id, isCompleted: ischeck ? true : false });
}; }, [ischeck]);
const handleContent = (e) => { const handleContent = (e) => {
setIsEdit(true);
setDebounceTitle(e.target.value); setDebounceTitle(e.target.value);
const textarea = document.querySelector("textarea"); const textarea = document.querySelector("textarea");
textarea.addEventListener("keyup", (e) => { textarea.addEventListener("keyup", (e) => {
...@@ -35,10 +40,10 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) { ...@@ -35,10 +40,10 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
//debounce //debounce
useEffect(() => { useEffect(() => {
const handler = setTimeout(() => { const handler = setTimeout(() => {
if (isedit) { if (textarea_ref.current.value != title) {
onEdit({ id, title: debouncetitle }); onEdit({ id, title: debouncetitle });
} }
}, 3000); }, 2000);
return () => { return () => {
clearTimeout(handler); clearTimeout(handler);
...@@ -54,8 +59,8 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) { ...@@ -54,8 +59,8 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
<div> <div>
<Checkbox <Checkbox
onChange={handleChange} onChange={handleChange}
checked={isCompleted} checked={ischeck}
disabled={isCompleted} // disabled={ischeck}
/> />
<textarea <textarea
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment