-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NotesStore: Storing and removing keys
- Loading branch information
1 parent
45294d4
commit bfc9f10
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
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,31 @@ | ||
import { action, observable } from 'mobx'; | ||
import EncryptedStorage from 'react-native-encrypted-storage'; | ||
|
||
export default class NotesStore { | ||
@observable public noteKeys: string[] = []; | ||
|
||
@action | ||
public storingNoteKeys = async (key: string, notes: string) => { | ||
if (!this.noteKeys.includes(key)) { | ||
if (notes) { | ||
this.noteKeys.push(key); | ||
} | ||
try { | ||
await EncryptedStorage.setItem( | ||
'note-Keys', | ||
JSON.stringify(this.noteKeys) | ||
); | ||
} catch (error) { | ||
console.error('Error saving to encrypted storage'); | ||
} | ||
} | ||
}; | ||
|
||
@action | ||
public removeNoteKeys = (key: string) => { | ||
const index = this.noteKeys.indexOf(key); | ||
if (index !== -1) { | ||
this.noteKeys.splice(index, 1); | ||
} | ||
}; | ||
} |
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