-
Notifications
You must be signed in to change notification settings - Fork 48
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
completed all the tasks #9
Open
shubhangi013
wants to merge
6
commits into
COPS-IITBHU:main
Choose a base branch
from
shubhangi013:branch1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74ded3e
made relevant changes
shubhangi013 917ef8e
made relevant changes
shubhangi013 5231dbc
changed class to classname
shubhangi013 552f168
changed class to classname
shubhangi013 cc98357
removed comment lines
shubhangi013 e4f6f7c
improved the UI
shubhangi013 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,60 @@ | ||
export default function AddTask() { | ||
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. | ||
*/ | ||
} | ||
return ( | ||
<div className='flex items-center max-w-sm mt-24'> | ||
<input | ||
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' | ||
/> | ||
<button | ||
type='button' | ||
className='todo-add-task bg-transparent hover:bg-green-500 text-green-700 text-sm hover:text-white px-3 py-2 border border-green-500 hover:border-transparent rounded' | ||
onClick={addTask} | ||
> | ||
Add Task | ||
</button> | ||
</div> | ||
) | ||
} | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
export default function AddTask(props) { | ||
const API_BASE_URL = "https://todo-app-csoc.herokuapp.com/"; | ||
const [value, setValue] = useState(""); | ||
const addTask = () => { | ||
const todoText = value.trim(); | ||
|
||
if (!todoText) { | ||
alert("Enter something to add it") | ||
return; | ||
} | ||
|
||
axios({ | ||
headers: { | ||
Authorization: "Token " + localStorage.getItem("token") | ||
}, | ||
url: API_BASE_URL + "todo/create/", | ||
method: "post", | ||
data: { title: todoText } | ||
}) | ||
.then(function (response) { | ||
axios({ | ||
headers: { | ||
Authorization: "Token " + localStorage.getItem("token") | ||
}, | ||
url: API_BASE_URL + "todo/", | ||
method: "get" | ||
}).then(function ({ data, status }) { | ||
const newTask = data[data.length - 1]; | ||
props.addNewTask(newTask); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(error); | ||
}); | ||
setValue("") | ||
|
||
}; | ||
return ( | ||
<div> | ||
<div className> | ||
<input | ||
id="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={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
/> | ||
<button | ||
type="reset" | ||
className="btn" | ||
onClick={addTask}> | ||
Add Task | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,74 @@ | ||
export default function RegisterForm() { | ||
const login = () => { | ||
/*** | ||
* @todo Complete this function. | ||
* @todo 1. Write code for form validation. | ||
* @todo 2. Fetch the auth token from backend and login the user. | ||
*/ | ||
} | ||
import React, { useState, useEffect } from "react"; | ||
import axios from "axios"; | ||
import no_auth_required from "../middlewares/no_auth_required"; | ||
import Particles from 'react-particles-js'; | ||
|
||
return ( | ||
<div className='bg-grey-lighter min-h-screen flex flex-col'> | ||
<div className='container max-w-sm mx-auto flex-1 flex flex-col items-center justify-center px-2'> | ||
<div className='bg-white px-6 py-8 rounded shadow-md text-black w-full'> | ||
<h1 className='mb-8 text-3xl text-center'>Login</h1> | ||
<input | ||
type='text' | ||
className='block border border-grey-light w-full p-3 rounded mb-4' | ||
name='inputUsername' | ||
id='inputUsername' | ||
placeholder='Username' | ||
/> | ||
export default function LoginForm() { | ||
const [password, setPassword] = useState(""); | ||
const [username, setUsername] = useState(""); | ||
|
||
<input | ||
type='password' | ||
className='block border border-grey-light w-full p-3 rounded mb-4' | ||
name='inputPassword' | ||
id='inputPassword' | ||
placeholder='Password' | ||
/> | ||
const API_BASE_URL = "https://todo-app-csoc.herokuapp.com/"; | ||
|
||
<button | ||
type='submit' | ||
className='w-full text-center py-3 rounded bg-transparent text-green-500 hover:text-white hover:bg-green-500 border border-green-500 hover:border-transparent focus:outline-none my-1' | ||
onClick={login} | ||
> | ||
Login | ||
</button> | ||
useEffect(() => { | ||
no_auth_required(); | ||
}); | ||
|
||
const login = (e) => { | ||
e.preventDefault(); | ||
|
||
if (username == "" || password == "") { | ||
alert("Fill all the details ") | ||
} else { | ||
const dataForApiRequest = { | ||
username: username, | ||
password: password | ||
}; | ||
|
||
axios({ | ||
url: API_BASE_URL + "auth/login/", | ||
method: "post", | ||
data: dataForApiRequest | ||
}) | ||
.then(function ({ data, status }) { | ||
localStorage.setItem("token", data.token); | ||
window.location.href = "/"; | ||
}) | ||
.catch(function (err) { | ||
console.log(err) | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div > | ||
<div className="box"> | ||
<form> | ||
<span className="textHeading">login</span> | ||
<div className="input-container"> | ||
<input type="text" required="" | ||
name="inputUsername" | ||
id="inputUsername" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)}/> | ||
<label | ||
|
||
>Username</label> | ||
</div> | ||
<div className="input-container"> | ||
<input type="password" required="" | ||
name="inputPassword" | ||
id="inputPassword" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)}/> | ||
<label | ||
|
||
>Password</label> | ||
</div> | ||
<button type="button" className="btn" | ||
onClick={login}>LOGIN</button> | ||
</form> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,72 @@ | ||
/* eslint-disable jsx-a11y/alt-text */ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import Link from 'next/link' | ||
/** | ||
* | ||
* @todo Condtionally render login/register and Profile name in NavBar | ||
*/ | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
export default function Nav({ profileName = "Loading", avatarImage = "#", page = "" }) { | ||
const logout = () => { | ||
localStorage.removeItem("token"); | ||
window.location.href = "/login/"; | ||
}; | ||
|
||
export default function Nav({ profileName = 'Loading', avatarImage = '#' }) { | ||
const logout = () => { | ||
localStorage.removeItem('token') | ||
window.location.href = '/login/' | ||
} | ||
|
||
return ( | ||
<nav className='bg-blue-600'> | ||
<ul className='flex items-center justify-between p-5'> | ||
<ul className='flex items-center justify-between space-x-4'> | ||
<li> | ||
<h1 className='text-white font-bold text-xl'>Todo</h1> | ||
</li> | ||
<li className='text-white font-semibold'> | ||
<Link href='/'>Tasks</Link> | ||
</li> | ||
</ul> | ||
<ul className='flex'> | ||
<li className='text-white mr-2'> | ||
<Link href='/login'>Login</Link> | ||
</li> | ||
<li className='text-white'> | ||
<Link href='/register'>Register</Link> | ||
</li> | ||
</ul> | ||
<div className='inline-block relative w-28'> | ||
<div className='group inline-block relative'> | ||
<button className='bg-gray-300 text-gray-700 font-semibold py-2 px-4 rounded inline-flex items-center'> | ||
<img src={avatarImage} /> | ||
<span className='mr-1'>{profileName}</span> | ||
<svg | ||
className='fill-current h-4 w-4' | ||
xmlns='http://www.w3.org/2000/svg' | ||
viewBox='0 0 20 20' | ||
> | ||
<path d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z' /> | ||
</svg> | ||
</button> | ||
<ul className='absolute hidden text-gray-700 pt-1 group-hover:block'> | ||
<li className=''> | ||
<a | ||
className='rounded-b bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap' | ||
href='#' | ||
onClick={logout} | ||
> | ||
Logout | ||
</a> | ||
</li> | ||
return ( | ||
<nav > | ||
<ul className="flex items-center justify-between p-5"> | ||
<ul className="flex items-center justify-between space-x-4"> | ||
<li> | ||
<h1 className="text-white font-bold text-xl">Todo</h1> | ||
</li> | ||
<li className="text-white font-semibold"> | ||
Tasks | ||
</li> | ||
</ul> | ||
{page !== "index" ? ( | ||
<ul className="flex"> | ||
<li className="text-white mr-2"> | ||
<Link href="/login">Login</Link> | ||
</li> | ||
<li className="text-white"> | ||
<Link href="/register">Register</Link> | ||
</li> | ||
</ul> | ||
) : ( | ||
<div className="inline-block relative"> | ||
<div className="group inline-block relative"> | ||
<div className="avatar"> | ||
<button className="btn Avatar"> | ||
{avatarImage ? ( | ||
<Image | ||
className="img" | ||
src={avatarImage} | ||
height={33} | ||
width={33} | ||
alt="Profile image" | ||
/> | ||
) : ( | ||
"" | ||
)} | ||
<br/> | ||
<span className="mr-1 texHeading">{profileName.slice(0, 8)}</span> | ||
<svg | ||
className="fill-current h-4 w-4" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20"> | ||
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" /> | ||
</svg> | ||
</button> | ||
<ul className="absolute hidden text-gray-700 pt-1 group-hover:block"> | ||
<li className="logout"> | ||
<a | ||
className="logout" | ||
// className="rounded-b bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap" | ||
href="#" | ||
onClick={logout}> | ||
Logout | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</ul> | ||
</div> | ||
</div> | ||
</ul> | ||
</nav> | ||
) | ||
} | ||
</nav> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make use of Toasts here