MCPcopy Create free account
hub / github.com/codemistic/Web-Development / Tasks

Function Tasks

Django_React_Todo/frontend/src/pages/Tasks.jsx:23–94  ·  view source on GitHub ↗
({ postID, backButton, postTitle, fetcher })

Source from the content-addressed store, hash-verified

21 });
22
23const Tasks = ({ postID, backButton, postTitle, fetcher }) => {
24 const [titlee, setTitlee] = useState(postTitle);
25
26 // Request for GET information for Individual Task
27 const { data: taskDetail, isLoading, isError, } = useQuery(["todo"], () => {
28 return fetch(`http://127.0.0.1:8000/api/task-detail/${postID}`).then((t) =>
29 t.json()
30 );
31 });
32
33 // Post a request for deleting a task
34 const mutationD = useMutation(
35 (body) =>
36 deletion(`http://127.0.0.1:8000/api/task-delete/${postID}/`, body),
37 {
38 onSuccess(data) {
39 console.log("Got response from backend", data);
40 client.invalidateQueries("todos");
41 },
42 onError(error) {
43 console.log("Got error from backend", error);
44 },
45 }
46 );
47
48 // POST request for Updating Task
49 const mutationU = useMutation(
50 (body) => fetcher(`http://127.0.0.1:8000/api/task-update/${postID}/`, body),
51 {
52 onSuccess(data) {
53 console.log("Got response from backend", data);
54 client.invalidateQueries("todos");
55 },
56 onError(error) {
57 console.log("Got error from backend", error);
58 },
59 }
60 );
61
62 if (isLoading) return <h1>Loading...</h1>;
63
64 if (isError) return <h1>Error with request</h1>;
65
66 // Calling Delete request
67 function deleting_task() {
68 mutationD.mutate();
69 backButton();
70 }
71
72 // Calling Update
73 function callMutationU() {
74 mutationU.mutate({ title: titlee });
75 backButton();
76 }
77
78 return (
79 <div className="Task_Container">
80 <div className="Task_div">

Callers

nothing calls this directly

Calls 4

deletionFunction · 0.85
fetcherFunction · 0.85
callMutationUFunction · 0.85
deleting_taskFunction · 0.85

Tested by

no test coverage detected