1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00
Files
Facebook-Events-iCal-Converter/lib/static/app/storage.js
2020-12-15 22:42:43 +01:00

75 lines
1.5 KiB
JavaScript

// TODO: this import should be removed once refactoring is finished
import { eventStore } from '../../frontend/stores'
const migrateRecord = (record) => {
// NOTE: v3 records
const id = record.id || record.order
const startTime = record.startTime || null
return {
...record,
id,
startTime,
}
}
const getStorage = () => {
const storage = localStorage.getItem('fb-to-ical-events')
if (!storage) {
localStorage.setItem('fb-to-ical-events', JSON.stringify([]))
return "[]"
}
return storage
}
const getConfigStorage = () => {
const storage = localStorage.getItem('fb-to-ical-config')
if (!storage) {
localStorage.setItem('fb-to-ical-config', JSON.stringify({}))
return "{}"
}
return storage
}
const getStorageContents = (storage) => {
return JSON.parse(storage)
}
const updateStorage = (storageContents) => {
const encodedStorage = JSON.stringify(storageContents)
localStorage.setItem('fb-to-ical-events', encodedStorage)
}
const updateConfigStorage = (storageContents, key, value) => {
const encodedStorage = JSON.stringify({
...storageContents,
[key]: value,
})
localStorage.setItem('fb-to-ical-config', encodedStorage)
}
const saveRecord = ({ id, link, createdAt, startTime, title }) => {
eventStore.setCalculation({ id, link, createdAt, startTime, title })
}
const deleteRecord = (id) => {
eventStore.clearCalculation(id)
}
export {
migrateRecord,
getStorage,
getConfigStorage,
getStorageContents,
updateStorage,
updateConfigStorage,
saveRecord,
deleteRecord,
}