Skip to content
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

Made Changes Required For CSOC Vue Tasks #8

Open
wants to merge 1 commit 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
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = {
'vue/singleline-html-element-content-newline': 0,
'vue/html-self-closing': 0,
'vue/html-closing-bracket-newline': 0,
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
parserOptions: {
parser: '@typescript-eslint/parser',
Expand Down
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
shamefully-hoist=true
auto-install-peers=true
strict-peer-dependencies=false
39 changes: 38 additions & 1 deletion components/addTask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<aside class="mx-auto flex justify-between mt-24 px-4">
<label for="add task" class="flex-1">
<input
v-model.trim="newTask"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on using trim.

type="text"
name="add task"
class="
Expand Down Expand Up @@ -34,6 +35,7 @@
border border-green-500
hover:border-transparent
rounded
addBorder
"
@click="addTask"
>
Expand All @@ -46,7 +48,11 @@
import { defineComponent } from '@nuxtjs/composition-api'

export default defineComponent({
emits: ['newTask'],
// emits: ['newTask'],
data() {
return { newTask: '' }
},

methods: {
addTask() {
/**
Expand All @@ -55,7 +61,38 @@ export default defineComponent({
* @todo 2. Add the task in the dom.
* @hint use emit to make a event that parent can observe
*/

if (this.newTask === '') {
this.$toast.error('Please fill the Add task Field....')
return
}

const data = {
title: this.newTask,
}
const headerForApiRequets = {
headers: { Authorization: 'Token ' + this.$store.getters.token },
}
this.$toast.info('Please wait...')

this.$axios
.$post('todo/create/', data, headerForApiRequets)
.then(() => {
this.$toast.success('Task added successfully...')
this.newTask = ''
this.$emit('newTask')
// this.$router.go()
})
.catch(() => {
this.$toast.error('Task not Added Succesfully')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good error callback would be to ask the user to try again.

})
},
},
})
</script>

<style scoped>
.addBorder {
border-color: #7bf1a8;
}
</style>
8 changes: 8 additions & 0 deletions components/navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
block
whitespace-no-wrap
hover:bg-gray-400
logout
"
href="#"
@click="logout"
Expand All @@ -55,7 +56,14 @@ export default defineComponent({
logout() {
this.$store.commit('setToken', null)
this.$router.replace('/login')
this.$toast.success('Logged out successfully!')
},
},
})
</script>
<style scoped>
.logout {
background-color: white;
border-radius: 10%;
}
</style>
12 changes: 11 additions & 1 deletion middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ export default defineNuxtMiddleware((context) => {
/***
* @todo Redirect the user to login page if token is not present in store.
* @todo Redirect the user to main page if token is present in store
* @hints check what propeties context has
* @hints check what propeties context has ssd
*/

const path = context.route.fullPath
const token = context.store.getters.token

const newLocal = token != null && path !== '/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JS naming convention for naming a boolean variable.

if (token === null && path === '/') {
context.redirect('login/')
} else if (newLocal) {
context.redirect('/')
}
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"node": ">=12",
"pnpm": ">=3"
}
}
}
Loading