From 6c0d78fbafe79983dca1fe62f267d082fa22982e Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 29 Dec 2021 10:15:54 +0100 Subject: [PATCH] fix: update snjs & protection code --- package.json | 2 +- src/screens/Notes/Notes.tsx | 37 ++++++++++++----------- yarn.lock | 58 ++++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 719c0d85..b058eba7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@react-navigation/native": "^5.9.3", "@react-navigation/stack": "^5.14.3", "@standardnotes/sncrypto-common": "1.5.2", - "@standardnotes/snjs": "2.20.3", + "@standardnotes/snjs": "2.30.0", "js-base64": "^3.5.2", "moment": "^2.29.1", "react": "17.0.1", diff --git a/src/screens/Notes/Notes.tsx b/src/screens/Notes/Notes.tsx index 9bd0b03f..ae3a9490 100644 --- a/src/screens/Notes/Notes.tsx +++ b/src/screens/Notes/Notes.tsx @@ -81,16 +81,23 @@ export const Notes = React.memo( const [searchText, setSearchText] = useState(''); const [editor, setEditor] = useState(undefined); const [searchOptions, setSearchOptions] = useState([]); + + const areNotesCurrentlyProtected = useCallback(() => { + if (!application) { + return true; + } + + return ( + application.hasProtectionSources() && + !application.hasUnprotectedAccessSession() + ); + }, [application]); + const [ includeProtectedNoteText, setIncludeProtectedNoteText, - ] = useState( - () => - !( - application!.hasProtectionSources() && - application!.areProtectionsEnabled() - ) - ); + ] = useState(!areNotesCurrentlyProtected()); + const [includeArchivedNotes, setIncludeArchivedNotes] = useState( false ); @@ -105,10 +112,7 @@ export const Notes = React.memo( // Ref const haveDisplayOptions = useRef(false); - const protectionsEnabled = useRef( - application!.hasProtectionSources() && - application!.areProtectionsEnabled() - ); + const protectionsEnabled = useRef(areNotesCurrentlyProtected()); const reloadTitle = useCallback( (newNotes?: SNNote[], newFilter?: string) => { @@ -321,13 +325,11 @@ export const Notes = React.memo( }, [includeTrashedNotes, reloadNotesDisplayOptions]); const reloadSearchOptions = useCallback(() => { - const protections = - application?.hasProtectionSources() && - application?.areProtectionsEnabled(); + const currentlyProtected = areNotesCurrentlyProtected(); - if (protections !== protectionsEnabled.current) { - protectionsEnabled.current = !!protections; - setIncludeProtectedNoteText(!protections); + if (currentlyProtected !== protectionsEnabled.current) { + protectionsEnabled.current = !!currentlyProtected; + setIncludeProtectedNoteText(!currentlyProtected); } const selectedTag = application?.getAppState().selectedTag; @@ -361,6 +363,7 @@ export const Notes = React.memo( includeProtectedNoteText, includeArchivedNotes, includeTrashedNotes, + areNotesCurrentlyProtected, toggleIncludeProtected, toggleIncludeArchived, toggleIncludeTrashed, diff --git a/yarn.lock b/yarn.lock index fc41aa78..e3a98798 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1625,6 +1625,13 @@ dependencies: "@sinonjs/commons" "^1.7.0" +"@standardnotes/auth@3.8.1": + version "3.8.1" + resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.8.1.tgz#4197fb2f7e223c6bd13a870a3feac3c73294fb3c" + integrity sha512-Q2/81dgFGIGuYlQ4VnSjGRsDB0Qw0tQP/qsiuV+DQj+wdp5Wy5WX3Q4g+p2PNvoyEAYgbuduEHZfWuTLAaIdyw== + dependencies: + "@standardnotes/common" "^1.2.1" + "@standardnotes/auth@3.8.3", "@standardnotes/auth@^3.8.1": version "3.8.3" resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.8.3.tgz#6e627c1a1a9ebf91d97f52950d099bf7704382e3" @@ -1632,47 +1639,52 @@ dependencies: "@standardnotes/common" "^1.2.1" +"@standardnotes/common@1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@standardnotes/common/-/common-1.2.1.tgz#9db212db86ccbf08b347da02549b3dbe4bedbb02" + integrity sha512-HilBxS50CBlC6TJvy1mrnhGVDzOH63M/Jf+hyMxQ0Vt1nYzpd0iyxVEUrgMh7ZiyO1b9CLnCDED99Jy9rnZWVQ== + "@standardnotes/common@^1.2.1": version "1.3.0" resolved "https://registry.yarnpkg.com/@standardnotes/common/-/common-1.3.0.tgz#d3376ebe146cbe43577a0980fc09ea01fd18eb3a" integrity sha512-ePyxHHG+AswmDSemh4AEGtDL8hvlW1KOnUSweGBtLbgSuh2CrhexuoYp7Juf9Bzli7s+Zl+2EZI0EEBqoE8iyg== -"@standardnotes/domain-events@^2.5.1": - version "2.5.2" - resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.5.2.tgz#fa3279c156ab21546c4e5fbd0efea599403bbae8" - integrity sha512-krXYWmdyTbor8zicV1svx2efnn+4iYcO0YIv59EdGt6SPt5was6WdIJyYZOGgOsCcOuTkLk8Rj/zAfSUxDBDxw== +"@standardnotes/domain-events@2.5.1": + version "2.5.1" + resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.5.1.tgz#e6433e940ae616683d1c24f76133c70755504c44" + integrity sha512-p0VB4Al/ZcVqcj9ztU7TNqzc3jjjG6/U7x9lBW/QURHxpB+PnwJq3kFU5V5JA9QpCOYlXLT71CMERMf/O5QX6g== dependencies: "@standardnotes/auth" "^3.8.1" -"@standardnotes/features@^1.10.2": - version "1.10.2" - resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.10.2.tgz#a0783f66c00e21cb7692edc0cea95ec25a0253a5" - integrity sha512-Zh6EMjli4mL6jlXEhMyU3qYIKFJj5kuhbxtHXiErUGIDy+s1hHY+THFFO53Jdga2+8wgcATWlmSBY7dieVA8uA== +"@standardnotes/features@1.11.0": + version "1.11.0" + resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.11.0.tgz#66e960a20358c5f58b6be4e19226b34df6f4efbf" + integrity sha512-KMP60C1lf5C141s5VVOs7mISS1IUCioJfYsbsxtPycx9Q1mgbDB3xJv/GuCK/avsQOiGrB7QN06CQJ7fw4XV3Q== dependencies: "@standardnotes/auth" "3.8.3" "@standardnotes/common" "^1.2.1" -"@standardnotes/settings@^1.2.1": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@standardnotes/settings/-/settings-1.2.1.tgz#4c7656ea86d784a2f77c70acc89face5d28da024" - integrity sha512-EhCDtQKcVzY6cJ6qXCkAiA3sJ3Wj/q0L0ZVYq+tCXd0jaxmZ8fSk5YNqdwJfjmNXsqtuh7xq6eA2dcXd1fD9VQ== +"@standardnotes/settings@^1.8.0": + version "1.8.0" + resolved "https://registry.yarnpkg.com/@standardnotes/settings/-/settings-1.8.0.tgz#d7bd1f35c3b500d12ba73f5f385b1019baae3efc" + integrity sha512-gszghenDHFHoEeIGW7fHtIOJw35WpuaOdTD6UNMrH71xEduAr0JtzaLwrFXJ7XIp62zY7CSY1V6Npxo6HTGn+w== -"@standardnotes/sncrypto-common@1.5.2", "@standardnotes/sncrypto-common@^1.5.2": +"@standardnotes/sncrypto-common@1.5.2": version "1.5.2" resolved "https://registry.yarnpkg.com/@standardnotes/sncrypto-common/-/sncrypto-common-1.5.2.tgz#be9404689d94f953c68302609a4f76751eaa82cd" integrity sha512-+OQ6gajTcVSHruw33T52MHyBDKL1vRCfQBXQn4tt4+bCfBAe+PFLkEQMHp35bg5twCfg9+wUf2KhmNNSNyBBZw== -"@standardnotes/snjs@2.20.3": - version "2.20.3" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.20.3.tgz#11fe962dfb017be459e856b9fbc6311c5046a0b0" - integrity sha512-FHog3p3SuMvTXsEl76UenbjY8PS6VL/b6MjaC9whJR5ZwsvmLwE0G16dWZ+z+izm+CsRaHMWU8R2cy7RG7HjZg== +"@standardnotes/snjs@2.30.0": + version "2.30.0" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.30.0.tgz#12abda65e8069273347bbf6786d6a99203260023" + integrity sha512-0s7NYtO8edvY3/MNwx/Ic+fIDXiSnaVhdBWlaIOreVHwUl15LkHyN8mptR8QLtHOjOhvaguew+KCvmXXmkNjTA== dependencies: - "@standardnotes/auth" "^3.8.1" - "@standardnotes/common" "^1.2.1" - "@standardnotes/domain-events" "^2.5.1" - "@standardnotes/features" "^1.10.2" - "@standardnotes/settings" "^1.2.1" - "@standardnotes/sncrypto-common" "^1.5.2" + "@standardnotes/auth" "3.8.1" + "@standardnotes/common" "1.2.1" + "@standardnotes/domain-events" "2.5.1" + "@standardnotes/features" "1.11.0" + "@standardnotes/settings" "^1.8.0" + "@standardnotes/sncrypto-common" "1.5.2" "@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7": version "7.1.10"