From c155d2a4ed7286f99865bc026f3db5ddba9139ed Mon Sep 17 00:00:00 2001 From: Krishna Date: Sat, 25 Jun 2022 18:04:30 +0530 Subject: [PATCH 1/6] v1.22.19 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 98b7437..8b54446 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "csoc-2022-task3-nextjs", - "version": "0.1.0", + "version": "1.22.19", "private": true, "scripts": { "dev": "next dev", From e63a5bf2407f64d024cdcb4bcffeb3395129a046 Mon Sep 17 00:00:00 2001 From: Krishna Date: Wed, 29 Jun 2022 22:12:18 +0530 Subject: [PATCH 2/6] first_commit --- components/AddTask.js | 34 +- components/LoginForm.js | 44 +- components/Nav.js | 8 +- components/RegisterForm.js | 10 +- components/TodoListItem.js | 93 +- context/auth.js | 5 +- middlewares/auth_required.js | 22 +- middlewares/no_auth_required.js | 21 +- package-lock.json | 9739 +++++++++++++++++++++++++++++++ package.json | 2 +- pages/index.js | 33 +- yarn.lock | 6954 +++++++++++----------- 12 files changed, 13424 insertions(+), 3541 deletions(-) create mode 100644 package-lock.json diff --git a/components/AddTask.js b/components/AddTask.js index 9652adb..9841bff 100644 --- a/components/AddTask.js +++ b/components/AddTask.js @@ -1,10 +1,32 @@ +import axios from "axios" +import { useState } from "react" +import { useAuth } from "../context/auth" + export default function AddTask() { + const [task, setTask] = useState("") + const { token } = useAuth() const addTask = () => { - /** - * @todo Complete this function. - * @todo 1. Send the request to add the task to the backend server. - * @todo 2. Add the task in the dom. - */ + axios({ + url : 'https://todo-app-csoc.herokuapp.com/todo/create/', + method : "post", + headers: { + Authorization: 'Token ' + token, + }, + data : { + title: task + } + } + + ) + .then(function ({ data, status }) { + setTask(""); + + + }) + .catch(function (err) { + }) + + } return (
@@ -12,6 +34,8 @@ export default function AddTask() { type='text' className='todo-add-task-input px-4 py-2 placeholder-blueGray-300 text-blueGray-600 bg-white rounded text-sm border border-blueGray-300 outline-none focus:outline-none focus:ring w-full' placeholder='Enter Task' + value={task} + onChange = {(e)=> {setTask(e.target.value)}} />
+ ) diff --git a/components/RegisterForm.js b/components/RegisterForm.js index a6ef2e3..41dd997 100644 --- a/components/RegisterForm.js +++ b/components/RegisterForm.js @@ -2,8 +2,10 @@ import React, { useState } from 'react' import axios from '../utils/axios' import { useAuth } from '../context/auth' import { useRouter } from 'next/router' +import {no_auth_required} from "../middlewares/no_auth_required"; export default function Register() { + no_auth_required(); const { setToken } = useAuth() const router = useRouter() @@ -52,9 +54,11 @@ export default function Register() { password: password, } - axios.post( - 'auth/register/', - dataForApiRequest, + axios({ + url : 'https://todo-app-csoc.herokuapp.com/auth/register/', + method : "post", + data : dataForApiRequest + } ) .then(function ({ data, status }) { setToken(data.token) diff --git a/components/TodoListItem.js b/components/TodoListItem.js index 7965f3b..e7daefe 100644 --- a/components/TodoListItem.js +++ b/components/TodoListItem.js @@ -1,56 +1,89 @@ /* eslint-disable @next/next/no-img-element */ +import axios from "axios"; +import { useState } from "react"; +import { useAuth } from "../context/auth"; -export default function TodoListItem() { +export default function TodoListItem(e) { + const [showedit, setShowEdit] = useState(false); + const [updateData, setUpdateData] = useState(); + const { token } = useAuth(); const editTask = (id) => { - /** - * @todo Complete this function. - * @todo 1. Update the dom accordingly - */ + setShowEdit(!showedit); + } const deleteTask = (id) => { - /** - * @todo Complete this function. - * @todo 1. Send the request to delete the task to the backend server. - * @todo 2. Remove the task from the dom. - */ + axios({ + url:"https://todo-app-csoc.herokuapp.com/todo/"+id+"/", + headers:{ + Authorization: 'Token ' + token + }, + method:"DELETE" + + }).then((res)=>{ + console.log("success") + }).catch((err)=>{ + console.log("error") + }) + } const updateTask = (id) => { - /** - * @todo Complete this function. - * @todo 1. Send the request to update the task to the backend server. - * @todo 2. Update the task in the dom. - */ + const dataForUpdate = { + title: updateData + } + if(token){ + axios({ + url:"https://todo-app-csoc.herokuapp.com/todo/"+id+"/", + headers:{ + Authorization: 'Token ' + token + }, + data:dataForUpdate, + method:"patch" + + }).then((res)=>{ + setShowEdit(!showedit) + setUpdateData('') + }).catch((err)=>{ + console.log("error") + }) + } + } return ( <>
  • { + setUpdateData(e.target.value); + }} + value={updateData} /> -
    +
    -
    - Sample Task 1 +
    + {e.title}
    - +