Skip to content

Commit 6ed5ff4

Browse files
authored
Merge pull request #97 from malikpiara/v2
Logicola is now a PWA and works offline
2 parents ab5964f + b820c37 commit 6ed5ff4

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

app/layout.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Footer } from '@/components/footer';
77
import { CSPostHogProvider } from '@/components/providers';
88
import thumbnail from '../public/thumbnail.jpg';
99
import ExerciseNavbar from '@/components/mobile/exerciseNavbar';
10+
import RegisterSW from '@/components/providers/service-worker';
1011

1112
const robotoFlex = Roboto_Flex({
1213
subsets: ['latin'],
@@ -16,6 +17,7 @@ const robotoFlex = Roboto_Flex({
1617

1718
export const metadata: Metadata = {
1819
metadataBase: new URL('https://logicola.org'),
20+
themeColor: '#ffffff',
1921
title: 'Logicola',
2022
description:
2123
'LogiCola is a program to help students learn logic. This is a web version of the original software built by the late Professor Harry Gensler.',
@@ -58,6 +60,10 @@ export default function RootLayout({
5860
}>) {
5961
return (
6062
<html lang='en'>
63+
<head>
64+
<meta name='theme-color' content='#FFFFFF' />
65+
<link rel='manifest' href='/manifest.json' />
66+
</head>
6167
<CSPostHogProvider>
6268
<body
6369
className={`antialiased min-h-screen bg-white text-primaryColor ${robotoFlex.className}`}
@@ -67,6 +73,7 @@ export default function RootLayout({
6773

6874
<Navbar />
6975
<main className={`flex`}>{children}</main>
76+
<RegisterSW />
7077
<Footer />
7178
</body>
7279
</CSPostHogProvider>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// You could create a new component like RegisterSW.tsx
2+
'use client';
3+
import { useEffect } from 'react';
4+
5+
export default function RegisterSW() {
6+
useEffect(() => {
7+
if ('serviceWorker' in navigator) {
8+
navigator.serviceWorker
9+
.register('/sw.js')
10+
.then((registration) => console.log('SW registered:', registration))
11+
.catch((error) => console.log('SW registration failed:', error));
12+
}
13+
}, []);
14+
15+
return null;
16+
}

public/icon-192.png

4.99 KB
Loading

public/icon-512.png

14.2 KB
Loading

public/manifest.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "LogiCola",
3+
"short_name": "LogiCola",
4+
"description": "LogiCola helps you learn logic.",
5+
"start_url": "/",
6+
"display": "standalone",
7+
"background_color": "#ffffff",
8+
"theme_color": "#ffffff",
9+
"orientation": "portrait",
10+
"icons": [
11+
{
12+
"src": "/icon-192.png",
13+
"sizes": "192x192",
14+
"type": "image/png",
15+
"purpose": "any maskable"
16+
},
17+
{
18+
"src": "/icon-512.png",
19+
"sizes": "512x512",
20+
"type": "image/png"
21+
}
22+
]
23+
}

public/sw.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const CACHE_NAME = 'logicola-cache-v1';
2+
const urlsToCache = [
3+
'/',
4+
'/manifest.json',
5+
'/icon.svg',
6+
// Add other static assets like
7+
'/globals.css',
8+
// Add any other pages/routes you want to cache
9+
];
10+
11+
self.addEventListener('install', (event) => {
12+
event.waitUntil(
13+
caches.open(CACHE_NAME)
14+
.then((cache) => {
15+
return cache.addAll(urlsToCache);
16+
})
17+
);
18+
});
19+
20+
self.addEventListener('fetch', (event) => {
21+
event.respondWith(
22+
caches.match(event.request)
23+
.then((response) => {
24+
// Return cached version or fetch from network
25+
return response || fetch(event.request);
26+
})
27+
);
28+
});

0 commit comments

Comments
 (0)