mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
fix
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { useEffect } from 'react';
|
||||
import { usePublicSettings } from './usePublicSettings';
|
||||
import { getFontPairing, applyFontPairing, getDefaultFontPairing } from '../config/fonts';
|
||||
import {
|
||||
FONT_PAIRINGS,
|
||||
getFontPairing,
|
||||
applyFontPairing,
|
||||
getDefaultFontPairing,
|
||||
type FontPairing,
|
||||
} from '../config/fonts';
|
||||
|
||||
/**
|
||||
* Hook to load and apply club fonts from settings
|
||||
@@ -12,15 +18,14 @@ export const useFontLoader = () => {
|
||||
// Determine which font pairing to use
|
||||
const fontId = settings?.font_heading || settings?.font_body;
|
||||
|
||||
let pairing;
|
||||
let pairing: FontPairing | undefined;
|
||||
if (fontId) {
|
||||
// Try to find matching pairing by heading or body font name
|
||||
pairing = getFontPairing(fontId);
|
||||
|
||||
// If not found by ID, try to find by font name
|
||||
if (!pairing) {
|
||||
const allPairings = require('../config/fonts').FONT_PAIRINGS;
|
||||
pairing = allPairings.find((p: any) =>
|
||||
pairing = FONT_PAIRINGS.find((p) =>
|
||||
p.heading === fontId ||
|
||||
p.body === fontId ||
|
||||
p.id === fontId
|
||||
|
||||
@@ -20,20 +20,37 @@ export function register(config?: Config) {
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log('Service worker is ready in development mode');
|
||||
});
|
||||
disableLocalServiceWorkers();
|
||||
return;
|
||||
} else {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function disableLocalServiceWorkers() {
|
||||
navigator.serviceWorker
|
||||
.getRegistrations()
|
||||
.then(async (registrations) => {
|
||||
await Promise.all(registrations.map((registration) => registration.unregister()));
|
||||
|
||||
if ('caches' in window) {
|
||||
const cacheKeys = await caches.keys();
|
||||
await Promise.all(cacheKeys.map((key) => caches.delete(key)));
|
||||
}
|
||||
|
||||
if (registrations.length > 0) {
|
||||
console.log('Localhost detected; cleared service workers and caches.');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error while clearing localhost service workers:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
@@ -68,30 +85,6 @@ function registerValidSW(swUrl: string, config?: Config) {
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then((response) => {
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log('No internet connection found. App is running in offline mode.');
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
|
||||
Reference in New Issue
Block a user