-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5961bdf
commit 7056b8b
Showing
7 changed files
with
1,363 additions
and
275 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import firebase from "firebase/app"; | ||
|
||
import 'firebase/firestore'; | ||
|
||
const firebaseConfig = { | ||
apiKey: "AIzaSyCvMDYMI5lbnx6GFiw-_gyRDzWriUdPZzE", | ||
authDomain: "todos-1a807.firebaseapp.com", | ||
databaseURL: "https://todos-1a807.firebaseio.com", | ||
projectId: "todos-1a807", | ||
storageBucket: "todos-1a807.appspot.com", | ||
messagingSenderId: "44399547596", | ||
appId: "1:44399547596:web:ce0e227e96b2ca94965e69", | ||
measurementId: "G-5LLGPX4M5Z" | ||
}; | ||
|
||
const firebaseApp = firebase.initializeApp(firebaseConfig); | ||
|
||
const firestore = firebaseApp.firestore(); | ||
// firestore.settings({ timestampsInSnapshots : true }); | ||
|
||
export default firestore; |
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
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,77 +1,152 @@ | ||
export default { | ||
retrieveTodos(context) { | ||
axios | ||
.get('/todos') | ||
.then(res => { | ||
context.commit('retrieveTodos', res.data.data) | ||
}).catch(err => { | ||
console.log(err) | ||
}) | ||
context.state.loading = true; | ||
dbCollection.orderBy('timestamp', 'asc').get() | ||
.then(querySnapshot => { | ||
let tempTodos = []; | ||
querySnapshot.forEach(document => { | ||
//console.log(document.data()); | ||
const data = { | ||
id : document.id, | ||
title : document.data().title, | ||
completed : document.data().completed, | ||
timestamp : document.data().timestamp, | ||
}; | ||
tempTodos.push(data); | ||
}); | ||
context.state.loading = false; | ||
// const asc = tempTodos.sort((a, b) => { | ||
// return a.timestamp.seconds - b.timestamp.seconds | ||
// }); | ||
context.commit('retrieveTodos', tempTodos); | ||
}); | ||
|
||
|
||
// axios | ||
// .get('/todos') | ||
// .then(res => { | ||
// context.commit('retrieveTodos', res.data.data) | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }) | ||
}, | ||
addTodo(context, todo) { | ||
axios | ||
.post('/todos', { | ||
context.state.loading = true; | ||
//with firebase | ||
dbCollection.add({ | ||
title : todo.title, | ||
completed : false, | ||
timestamp : new Date(), | ||
}).then(document => { | ||
context.commit('addTodo', { | ||
id : document.id, | ||
title : todo.title, | ||
completed : false, | ||
}) | ||
.then(res => { | ||
context.commit('addTodo', res.data.data) | ||
}).catch(err => { | ||
console.log(err) | ||
}); | ||
}); | ||
context.state.loading = false; | ||
}) | ||
|
||
// axios | ||
// .post('/todos', { | ||
// title : todo.title, | ||
// completed : false, | ||
// }) | ||
// .then(res => { | ||
// context.commit('addTodo', res.data.data) | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }); | ||
// context.commit('addTodo', todo) | ||
}, | ||
|
||
updateTodo(context, todo) { | ||
axios | ||
.patch('/todos/' + todo.id, { | ||
title : todo.title, | ||
completed : todo.completed, | ||
}) | ||
.then(res => { | ||
context.commit('updateTodo', res.data.data) | ||
}).catch(err => { | ||
console.log(err) | ||
dbCollection.doc(todo.id).set({ | ||
//id : todo.id, | ||
title : todo.title, | ||
completed : todo.completed, | ||
//timestamp : new Date(), | ||
}, { merge: true }).then(() => { | ||
context.commit('updateTodo', todo) | ||
}); | ||
|
||
// axios | ||
// .patch('/todos/' + todo.id, { | ||
// title : todo.title, | ||
// completed : todo.completed, | ||
// }) | ||
// .then(res => { | ||
// context.commit('updateTodo', res.data.data) | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }); | ||
// context.commit('updateTodo', todo) | ||
}, | ||
|
||
deleteTodo(context, id) { | ||
axios | ||
.delete('/todos/' + id) | ||
.then(res => { | ||
dbCollection.doc(id).delete() | ||
.then(() => { | ||
context.commit('deleteTodo', id) | ||
}).catch(err => { | ||
console.log(err) | ||
}); | ||
}) | ||
|
||
// axios | ||
// .delete('/todos/' + id) | ||
// .then(res => { | ||
// context.commit('deleteTodo', id) | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }); | ||
// context.commit('deleteTodo', id) | ||
}, | ||
|
||
checkAll(context, checked) { | ||
axios | ||
.patch('/check-all', { | ||
completed : checked | ||
dbCollection.get().then(querySnapshot => { | ||
querySnapshot.forEach(document => { | ||
document.ref.update({ | ||
completed : checked, | ||
}).then(() => { | ||
context.commit('checkAll', checked); | ||
}) | ||
}) | ||
.then(res => { | ||
context.commit('checkAll', checked) | ||
}).catch(err => { | ||
console.log(err) | ||
}); | ||
}) | ||
|
||
// axios | ||
// .patch('/check-all', { | ||
// completed : checked | ||
// }) | ||
// .then(res => { | ||
// context.commit('checkAll', checked) | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }); | ||
// context.commit('checkAll', checked) | ||
}, | ||
|
||
updateFilter(context, filter) { | ||
context.commit('updateFilter', filter); | ||
}, | ||
|
||
clearCompleted(context) { | ||
const completed = context.state.todos.filter((todo) => todo.completed).map((todo) => todo.id); | ||
axios | ||
.delete('/delete-all-checked', { | ||
data : { | ||
todos : completed, | ||
} | ||
dbCollection.where('completed', '==', true).get() | ||
.then(querySnapshot => { | ||
querySnapshot.forEach(document => { | ||
document.ref.delete().then(() => { | ||
context.commit('clearCompleted'); | ||
}) | ||
}) | ||
}) | ||
.then(res => { | ||
context.commit('clearCompleted'); | ||
}).catch(err => { | ||
console.log(err) | ||
}); | ||
|
||
// const completed = context.state.todos.filter((todo) => todo.completed).map((todo) => todo.id); | ||
// axios | ||
// .delete('/delete-all-checked', { | ||
// data : { | ||
// todos : completed, | ||
// } | ||
// }) | ||
// .then(res => { | ||
// context.commit('clearCompleted'); | ||
// }).catch(err => { | ||
// console.log(err) | ||
// }); | ||
// context.commit('clearCompleted'); | ||
} | ||
} |
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,4 +1,5 @@ | ||
export default { | ||
loading : true, | ||
filter : 'all', | ||
todos : [ | ||
// { | ||
|