diff --git a/crabfit-frontend/.gitignore b/crabfit-frontend/.gitignore index 6565811..8b79af8 100644 --- a/crabfit-frontend/.gitignore +++ b/crabfit-frontend/.gitignore @@ -1,6 +1,7 @@ node_modules dist build +dev-dist npm-debug.log* yarn-debug.log* diff --git a/crabfit-frontend/config-overrides.js b/crabfit-frontend/config-overrides.js deleted file mode 100644 index 9e57d32..0000000 --- a/crabfit-frontend/config-overrides.js +++ /dev/null @@ -1,48 +0,0 @@ -const WorkboxWebpackPlugin = require('workbox-webpack-plugin'); -const path = require('path'); -// const fs = require('fs'); -// const glob = require('glob'); -// const crypto = require('crypto'); - -// const fileHash = path => { -// let file_buffer = fs.readFileSync(path); -// let sum = crypto.createHash('md5'); -// sum.update(file_buffer); -// return sum.digest('hex'); -// }; - -module.exports = function override(config, env) { - config.output.filename = env === 'production' - ? 'static/js/[name].[contenthash].js' - : env === 'development' && 'static/js/bundle.js'; - - config.output.chunkFilename = env === 'production' - ? 'static/js/[name].[contenthash].chunk.js' - : env === 'development' && 'static/js/[name].chunk.js'; - - if (env === 'production') { - config.plugins.push(new WorkboxWebpackPlugin.InjectManifest({ - swSrc: path.resolve(__dirname, 'src/sw.js'), - exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/], - maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, - additionalManifestEntries: [ - // ...glob.sync('./public/i18n/*/*.json').map(file => { - // return ({ - // url: file.replace('./public', ''), - // revision: fileHash(file), - // }); - // }), - { - url: '/index.css', - revision: null, - }, - { - url: '/manifest.json', - revision: null, - }, - ], - })); - } - - return config; -} diff --git a/crabfit-frontend/package.json b/crabfit-frontend/package.json index a5b208d..ce47a8c 100644 --- a/crabfit-frontend/package.json +++ b/crabfit-frontend/package.json @@ -43,6 +43,7 @@ "eslint": "^8.22.0", "eslint-plugin-react": "^7.30.1", "vite": "^3.0.7", + "vite-plugin-pwa": "^0.12.3", "workbox-webpack-plugin": "^6.5.4" }, "browserslist": { diff --git a/crabfit-frontend/public/i18n/de/common.json b/crabfit-frontend/public/i18n/de/common.json index 7b4a05b..f767498 100644 --- a/crabfit-frontend/public/i18n/de/common.json +++ b/crabfit-frontend/public/i18n/de/common.json @@ -55,14 +55,6 @@ "label": "Sprache" } }, - "update": { - "heading": "Crab Fit wurde aktualisiert", - "body": "Eine neue Version von Crab Fit ist verfügbar, die Updates, Fixes und neue Funktionen enthält.", - "buttons": { - "close": "Entlassen", - "reload": "Neu laden" - } - }, "video": { "title": "Crab Fit Promo Video", "button": "Unser Video" diff --git a/crabfit-frontend/public/i18n/en-GB/common.json b/crabfit-frontend/public/i18n/en-GB/common.json index 4012234..27bfa42 100644 --- a/crabfit-frontend/public/i18n/en-GB/common.json +++ b/crabfit-frontend/public/i18n/en-GB/common.json @@ -54,13 +54,5 @@ "language": { "label": "Language" } - }, - "update": { - "heading": "Crab Fit has been updated", - "body": "A new version of Crab Fit is available, which includes updates, fixes, and new features.", - "buttons": { - "close": "Close", - "reload": "Reload" - } } } diff --git a/crabfit-frontend/public/i18n/en/common.json b/crabfit-frontend/public/i18n/en/common.json index 367fd74..3081de2 100644 --- a/crabfit-frontend/public/i18n/en/common.json +++ b/crabfit-frontend/public/i18n/en/common.json @@ -55,14 +55,6 @@ "label": "Language" } }, - "update": { - "heading": "Crab Fit has been updated", - "body": "A new version of Crab Fit is available, which includes updates, fixes, and new features.", - "buttons": { - "close": "Close", - "reload": "Reload" - } - }, "video": { "title": "Crab Fit Promotional Video", "button": "Watch the video" diff --git a/crabfit-frontend/public/i18n/es/common.json b/crabfit-frontend/public/i18n/es/common.json index a78be99..87e4a1d 100644 --- a/crabfit-frontend/public/i18n/es/common.json +++ b/crabfit-frontend/public/i18n/es/common.json @@ -54,13 +54,5 @@ "language": { "label": "Idioma" } - }, - "update": { - "heading": "Se ha actualizado Crab Fit", - "body": "Está disponible una nueva versión de Crab Fit, que incluye actualizaciones, correcciones y nuevas funciones.", - "buttons": { - "close": "Cerca", - "reload": "Recargar" - } } } diff --git a/crabfit-frontend/public/i18n/fr/common.json b/crabfit-frontend/public/i18n/fr/common.json index 83f918d..5beb4aa 100644 --- a/crabfit-frontend/public/i18n/fr/common.json +++ b/crabfit-frontend/public/i18n/fr/common.json @@ -55,14 +55,6 @@ "label": "Langue" } }, - "update": { - "heading": "Crab Fit a été mis à jour", - "body": "Une nouvelle version de Crab Fit est disponible, qui comprend des mises à jour, des correctifs et de nouvelles fonctionnalités.", - "buttons": { - "close": "Fermer", - "reload": "Recharger" - } - }, "video": { "title": "Vidéo promotionnelle de Crab Fit", "button": "Regarder la vidéo" diff --git a/crabfit-frontend/public/i18n/hi/common.json b/crabfit-frontend/public/i18n/hi/common.json index ff565fb..5119a2c 100644 --- a/crabfit-frontend/public/i18n/hi/common.json +++ b/crabfit-frontend/public/i18n/hi/common.json @@ -54,13 +54,5 @@ "language": { "label": "भाषा" } - }, - "update": { - "heading": "एक अपडेट है", - "body": "एक नया संस्करण उपलब्ध है, जिसमें अपडेट, सुधार और नई सुविधाएं शामिल हैं।", - "buttons": { - "close": "खारिज", - "reload": "पुनः लोड करें" - } } } diff --git a/crabfit-frontend/public/i18n/id/common.json b/crabfit-frontend/public/i18n/id/common.json index 8623dc9..a5d31ce 100644 --- a/crabfit-frontend/public/i18n/id/common.json +++ b/crabfit-frontend/public/i18n/id/common.json @@ -54,13 +54,5 @@ "language": { "label": "Bahasa" } - }, - "update": { - "heading": "Crab Fit telah diperbarui", - "body": "Versi baru Crab Fit tersedia, yang mencakup pembaruan, perbaikan, dan fitur baru.", - "buttons": { - "close": "Menutup", - "reload": "Muat ulang" - } } } diff --git a/crabfit-frontend/public/i18n/ja/common.json b/crabfit-frontend/public/i18n/ja/common.json index ec5c28f..74b14b9 100644 --- a/crabfit-frontend/public/i18n/ja/common.json +++ b/crabfit-frontend/public/i18n/ja/common.json @@ -54,13 +54,5 @@ "language": { "label": "言語" } - }, - "update": { - "heading": "Crab Fit が更新されました", - "body": "新しいバージョンの Crab Fit を利用できます。不具合の修正や新機能の追加などが行われています。", - "buttons": { - "close": "閉じる", - "reload": "再読込" - } } } diff --git a/crabfit-frontend/public/i18n/ko/common.json b/crabfit-frontend/public/i18n/ko/common.json index cedfca7..8c97f1d 100644 --- a/crabfit-frontend/public/i18n/ko/common.json +++ b/crabfit-frontend/public/i18n/ko/common.json @@ -54,13 +54,5 @@ "language": { "label": "언어" } - }, - "update": { - "heading": "새 업데이트가 있습니다", - "body": "업데이트, 수정 및 새 기능이 포함된 새 버전을 사용할 수 있습니다.", - "buttons": { - "close": "닫다", - "reload": "다시 로드합니다" - } } } diff --git a/crabfit-frontend/public/i18n/pl/common.json b/crabfit-frontend/public/i18n/pl/common.json index 098960c..a961748 100644 --- a/crabfit-frontend/public/i18n/pl/common.json +++ b/crabfit-frontend/public/i18n/pl/common.json @@ -55,14 +55,6 @@ "label": "Język" } }, - "update": { - "heading": "Crab Fit został zaktualizowany", - "body": "Nowa wersja Crab Fita jest dostępna, która zawiera aktualizacje, poprawki oraz nowe funkcje.", - "buttons": { - "close": "Zamknij", - "reload": "Przeładuj" - } - }, "video": { "title": "Promocyjne wideo Crab Fita", "button": "Obejrzyj wideo" diff --git a/crabfit-frontend/public/i18n/pt-BR/common.json b/crabfit-frontend/public/i18n/pt-BR/common.json index 2d7671d..7be4fb3 100644 --- a/crabfit-frontend/public/i18n/pt-BR/common.json +++ b/crabfit-frontend/public/i18n/pt-BR/common.json @@ -55,14 +55,6 @@ "label": "idioma" } }, - "update": { - "heading": "Crab Fit foi atualizado", - "body": "Uma nova versão está disponível com atualizações, correções e funções novas.", - "buttons": { - "close": "Fechar", - "reload": "Recarregar" - } - }, "video": { "title": "Vídeo promocional Crab Fit", "button": "veja o vídeo" diff --git a/crabfit-frontend/public/i18n/ru/common.json b/crabfit-frontend/public/i18n/ru/common.json index 3b1f04c..6d6a627 100644 --- a/crabfit-frontend/public/i18n/ru/common.json +++ b/crabfit-frontend/public/i18n/ru/common.json @@ -54,13 +54,5 @@ "language": { "label": "Язык" } - }, - "update": { - "heading": "Crab Fit обновлен", - "body": "Доступна новая версия Crab Fit, которая включает обновления, исправления и новые функции.", - "buttons": { - "close": "Закрыть", - "reload": "Перезагрузить" - } } } diff --git a/crabfit-frontend/src/sw.js b/crabfit-frontend/public/sw.js similarity index 96% rename from crabfit-frontend/src/sw.js rename to crabfit-frontend/public/sw.js index 198d965..aab6b66 100644 --- a/crabfit-frontend/src/sw.js +++ b/crabfit-frontend/public/sw.js @@ -31,7 +31,7 @@ registerRoute( return true }, - createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html') + createHandlerBoundToURL('index.html') ) registerRoute( diff --git a/crabfit-frontend/src/App.jsx b/crabfit-frontend/src/App.jsx index 8a1a401..7491131 100644 --- a/crabfit-frontend/src/App.jsx +++ b/crabfit-frontend/src/App.jsx @@ -1,22 +1,18 @@ import { useState, useEffect, useCallback, Suspense } from 'react' import { Route, Routes } from 'react-router-dom' -import { Workbox } from 'workbox-window' import * as Pages from '/src/pages' -import { Settings, Loading, Egg, UpdateDialog, TranslateDialog } from '/src/components' +import { Settings, Loading, Egg, TranslateDialog } from '/src/components' import { useSettingsStore, useTranslateStore } from '/src/stores' const EGG_PATTERN = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'] -const wb = new Workbox('sw.js') - const App = () => { const [eggCount, setEggCount] = useState(0) const [eggVisible, setEggVisible] = useState(false) const [eggKey, setEggKey] = useState(0) - const [updateAvailable, setUpdateAvailable] = useState(false) const languageSupported = useTranslateStore(state => state.navigatorSupported) const translateDialogDismissed = useTranslateStore(state => state.translateDialogDismissed) @@ -30,19 +26,6 @@ const App = () => { } }, [eggCount, eggKey]) - useEffect(() => { - // Register service worker - if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') { - wb.addEventListener('installed', event => { - if (event.isUpdate) { - setUpdateAvailable(true) - } - }) - - wb.register() - } - }, []) - useEffect(() => { document.addEventListener('keyup', eggHandler, false) return () => document.removeEventListener('keyup', eggHandler, false) @@ -71,12 +54,6 @@ const App = () => { - {updateAvailable && ( - }> - setUpdateAvailable(false)} /> - - )} - {eggVisible && setEggVisible(false)} />} ) diff --git a/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.jsx b/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.jsx deleted file mode 100644 index 20f0f31..0000000 --- a/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.jsx +++ /dev/null @@ -1,25 +0,0 @@ -import { useTranslation } from 'react-i18next' - -import { Button } from '/src/components' - -import { - Wrapper, - ButtonWrapper, -} from './UpdateDialog.styles' - -const UpdateDialog = ({ onClose }) => { - const { t } = useTranslation('common') - - return ( - -

