Skip to content

Commit

Permalink
Fix sw (#342)
Browse files Browse the repository at this point in the history
* Fix sw

* Fix sw #1

* Fix sw #2
  • Loading branch information
sonic16x authored Nov 23, 2024
1 parent 88bbf02 commit 5668264
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 147 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interslavic",
"version": "1.23.2",
"version": "1.24.0",
"description": "Interslavic Dictionary",
"license": "MIT",
"author": {
Expand Down
10 changes: 0 additions & 10 deletions src/404.html.ejs

This file was deleted.

7 changes: 1 addition & 6 deletions src/components/Pages/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export const About =
const worksheetUrl = getTablePublicUrl(tablesData[0].spreadsheetId, tablesData[0].sheetId);
const email = '[email protected]';
const source = 'http://steen.free.fr/interslavic';
let version = `v${VERSION}`;
const trimmedBaseUrl = BASE_URL.replace('/', '');
if (trimmedBaseUrl !== '') {
version += `-${trimmedBaseUrl}`;
}

return (
<div className="about-page">
Expand Down Expand Up @@ -151,7 +146,7 @@ export const About =
)}
</div>
</div>
<div className="about-page__release-date">{version}</div>
<div className="about-page__release-date">v{VERSION}</div>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Router/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Router =
const onChangeUrl = () => {
const currentPage = getPageFromPath();

if (getPathFromPage(page) !== `${BASE_URL}${currentPage}`) {
if (getPathFromPage(page) !== `/${currentPage}`) {
dispatch(setPageAction(currentPage));
}
};
Expand Down
17 changes: 2 additions & 15 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { store } from './store'

declare global {
const VERSION: string;
const BASE_URL: string;
const SW: boolean;
const CLIENT: boolean;
// eslint-disable-next-line
interface Window {
__REDUX_DEVTOOLS_EXTENSION__: any;
Expand All @@ -22,18 +19,8 @@ declare global {

setInitialPage();

if (SW) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(`sw.js`)
.then((registration) => {
// eslint-disable-next-line no-console
console.log('Registration successful, scope is:', registration.scope);
})
.catch((error) => {
// eslint-disable-next-line no-console
console.log('Service worker registration failed, error:', error);
});
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(`sw.js`, { scope: '.' });
}


Expand Down
16 changes: 8 additions & 8 deletions src/routing/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ export const pages: IPage[] = [
{
title: 'dictionaryTitle',
value: 'dictionary',
path: BASE_URL,
path: '/',
},
{
title: 'communityTitle',
value: 'community',
path: `${BASE_URL}community`,
path: '/community',
online: true,
},
{
title: 'grammarTitle',
value: 'grammar',
path: `${BASE_URL}grammar`,
path: '/grammar',
},
{
title: 'viewerTitle',
value: 'viewer',
path: `${BASE_URL}viewer`,
path: '/viewer',
online: true,
},
{
title: 'settingsTitle',
value: 'settings',
path: `${BASE_URL}settings`,
path: '/settings',
},
{
title: 'aboutTitle',
value: 'about',
path: `${BASE_URL}about`,
path: '/about',
},
];

Expand All @@ -61,7 +61,7 @@ export function setInitialPage() {
const currentPath = window.location.pathname.split('#')[0];
const page = pages.find(({ path }) => (path === currentPath));
if (!page) {
window.history.replaceState({}, document.title, BASE_URL);
window.history.replaceState({}, document.title, '/');
}
}

Expand All @@ -71,5 +71,5 @@ export function getPathFromPage(page: string): string {
return finded.path;
}

return BASE_URL;
return '/';
}
50 changes: 50 additions & 0 deletions src/serviceWorker/cashUrls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { addLangs } from 'consts';

export const CASH_URLS = [
'/',
'/data/basic.json',
'/data/translateStatistic.json',
...addLangs.map((lang) => `/data/${lang}.json`),
'/grammarComponent.js',
'/communityComponent.js',
'/index.js',
'/sw.js',
'/styles/grammarComponent.css',
'/styles/communityComponent.css',
'/styles/index.css',
'/icons/android-icon-36x36.png',
'/icons/android-icon-48x48.png',
'/icons/android-icon-72x72.png',
'/icons/android-icon-96x96.png',
'/icons/android-icon-144x144.png',
'/icons/android-icon-192x192.png',
'/icons/apple-icon.png',
'/icons/apple-icon-57x57.png',
'/icons/apple-icon-60x60.png',
'/icons/apple-icon-72x72.png',
'/icons/apple-icon-76x76.png',
'/icons/apple-icon-114x114.png',
'/icons/apple-icon-120x120.png',
'/icons/apple-icon-144x144.png',
'/icons/apple-icon-152x152.png',
'/icons/apple-icon-180x180.png',
'/icons/apple-icon-precomposed.png',
'/icons/discord-icon-330x102.png',
'/icons/favicon.ico',
'/icons/favicon-16x16.png',
'/icons/favicon-32x32.png',
'/icons/favicon-96x96.png',
'/icons/icon-72x72.png',
'/icons/icon-96x96.png',
'/icons/icon-128x128.png',
'/icons/icon-144x144.png',
'/icons/icon-152x152.png',
'/icons/icon-192x192.png',
'/icons/icon-384x384.png',
'/icons/icon-512x512.png',
'/icons/manifest.json',
'/icons/ms-icon-70x70.png',
'/icons/ms-icon-144x144.png',
'/icons/ms-icon-150x150.png',
'/icons/ms-icon-310x310.png',
];
46 changes: 46 additions & 0 deletions src/serviceWorker/sw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { CASH_URLS } from './cashUrls';

self.addEventListener("install", (event: any) => {
event.waitUntil(
caches
.open(`${VERSION}fundamentals`)
.then((cache) => cache.addAll(CASH_URLS))
);
});

self.addEventListener("fetch", (event: any) => {
if (event.request.method !== 'GET') {
return;
}

event.respondWith(
caches
.match(event.request)
.then((cached) => {
const networked = fetch(event.request)
.then((response: any) => {
const cacheCopy = response.clone();

caches
.open(`${VERSION}pages`)
.then((cache) => cache.put(event.request, cacheCopy))

return response;
});

return cached || networked;
})
);
});

self.addEventListener("activate", (event: any) => {
event.waitUntil(
caches
.keys()
.then((keys) => Promise.all(
keys
.filter((key) => !key.startsWith(VERSION))
.map((key) => caches.delete(key))
))
);
});
71 changes: 0 additions & 71 deletions src/sw.ts

This file was deleted.

8 changes: 4 additions & 4 deletions static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Word dictionary for interslavic language",
"lang": "en",
"dir": "ltr",
"scope": "https://interslavic-dictionary.com/",
"scope": ".",
"icons": [
{
"src": "icons/icon-72x72.png",
Expand Down Expand Up @@ -48,11 +48,11 @@
}
],
"serviceworker": {
"src": "sw.prod.js",
"scope": "https://interslavic-dictionary.com/",
"src": "sw.js",
"scope": ".",
"update_via_cache": "none"
},
"start_url": "https://interslavic-dictionary.com/",
"start_url": "/",
"background_color": "#272727",
"display": "standalone",
"orientation": "portrait-primary",
Expand Down
10 changes: 1 addition & 9 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const outputPath = path.resolve(__dirname, 'dist');
const srcPath = path.resolve(__dirname, 'src');
const nodeModulesPath = path.resolve(__dirname, 'node_modules/');
const baseUrl = '/';

module.exports = {
entry: {
index: './src/index',
grammarComponent: './src/components/Pages/Grammar/Grammar',
viewerComponent: './src/components/Pages/Viewer/Viewer',
communityComponent: './src/components/Pages/CommunityPage/CommunityPage',
sw: './src/sw',
sw: './src/serviceWorker/sw',
},
output: {
path: outputPath,
Expand Down Expand Up @@ -75,17 +74,10 @@ module.exports = {
filename: 'index.html',
path: outputPath,
excludeChunks: ['sw', 'grammarComponent', 'viewerComponent', 'communityComponent'],
env: {
BASE_URL: baseUrl,
},
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
SW: false,
IS_COM: true,
CLIENT: true,
BASE_URL: JSON.stringify(baseUrl),
DATE: JSON.stringify(new Date().toISOString()),
VERSION: JSON.stringify(require('./package.json').version),
}),
new CopyWebpackPlugin({
Expand Down
Loading

0 comments on commit 5668264

Please sign in to comment.