Skip to content

Commit

Permalink
offline & fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GravitySow committed Sep 4, 2024
1 parent b53a7b2 commit 33ca4f8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
50 changes: 50 additions & 0 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('my-pwa-cache').then((cache) => {
return cache.addAll([
'/',
'/favicon.ico',
'/cons60-logo.png',
'/index.html',
'/manifest.json',
'/static/js/bundle.js',
'/data/constitution.json?v=1.0.0',
'/data/minutes.json?v=1.0.0',
'/static/js/main.chunk.js',
'/static/js/0.chunk.js',
'/static/css/main.6dfa0ae8.css',
'/static/js/main.39418a90.js',
'/android-chrome-192x192.png',
'/data/chapter-01.json?v=1.0.0',
'/data/chapter-02.json?v=1.0.0',
'/data/chapter-03.json?v=1.0.0',
'/data/chapter-04.json?v=1.0.0',
'/data/chapter-05.json?v=1.0.0',
'/data/chapter-06.json?v=1.0.0',
'/data/chapter-07.json?v=1.0.0',
'/data/chapter-08.json?v=1.0.0',
'/data/chapter-09.json?v=1.0.0',
'/data/chapter-10.json?v=1.0.0',
'/data/chapter-11.json?v=1.0.0',
'/data/chapter-12.json?v=1.0.0',
'/data/chapter-13.json?v=1.0.0',
'/data/chapter-14.json?v=1.0.0',
'/data/chapter-15.json?v=1.0.0',
'/data/chapter-16.json?v=1.0.0',
'/data/transitory-provisions.json?v=1.0.0',
'/static/media/mainmenu.5ad6049cfb419be336a4.jpg',


// Add other assets and routes to cache
]);
})
);
});

self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
return response;
})
);
});
22 changes: 22 additions & 0 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// let cacheData = "appV1"
// this.addEventListener("install", (event) => {
// event.waitUntil(
// caches.open(cacheData).then((cache) => {
// cache.addAll([
// '/static/js/main.chunk.js',
// '/static/js/0.chunk.js',
// '/static/js/bundle.js',
// '/index.html',
// '/'
// ])
// })
// )
// })

// this.addEventListener("fetch", (event) => {
// event.respondwith(
// caches.match(event.request).then((resp) => {
// if(resp) return resp
// })
// )
// })
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import App from './App';
import reportWebVitals from './reportWebVitals';
import { HashRouter } from 'react-router-dom';

if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js')
.then((registration) => {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch((error) => {
console.log('Service Worker registration failed:', error);
});
});
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function Search({ searchInputValue, setSearchInputValue }) {
const [section, chapter] = item[1].split('|');
return (
<Link
to={"/section/" + item[0] + `/${searchInputValue.trim().replace(/\s/g, '+')}`}
to={"/section/" + item[0] + `/${searchInputValue}`}
onClick={() => saveHistory(searchInputValue)}
key={index}
state={{ backable: true }}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/highlight.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export default function highlight(content, words='') {
if (!words) {
return content
}
return words
.trim()
.split('+')
.split(' ')
.reduce(
(hc, word) => hc.replace(
new RegExp(word, 'gi'),
`<span class="highlight">${word}</span>`
)
, content)
, content)

}

0 comments on commit 33ca4f8

Please sign in to comment.