Skip to content

Commit

Permalink
Fix for uninitialised 'Snapshot' field if using old IndexedDB (Closes…
Browse files Browse the repository at this point in the history
… Issue EvitanRelta#105)
  • Loading branch information
swxk19 committed Jul 6, 2022
1 parent 29c6dcb commit e14880b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ export const Header = ({ title, setTitle, lastEditedOn, db }: Props) => {
const textColor = theme === 'dark' ? 'white' : '#181414'

const updateSnapshotsFromDb = async () => {
let allSnapshots = await db.snapshots.toArray()
setSnapshotArray(allSnapshots)
try {
let allSnapshots = await db.snapshots.toArray()
setSnapshotArray(allSnapshots)
} catch (e) {
//if 'snapshots' field is not initialised in db, it will be undefined, and 'toArray' causes a TypeError'
if (db.snapshots === undefined) {
await db.delete()
window.location.reload()
}
}
}

const saveSnapshot = () => {
Expand Down

0 comments on commit e14880b

Please sign in to comment.