Skip to content

Completed all tasks #1

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
shamefully-hoist=true
auto-install-peers=true
49 changes: 39 additions & 10 deletions components/addTask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<input
type="text"
name="add task"
v-model.trim="newTodo"
class="
todo-add-task-input
px-4
Expand All @@ -15,10 +16,11 @@
text-sm
border border-blueGray-300
outline-none
focus:outline-none focus:ring
focus:outline-none
focus:ring
w-full
"
placeholder="Enter Task"
placeholder="Enter your task here"
/>
</label>
<button
Expand Down Expand Up @@ -46,15 +48,42 @@
import { defineComponent } from '@nuxtjs/composition-api'

export default defineComponent({
emits: ['newTask'],
data() {
return {
newTodo: '',
}
},
methods: {
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.
* @hint use emit to make a event that parent can observe
*/
async addTask() {
let newTodo = this.newTodo
if (newTodo == '') {
this.$toast.error('New Todo cannot be empty.')
return
}

this.$toast.info('Adding Todo...')
this.newTodo = ''

const headerForAuthorization = {
Authorization: 'Token ' + this.$store.getters.token,
}
const dataForAPIRequest = {
title: newTodo,
}

this.$axios({
headers: headerForAuthorization,
url: 'todo/create/',
method: 'post',
data: dataForAPIRequest,
})
.then(() => {
this.$toast.success('Todo added successfully!')
this.$emit('newTask')
})
.catch(() =>
this.$toast.error('Addition failed. Please try again later.')
)
},
},
})
Expand Down
1 change: 1 addition & 0 deletions components/navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default defineComponent({
logout() {
this.$store.commit('setToken', null)
this.$router.replace('/login')
this.$toast.info('Logged out successfully!')
},
},
})
Expand Down
64 changes: 64 additions & 0 deletions components/searchBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<aside class="mx-auto flex justify-between mt-2 px-4">
<label for="search task" class="flex-1">
<input
type="text"
name="search task"
v-model.trim="searchTodo"
@change="updateFilter"
class="
todo-search-task-input
px-4
py-2
placeholder-yellowGray-300
text-yellowGray-600
bg-white
rounded
text-sm
border border-yellowGray-300
outline-none
focus:outline-none focus:ring
w-full
pr-3
mr-3
"
placeholder="Filter tasks"
/>
</label>
<button
type="button"
class="
px-4
py-2
bg-transparent
hover:bg-blue-500
text-blue-700 text-sm
hover:text-white
border border-blue-500
hover:border-transparent
rounded
"
@click="searchTodo = ''"
>
Clear Filter
</button>
</aside>
</template>
>

<script>
import { defineComponent } from '@nuxtjs/composition-api'

export default defineComponent({
data() {
return {
searchTodo: '',
}
},
methods : {
async updateFilter(){
this.$emit('updateFilter', this.searchTodo)
}
}
})
</script>
59 changes: 59 additions & 0 deletions components/sortBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template>
<aside class="mx-auto flex justify-between mt-2 px-4">
<button
type="button"
class="
w-1/2
px-4
py-2
bg-transparent
hover:bg-yellow-500
text-yellow-600 text-sm
hover:text-white
border border-yellow-500
hover:border-transparent
rounded
"
@click="sortAsc"
>
Sort (A-Z)
</button>
<button
type="button"
class="
w-1/2
px-4
py-2
bg-transparent
hover:bg-yellow-500
text-yellow-600 text-sm
hover:text-white
border border-yellow-500
hover:border-transparent
rounded
"
@click="sortDesc"
>
Sort (Z-A)
</button>
</aside>
</template>
>

<script>
import { defineComponent } from '@nuxtjs/composition-api'

export default defineComponent({
data() {
return {}
},
methods: {
async sortAsc() {
this.$emit('sortAsc')
},
async sortDesc() {
this.$emit('sortDesc')
},
},
})
</script>
7 changes: 7 additions & 0 deletions middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export default defineNuxtMiddleware((context) => {
* @todo Redirect the user to main page if token is present in store
* @hints check what propeties context has
*/

let path = context.route.fullPath;
let token = context.store.getters.token;

if (token === null && path === '/') context.redirect('login/');
else if (token != null && path != '/') context.redirect('/');

})
Loading