Skip to content

Commit

Permalink
NotesStore: removeNoteKeys: update local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed May 30, 2023
1 parent da0b5e3 commit bb18fbe
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions stores/NotesStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { action, observable } from 'mobx';
import EncryptedStorage from 'react-native-encrypted-storage';

const NOTES_KEY = 'note-Keys';

export default class NotesStore {
@observable public noteKeys: string[] = [];

Expand All @@ -10,22 +12,28 @@ export default class NotesStore {
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');
}
await this.writeNoteKeysToLocalStorage();
}
};

@action
public removeNoteKeys = (key: string) => {
public removeNoteKeys = async (key: string) => {
const index = this.noteKeys.indexOf(key);
if (index !== -1) {
this.noteKeys.splice(index, 1);
// write updated keys to storage
await this.writeNoteKeysToLocalStorage();
}
};

writeNoteKeysToLocalStorage = async () => {
try {
await EncryptedStorage.setItem(
NOTES_KEY,
JSON.stringify(this.noteKeys)
);
} catch (error) {
console.error('Error saving to encrypted storage');
}
};
}

0 comments on commit bb18fbe

Please sign in to comment.