Skip to content

Commit

Permalink
create new tasks without signing up
Browse files Browse the repository at this point in the history
  • Loading branch information
trisDeveloper committed Feb 25, 2024
1 parent b24ad2c commit 9e8e752
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
30 changes: 24 additions & 6 deletions frontend/src/components/task-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,31 @@ const saveTaskAndClose = async () => {
closeTaskCard()
return
}
if (store.selectedTask.id) {
await axios.patch(
`/api/users/${store.user.id}/tasks/${store.selectedTask.id}/`,
store.selectedTask
)
if (localStorage.getItem('userId')) {
if (store.selectedTask.id) {
await axios.patch(
`/api/users/${store.user.id}/tasks/${store.selectedTask.id}/`,
store.selectedTask
)
} else {
await axios.post(`/api/users/${store.user.id}/tasks/`, store.selectedTask)
}
} else {
await axios.post(`/api/users/${store.user.id}/tasks/`, store.selectedTask)
if (store.selectedTask.id) {
console.log(store.selectedTask.id)
const localTasks = JSON.parse(localStorage.getItem('tasks')) || []
const existingTaskIndex = localTasks.findIndex((task) => task.id === store.selectedTask.id)
if (existingTaskIndex !== -1) {
// Task found, update its properties
localTasks[existingTaskIndex] = store.selectedTask
}
localStorage.setItem('tasks', JSON.stringify(localTasks))
} else {
const localTasks = JSON.parse(localStorage.getItem('tasks')) || []
store.selectedTask.id = localTasks.length + 1
localTasks.push(store.selectedTask)
localStorage.setItem('tasks', JSON.stringify(localTasks))
}
}
props.fetchData()
closeTaskCard()
Expand Down
32 changes: 26 additions & 6 deletions frontend/src/views/CalendarView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ const fetchData = () => {
.catch((error) => {
console.error(error)
})
} else {
const localTasks = JSON.parse(localStorage.getItem('tasks')) || []
tasks.value = localTasks
}
}
Expand Down Expand Up @@ -164,13 +167,30 @@ const saveTaskAndClose = async () => {
closeTaskCard()
return
}
if (store.selectedTask.id) {
await axios.patch(
`/api/users/${store.user.id}/tasks/${store.selectedTask.id}/`,
store.selectedTask
)
if (localStorage.getItem('userId')) {
if (store.selectedTask.id) {
await axios.patch(
`/api/users/${store.user.id}/tasks/${store.selectedTask.id}/`,
store.selectedTask
)
} else {
await axios.post(`/api/users/${store.user.id}/tasks/`, store.selectedTask)
}
} else {
await axios.post(`/api/users/${store.user.id}/tasks/`, store.selectedTask)
if (store.selectedTask.id) {
const localTasks = JSON.parse(localStorage.getItem('tasks')) || []
const existingTaskIndex = localTasks.findIndex((task) => task.id === store.selectedTask.id)
if (existingTaskIndex !== -1) {
// Task found, update its properties
localTasks[existingTaskIndex] = store.selectedTask
}
localStorage.setItem('tasks', JSON.stringify(localTasks))
} else {
const localTasks = JSON.parse(localStorage.getItem('tasks')) || []
store.selectedTask.id = localTasks.length + 1
localTasks.push(store.selectedTask)
localStorage.setItem('tasks', JSON.stringify(localTasks))
}
}
fetchData()
closeTaskCard()
Expand Down

0 comments on commit 9e8e752

Please sign in to comment.