Skip to content

Commit

Permalink
Fix sw #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic16x committed Nov 23, 2024
1 parent 7bea333 commit 3220c98
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 309 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
15 changes: 1 addition & 14 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 @@ -23,17 +20,7 @@ declare global {
setInitialPage();

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(`sw.js`, {
scope: '.' // <--- THIS BIT IS REQUIRED
})
.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);
});
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))
))
);
});
Loading

0 comments on commit 3220c98

Please sign in to comment.