From a89777b91a430355d5b7a4eed45ead17b3f1a0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Syn=C3=A1=C4=8Dek?= Date: Tue, 15 Dec 2020 10:23:20 +0100 Subject: [PATCH] feature: add Svelte framework to app, refactor tracking panel into Svelte component --- lib/frontend/components/App.svelte | 5 + lib/frontend/components/AppContainer.svelte | 14 + lib/frontend/components/TrackingPanel.svelte | 46 +++ lib/frontend/index.js | 17 + lib/frontend/stores/configStore.js | 30 ++ lib/frontend/stores/index.js | 5 + lib/static/index.html | 2 + lib/static/index.js | 54 +-- lib/static/style.css | 19 -- package-lock.json | 334 +++++++++++++++++++ package.json | 13 +- webpack.config.js => webpack.common.js | 43 ++- webpack.dev.js | 11 + webpack.prod.js | 7 + 14 files changed, 511 insertions(+), 89 deletions(-) create mode 100644 lib/frontend/components/App.svelte create mode 100644 lib/frontend/components/AppContainer.svelte create mode 100644 lib/frontend/components/TrackingPanel.svelte create mode 100644 lib/frontend/index.js create mode 100644 lib/frontend/stores/configStore.js create mode 100644 lib/frontend/stores/index.js rename webpack.config.js => webpack.common.js (65%) create mode 100644 webpack.dev.js create mode 100644 webpack.prod.js diff --git a/lib/frontend/components/App.svelte b/lib/frontend/components/App.svelte new file mode 100644 index 0000000..208abda --- /dev/null +++ b/lib/frontend/components/App.svelte @@ -0,0 +1,5 @@ + + + diff --git a/lib/frontend/components/AppContainer.svelte b/lib/frontend/components/AppContainer.svelte new file mode 100644 index 0000000..4669fbc --- /dev/null +++ b/lib/frontend/components/AppContainer.svelte @@ -0,0 +1,14 @@ + + +{#if showTrackingPanel} + +{/if} + diff --git a/lib/frontend/components/TrackingPanel.svelte b/lib/frontend/components/TrackingPanel.svelte new file mode 100644 index 0000000..4f0e9fb --- /dev/null +++ b/lib/frontend/components/TrackingPanel.svelte @@ -0,0 +1,46 @@ + + + + +
+

+ Can we store anonymous logs? This data is only saved to our internal database and is used to debug the parsing of the web pages. We'll ask you only this time and won't bother you again. +

+ + + +
diff --git a/lib/frontend/index.js b/lib/frontend/index.js new file mode 100644 index 0000000..0be492e --- /dev/null +++ b/lib/frontend/index.js @@ -0,0 +1,17 @@ +import App from './components/App.svelte' + +import * as stores from './stores' + +const boot = () => { + new App({ + target: document.querySelector('#root'), + }) + + if (process.env.NODE_ENV === 'development') { + window._fb2ical = { + ...stores, + } + } +} + +export default boot diff --git a/lib/frontend/stores/configStore.js b/lib/frontend/stores/configStore.js new file mode 100644 index 0000000..adcaace --- /dev/null +++ b/lib/frontend/stores/configStore.js @@ -0,0 +1,30 @@ +import { writable } from 'svelte/store' + +const createConfigStore = () => { + const state = JSON.parse(localStorage.getItem('fb-to-ical-config') || '{}') + + const { subscribe, set, update } = writable(state) + + const setValue = (key, value) => { + update((prevState) => { + const nextState = { + ...prevState, + [key]: value, + } + + localStorage.setItem('fb-to-ical-config', JSON.stringify(nextState)) + + return nextState + }) + } + + return { + ...state, + subscribe, + set, + update, + setValue, + } +} + +export default createConfigStore() diff --git a/lib/frontend/stores/index.js b/lib/frontend/stores/index.js new file mode 100644 index 0000000..40e2cb9 --- /dev/null +++ b/lib/frontend/stores/index.js @@ -0,0 +1,5 @@ +import configStore from './configStore' + +export { + configStore, +} diff --git a/lib/static/index.html b/lib/static/index.html index 4f70a40..81be266 100644 --- a/lib/static/index.html +++ b/lib/static/index.html @@ -70,6 +70,8 @@ + +