mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
Added PWA support (#40)
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import './globals.css'
|
||||
import { Inter } from 'next/font/google'
|
||||
import { DM_Sans } from 'next/font/google'
|
||||
import { Toaster } from '@/components/ui/toaster'
|
||||
import { JotaiProvider } from '@/components/jotai-providers'
|
||||
import { Suspense } from 'react'
|
||||
import { JotaiHydrate } from '@/components/jotai-hydrate'
|
||||
import { loadSettings, loadHabitsData, loadCoinsData, loadWishlistData } from './actions/data'
|
||||
import Layout from '@/components/Layout'
|
||||
import { Toaster } from '@/components/ui/toaster'
|
||||
|
||||
// Inter (clean, modern, excellent readability)
|
||||
const inter = Inter({
|
||||
subsets: ['latin'],
|
||||
weight: ['400', '500', '600', '700']
|
||||
})
|
||||
//
|
||||
// const inter = Inter({
|
||||
// subsets: ['latin'],
|
||||
// weight: ['400', '500', '600', '700']
|
||||
// })
|
||||
|
||||
// Clean and contemporary
|
||||
const dmSans = DM_Sans({
|
||||
subsets: ['latin'],
|
||||
@@ -25,7 +27,7 @@ export const metadata = {
|
||||
description: 'Track your habits and get rewarded',
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic' // needed to prevent nextjs from caching the loadSettings function in Layout component
|
||||
export const dynamic = 'force-dynamic' // needed to prevent nextjs from caching the load... functions in Layout component
|
||||
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
@@ -42,6 +44,23 @@ export default async function RootLayout({
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={activeFont.className}>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
.then(registration => {
|
||||
console.log('ServiceWorker registration successful');
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
<JotaiProvider>
|
||||
<Suspense fallback="loading">
|
||||
<JotaiHydrate
|
||||
@@ -52,7 +71,9 @@ export default async function RootLayout({
|
||||
wishlist: initialWishlist
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
<Layout>
|
||||
{children}
|
||||
</Layout>
|
||||
</JotaiHydrate>
|
||||
</Suspense>
|
||||
</JotaiProvider>
|
||||
|
||||
Reference in New Issue
Block a user