slight refactoring
This commit is contained in:
@@ -59,9 +59,7 @@ async function getEncryptedEncryptionKey(): Promise<EncryptedEncryptionKey | voi
|
||||
return data?.key
|
||||
}
|
||||
|
||||
async function setEncryptedEncryptionKey(
|
||||
encryptedEncryptionKey: EncryptedEncryptionKey | null
|
||||
): Promise<void> {
|
||||
async function setEncryptedEncryptionKey(encryptedEncryptionKey: EncryptedEncryptionKey | null) {
|
||||
if (!user.value || !db.value) return
|
||||
const docRef = doc(db.value, 'encryptionKeys', user.value.uid)
|
||||
await setDoc(docRef, { key: encryptedEncryptionKey })
|
||||
|
||||
@@ -250,30 +250,22 @@ const parseBaseNotes = (notes: BaseNotes): BaseNotes => {
|
||||
)
|
||||
}
|
||||
|
||||
watch(
|
||||
[activeNotesSource, encryptionKey],
|
||||
async () => {
|
||||
if (!activeNotesSource.value) return
|
||||
baseNotes.value = {}
|
||||
let notes: BaseNotes = {}
|
||||
if (activeNotesSource.value === 'local') {
|
||||
try {
|
||||
notes = JSON.parse(localStorage.getItem('notes') || '{}')
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
} else if (activeNotesSource.value === 'firebase' && db.value) {
|
||||
if (encryptionKey.value === undefined || !user.value) return
|
||||
const firebaseNotes = (await getDoc(doc(db.value, 'pages', user.value.uid))).data() as {
|
||||
[noteId: string]: any
|
||||
}
|
||||
notes = encryptionKey.value ? decryptNotes(firebaseNotes, encryptionKey.value) : firebaseNotes
|
||||
console.log('get notes from firebase', notes)
|
||||
export const getNotes = async () => {
|
||||
baseNotes.value = {}
|
||||
let notes: BaseNotes = {}
|
||||
if (activeNotesSource.value === 'local') {
|
||||
try {
|
||||
notes = JSON.parse(localStorage.getItem('notes') || '{}')
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
baseNotes.value = parseBaseNotes(notes)
|
||||
if (!rootNote.value) insertDefaultNotes(defaultNotes)
|
||||
|
||||
setActiveNote(rootNote.value?.id)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
} else if (activeNotesSource.value === 'firebase') {
|
||||
if (encryptionKey.value === undefined || !user.value || !db.value) return
|
||||
const firebaseNotes = (await getDoc(doc(db.value, 'pages', user.value.uid))).data() as BaseNotes
|
||||
notes = encryptionKey.value ? decryptNotes(firebaseNotes, encryptionKey.value) : firebaseNotes
|
||||
console.log('get notes from firebase', notes)
|
||||
}
|
||||
baseNotes.value = parseBaseNotes(notes)
|
||||
if (!rootNote.value) insertDefaultNotes(defaultNotes)
|
||||
setActiveNote(rootNote.value?.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user