mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
refactor: remove checks for JS features
Since I'm introducing Svelte framework and targeting modern browsers, I think it does not make sense to check for browser features. I can always choose to use polyfills for backwards compatibility. I will make sure the form is still also rendered via HTML and works for non-SPA use.
This commit is contained in:
@ -1,5 +1,3 @@
|
|||||||
import { useStorage } from './utils'
|
|
||||||
|
|
||||||
const migrateRecord = (record) => {
|
const migrateRecord = (record) => {
|
||||||
// NOTE: v3 records
|
// NOTE: v3 records
|
||||||
const id = record.id || record.order
|
const id = record.id || record.order
|
||||||
@ -13,10 +11,6 @@ const migrateRecord = (record) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getStorage = () => {
|
const getStorage = () => {
|
||||||
if (!useStorage()) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const storage = localStorage.getItem('fb-to-ical-events')
|
const storage = localStorage.getItem('fb-to-ical-events')
|
||||||
|
|
||||||
if (!storage) {
|
if (!storage) {
|
||||||
@ -28,10 +22,6 @@ const getStorage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getConfigStorage = () => {
|
const getConfigStorage = () => {
|
||||||
if (!useStorage()) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const storage = localStorage.getItem('fb-to-ical-config')
|
const storage = localStorage.getItem('fb-to-ical-config')
|
||||||
|
|
||||||
if (!storage) {
|
if (!storage) {
|
||||||
@ -62,10 +52,6 @@ const updateConfigStorage = (storageContents, key, value) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const saveRecord = ({ id, link, createdAt, startTime, title }) => {
|
const saveRecord = ({ id, link, createdAt, startTime, title }) => {
|
||||||
if (!useStorage()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const storage = getStorage()
|
const storage = getStorage()
|
||||||
const storageContents = getStorageContents(storage)
|
const storageContents = getStorageContents(storage)
|
||||||
|
|
||||||
@ -81,10 +67,6 @@ const saveRecord = ({ id, link, createdAt, startTime, title }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteRecord = (id) => {
|
const deleteRecord = (id) => {
|
||||||
if (!useStorage()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const storage = getStorage()
|
const storage = getStorage()
|
||||||
const storageContents = getStorageContents(storage)
|
const storageContents = getStorageContents(storage)
|
||||||
const index = storageContents.findIndex((record) => {
|
const index = storageContents.findIndex((record) => {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
const useStorage = () => Boolean(window.localStorage)
|
|
||||||
|
|
||||||
// NOTE: Generate random IDs: https://stackoverflow.com/a/2117523/3056783
|
// NOTE: Generate random IDs: https://stackoverflow.com/a/2117523/3056783
|
||||||
const uuidv4 = () => {
|
const uuidv4 = () => {
|
||||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
||||||
@ -26,5 +24,4 @@ const parseStartTimeFromiCalString = (text = '') => {
|
|||||||
export {
|
export {
|
||||||
uuidv4,
|
uuidv4,
|
||||||
parseStartTimeFromiCalString,
|
parseStartTimeFromiCalString,
|
||||||
useStorage,
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { uuidv4, parseStartTimeFromiCalString, useStorage } from './app/utils'
|
import { uuidv4, parseStartTimeFromiCalString } from './app/utils'
|
||||||
import {
|
import {
|
||||||
migrateRecord,
|
migrateRecord,
|
||||||
getStorage,
|
getStorage,
|
||||||
@ -16,11 +16,6 @@ import generateICS from '../../lib/services/ics-generator'
|
|||||||
import boot from '../frontend'
|
import boot from '../frontend'
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
if (!window.fetch || !window.Promise || !window.URLSearchParams || !window.crypto) {
|
|
||||||
console.warn('JS features not available.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', boot)
|
document.addEventListener('DOMContentLoaded', boot)
|
||||||
|
|
||||||
const showTable = () => {
|
const showTable = () => {
|
||||||
@ -30,10 +25,6 @@ import boot from '../frontend'
|
|||||||
const deleteTableRow = (id, row) => {
|
const deleteTableRow = (id, row) => {
|
||||||
deleteRecord(id)
|
deleteRecord(id)
|
||||||
|
|
||||||
if (!useStorage()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
row.remove()
|
row.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,10 +86,6 @@ import boot from '../frontend'
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hydrateList = () => {
|
const hydrateList = () => {
|
||||||
if (!useStorage()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const prevStorage = getStorage()
|
const prevStorage = getStorage()
|
||||||
const migratedStorageContents = getStorageContents(prevStorage).map((record) => {
|
const migratedStorageContents = getStorageContents(prevStorage).map((record) => {
|
||||||
return migrateRecord(record)
|
return migrateRecord(record)
|
||||||
@ -129,7 +116,7 @@ import boot from '../frontend'
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configureLogger = (logger) => {
|
const configureLogger = (logger) => {
|
||||||
if (!logger || !useStorage()) {
|
if (!logger) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user