{t('common:update.heading')}

-

{t('common:update.body')}

- - - - -
- ) -} - -export default UpdateDialog diff --git a/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.styles.js b/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.styles.js deleted file mode 100644 index fb4ca37..0000000 --- a/crabfit-frontend/src/components/UpdateDialog/UpdateDialog.styles.js +++ /dev/null @@ -1,33 +0,0 @@ -import { styled } from 'goober' - -export const Wrapper = styled('div')` - position: fixed; - bottom: 20px; - right: 20px; - background-color: var(--background); - border: 1px solid var(--surface); - z-index: 900; - padding: 20px 26px; - border-radius: 3px; - width: 400px; - box-sizing: border-box; - max-width: calc(100% - 40px); - box-shadow: 0 3px 6px 0 rgba(0,0,0,.3); - - & h2 { - margin: 0; - font-size: 1.3rem; - } - & p { - margin: 16px 0 24px; - font-size: 1rem; - } -` - -export const ButtonWrapper = styled('div')` - display: flex; - align-items: center; - justify-content: flex-end; - gap: 16px; - flex-wrap: wrap; -` diff --git a/crabfit-frontend/src/components/index.js b/crabfit-frontend/src/components/index.js index 6254806..a0cb606 100644 --- a/crabfit-frontend/src/components/index.js +++ b/crabfit-frontend/src/components/index.js @@ -18,7 +18,6 @@ export { default as Egg } from './Egg/Egg' export { default as Footer } from './Footer/Footer' export { default as Recents } from './Recents/Recents' export { default as Logo } from './Logo/Logo' -export { default as UpdateDialog } from './UpdateDialog/UpdateDialog' export { default as TranslateDialog } from './TranslateDialog/TranslateDialog' export const _GoogleCalendar = () => import('./GoogleCalendar/GoogleCalendar') diff --git a/crabfit-frontend/vite.config.js b/crabfit-frontend/vite.config.js index 9ffcc67..b40ba3b 100644 --- a/crabfit-frontend/vite.config.js +++ b/crabfit-frontend/vite.config.js @@ -1,6 +1,14 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { VitePWA } from 'vite-plugin-pwa' export default defineConfig({ - plugins: [react()], + plugins: [ + react(), + VitePWA({ + registerType: 'autoUpdate', + manifestFilename: 'manifest.json', + strategies: 'injectManifest', + }), + ], }) diff --git a/crabfit-frontend/yarn.lock b/crabfit-frontend/yarn.lock index 10d44f3..ecea15c 100644 --- a/crabfit-frontend/yarn.lock +++ b/crabfit-frontend/yarn.lock @@ -1507,7 +1507,7 @@ debug@^4.1.0, debug@^4.1.1: dependencies: ms "2.1.2" -debug@^4.3.2: +debug@^4.3.2, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -1892,7 +1892,7 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== -fast-glob@^3.2.9: +fast-glob@^3.2.11, fast-glob@^3.2.9: version "3.2.11" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9" integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew== @@ -2776,6 +2776,11 @@ pretty-bytes@^5.3.0, pretty-bytes@^5.4.1: resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg== +pretty-bytes@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.0.0.tgz#928be2ad1f51a2e336add8ba764739f9776a8140" + integrity sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg== + prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" @@ -3020,6 +3025,13 @@ rollup@^2.43.1: optionalDependencies: fsevents "~2.3.2" +rollup@^2.75.7: + version "2.78.1" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.78.1.tgz#52fe3934d9c83cb4f7c4cb5fb75d88591be8648f" + integrity sha512-VeeCgtGi4P+o9hIg+xz4qQpRl6R401LWEXBmxYKOV4zlF82lyhgh2hTZnheFUbANE8l2A41F458iwj2vEYaXJg== + optionalDependencies: + fsevents "~2.3.2" + run-parallel@^1.1.9: version "1.2.0" resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" @@ -3373,6 +3385,18 @@ v8-compile-cache@^2.0.3: resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA== +vite-plugin-pwa@^0.12.3: + version "0.12.3" + resolved "https://registry.yarnpkg.com/vite-plugin-pwa/-/vite-plugin-pwa-0.12.3.tgz#acf2913ae85a4d39c13ae4b948307f3dd5506fa8" + integrity sha512-gmYdIVXpmBuNjzbJFPZFzxWYrX4lHqwMAlOtjmXBbxApiHjx9QPXKQPJjSpeTeosLKvVbNcKSAAhfxMda0QVNQ== + dependencies: + debug "^4.3.4" + fast-glob "^3.2.11" + pretty-bytes "^6.0.0" + rollup "^2.75.7" + workbox-build "^6.5.3" + workbox-window "^6.5.3" + vite@^3.0.7: version "3.0.7" resolved "https://registry.yarnpkg.com/vite/-/vite-3.0.7.tgz#f1e379857e9c5d652126f8b20d371e1365eb700f" @@ -3463,7 +3487,7 @@ workbox-broadcast-update@6.5.4, workbox-broadcast-update@^6.5.4: dependencies: workbox-core "6.5.4" -workbox-build@6.5.4: +workbox-build@6.5.4, workbox-build@^6.5.3: version "6.5.4" resolved "https://registry.yarnpkg.com/workbox-build/-/workbox-build-6.5.4.tgz#7d06d31eb28a878817e1c991c05c5b93409f0389" integrity sha512-kgRevLXEYvUW9WS4XoziYqZ8Q9j/2ziJYEtTrjdz5/L/cTUa2XfyMP2i7c3p34lgqJ03+mTiz13SdFef2POwbA== @@ -3609,7 +3633,7 @@ workbox-webpack-plugin@^6.5.4: webpack-sources "^1.4.3" workbox-build "6.5.4" -workbox-window@6.5.4, workbox-window@^6.5.4: +workbox-window@6.5.4, workbox-window@^6.5.3, workbox-window@^6.5.4: version "6.5.4" resolved "https://registry.yarnpkg.com/workbox-window/-/workbox-window-6.5.4.tgz#d991bc0a94dff3c2dbb6b84558cff155ca878e91" integrity sha512-HnLZJDwYBE+hpG25AQBO8RUWBJRaCsI9ksQJEp3aCOFCaG5kqaToAYXFRAHxzRluM2cQbGzdQF5rjKPWPA1fug==