diff --git a/firestore.indexes.json b/firestore.indexes.json index 2a6adac..f2ffcee 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -1,14 +1,11 @@ { - // Example: - // - // "indexes": [ - // { - // "collectionId": "widgets", - // "fields": [ - // { "fieldPath": "foo", "mode": "ASCENDING" }, - // { "fieldPath": "bar", "mode": "DESCENDING" } - // ] - // } - // ] - "indexes": [] + "indexes": [ + { + "collectionId": "passwords", + "fields": [ + { "fieldPath": "uid", "mode": "ASCENDING" }, + { "fieldPath": "time", "mode": "DESCENDING" } + ] + } + ] } \ No newline at end of file diff --git a/src/loc.exe b/src/loc.exe new file mode 100644 index 0000000..bcbd116 Binary files /dev/null and b/src/loc.exe differ diff --git a/src/pages/passwordManager/New.js b/src/pages/passwordManager/New.js index 2dd6896..68dd419 100644 --- a/src/pages/passwordManager/New.js +++ b/src/pages/passwordManager/New.js @@ -120,17 +120,26 @@ const New = inject("rootStore") ( observer( const password = encrypt(this.state.password, this.props.encryptionkey); const uid = this.stores.authStore.userData.uid; - db.collection("passwords").add({ + const data = { uid: uid, url: url, login: login, password: password, time: new Date() - }) + } + + //Add a new doc locally so no new data transfer from firestore + //is needed + this.props.addDoc(data); + + db.collection("passwords/"+uid+"/passwords").add(data) .then((docRef) => { console.log("Document written with ID: ", docRef.id); alertify.success("Document successfully added!"); this.props.toggleNewWindow(); + this.setState({ + loading: false + }); }) .catch(function(error) { console.error("Error adding document: ", error); diff --git a/src/pages/passwordManager/PasswordManager.js b/src/pages/passwordManager/PasswordManager.js index 64623c7..b7700e5 100644 --- a/src/pages/passwordManager/PasswordManager.js +++ b/src/pages/passwordManager/PasswordManager.js @@ -54,6 +54,7 @@ const PasswordManager = inject("rootStore") ( observer( this.toggleNewWindow = this.toggleNewWindow.bind(this); this.onChangeInput = this.onChangeInput.bind(this); + this.addDoc = this.addDoc.bind(this); this.state = { newWindowOpen: false, @@ -82,6 +83,18 @@ const PasswordManager = inject("rootStore") ( observer( } + addDoc(data) { + //Add a new doc locally so no new data transfer from firestore + //is needed + var newArr = []; + newArr[0] = data; + newArr = newArr.concat(this.state.data); + this.setState({ + data: newArr + }); + } + + onChangeInput(e) { //Encryption key and search input @@ -111,11 +124,11 @@ const PasswordManager = inject("rootStore") ( observer( const uid = this.stores.authStore.userData.uid; - db.collection("passwords").where("uid", "==", uid).orderBy("time", "desc").get().then((querySnapshot) => { + db.collection("passwords/"+uid+"/passwords").where("uid", "==", uid).orderBy("time", "desc").get().then((querySnapshot) => { var arr = []; querySnapshot.forEach((doc) => { const data = doc.data(); - arr.push(data); + arr.push(data); }); this.setState({ data: arr, @@ -128,25 +141,62 @@ const PasswordManager = inject("rootStore") ( observer( displayData(dataList) { //Returns array with all table row components var components = []; + + function copyToClipboard(string) { + var textArea = document.createElement("textarea"); + textArea.style.position = 'fixed'; + textArea.style.top = 0; + textArea.style.left = 0; + textArea.style.width = '2em'; + textArea.style.height = '2em'; + textArea.style.padding = 0; + textArea.style.border = 'none'; + textArea.style.outline = 'none'; + textArea.style.boxShadow = 'none'; + textArea.style.background = 'transparent'; + textArea.value = string; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + var successful = document.execCommand('copy'); + if(successful) { + alertify.success("Copied to clipboard!"); + } else { + alertify.error("Unable to copy to clipboard"); + } + } catch (err) { + alertify.error("Unable to copy to clipboard"); + } + document.body.removeChild(textArea); + } dataList.forEach((element, index) => { - components.push( -