diff --git a/src/components/PasswordManager/Edit.js b/src/components/PasswordManager/Edit.js
index 17fab97..2083b38 100644
--- a/src/components/PasswordManager/Edit.js
+++ b/src/components/PasswordManager/Edit.js
@@ -51,6 +51,14 @@ const Edit = inject("rootStore") ( observer(
* toggles window: open and close
* - encryptionkey: String
* encryption key of the password
+ * - updateDoc: function
+ * updates doc locally
+ * - deleteDoc: function
+ * deletes doc locally
+ * - editIndex: Int
+ * index of array with all docs. locale
+ * - toggleEditWindow: function
+ * Open or close edit window
*/
//Stored information
@@ -59,6 +67,7 @@ const Edit = inject("rootStore") ( observer(
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.dice = this.dice.bind(this);
+ this.delete = this.delete.bind(this);
this.state = {
url: '',
@@ -132,6 +141,39 @@ const Edit = inject("rootStore") ( observer(
}
+ delete() {
+ //Delete doc
+
+ alertify.confirm("Are you sure?", () => {
+ const id = this.props.data[this.props.editIndex].id;
+ const uid = this.stores.authStore.userData.uid;
+ const editIndex = this.props.editIndex;
+
+ db.collection("passwords/"+uid+"/passwords").doc(id).delete().then(() => {
+ //Delete doc locally
+ this.props.deleteDoc(editIndex);
+
+ this.props.toggleEditWindow();
+
+ alertify.success("Document removed!");
+ this.setState({
+ loading: false
+ });
+ }).catch((error) => {
+ console.error("Error updating the document: ", error);
+ alertify.error("Something went wrong! Please check your internet connection");
+ this.setState({
+ loading: false
+ });
+ });
+
+ this.setState({
+ loading: true
+ });
+ });
+ }
+
+
handleSubmit() {
const url = this.state.url;
const login = encrypt(this.state.login, this.props.encryptionkey);
@@ -151,7 +193,7 @@ const Edit = inject("rootStore") ( observer(
db.collection("passwords/"+uid+"/passwords").doc(id).set(data)
.then(() => {
console.log("Document updated");
- alertify.success("Document successfully updated!");
+ alertify.success("Document updated!");
//Update a doc locally with the new values
this.props.updateDoc(Object.assign(data, {id:id}), editIndex);
@@ -225,12 +267,15 @@ const Edit = inject("rootStore") ( observer(
/>
-
-
Login and password are going to be encrypted with the key you have set.
-
+
+
+
+
+
+
@@ -249,7 +294,7 @@ const Edit = inject("rootStore") ( observer(
width: '100vw',
height: '100vh',
position: 'fixed',
- zIndex: 1000,
+ zIndex: 1,
top: 0,
left: 0,
backgroundColor: 'rgba(255,255,255,0.9)',
diff --git a/src/components/PasswordManager/New.js b/src/components/PasswordManager/New.js
index 616fc45..b850ec1 100644
--- a/src/components/PasswordManager/New.js
+++ b/src/components/PasswordManager/New.js
@@ -51,6 +51,10 @@ const New = inject("rootStore") ( observer(
* toggles window: open and close
* - encryptionkey: String
* encryption key of the password
+ * - addDoc: function
+ * adds a new doc locally
+ * - toggleEditWindow: function
+ * Open or close edit window
*/
//Stored information
@@ -138,7 +142,7 @@ const New = inject("rootStore") ( observer(
db.collection("passwords/"+uid+"/passwords").add(data)
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
- alertify.success("Document successfully added!");
+ alertify.success("Document added!");
//Add a new doc locally so no new data transfer from firestore
//is needed
diff --git a/src/pages/home/Home.js b/src/pages/home/Home.js
index c88e90b..1bab6e3 100644
--- a/src/pages/home/Home.js
+++ b/src/pages/home/Home.js
@@ -2,7 +2,6 @@ import React, {Component} from 'react';
import jss from 'jss';
import preset from 'jss-preset-default';
import { Container } from 'semantic-ui-react';
-import history from '../../stores/functions/history';
/*
* Functions import
@@ -48,11 +47,6 @@ class Home extends Component {
//Styles
}
-
- componentDidMount() {
- history.push('/');
- }
-
componentWillUnmount() {
this.sheet.detach()
diff --git a/src/pages/passwordManager/PasswordManager.js b/src/pages/passwordManager/PasswordManager.js
index 78f1af4..c0c89a9 100644
--- a/src/pages/passwordManager/PasswordManager.js
+++ b/src/pages/passwordManager/PasswordManager.js
@@ -59,6 +59,7 @@ const PasswordManager = inject("rootStore") ( observer(
this.onChangeInput = this.onChangeInput.bind(this);
this.addDoc = this.addDoc.bind(this);
this.updateDoc = this.updateDoc.bind(this);
+ this.deleteDoc = this.deleteDoc.bind(this);
this.state = {
newWindowOpen: false,
@@ -111,6 +112,21 @@ const PasswordManager = inject("rootStore") ( observer(
}
+ deleteDoc(editIndex) {
+ //Delete doc locally
+
+ var newArr = [];
+ this.state.data.forEach(function(element, index) {
+ if(index !== editIndex) {
+ newArr.push(element);
+ }
+ });
+ this.setState({
+ data: newArr
+ });
+ }
+
+
onChangeInput(e) {
//Encryption key and search input
@@ -265,7 +281,7 @@ const PasswordManager = inject("rootStore") ( observer(
-
+