Formatting applied

This commit is contained in:
Alicia Sykes committed 2025-09-23 21:29:11 +01:00
1 parent c579bce248
commit 174a627258
6 files changed
+93 -85

No files matched your search

@@ -13,10 +13,10 @@
$: messageData = isOfflinePage
? { message: 'Currently offline. Awaiting internet connection...', showLink: false, isError: false }
: isActualTool
? { message: 'You are offline. This tool has been downloaded.', showLink: false, isError: false }
: !worksOffline
? { message: 'This tool may not function correctly without network access', showLink: false, isError: true }
: { message: 'Offline, limited functionality available.', showLink: true, isError: false };
? { message: 'You are offline. This tool has been downloaded.', showLink: false, isError: false }
: !worksOffline
? { message: 'This tool may not function correctly without network access', showLink: false, isError: true }
: { message: 'Offline, limited functionality available.', showLink: true, isError: false };
$: message = messageData.message;
$: showOfflineLink = messageData.showLink;
+40 -35
View File
@@ -20,7 +20,7 @@ export const serviceWorkerRegistered = writable(false);
export const offlineCapabilities = writable({
cacheEnabled: false,
backgroundSync: false,
pushNotifications: false
pushNotifications: false,
});
// Initialize offline functionality
@@ -37,12 +37,14 @@ export function initializeOfflineSupport() {
// Trigger background sync if available
if ('serviceWorker' in navigator && 'sync' in window.ServiceWorkerRegistration.prototype) {
navigator.serviceWorker.ready.then(registration => {
// Cast to any to work around TypeScript sync API limitations
return (registration as any).sync.register('background-sync-bookmarks');
}).catch(err => {
log('Offline', ' Background sync failed:', err);
});
navigator.serviceWorker.ready
.then((registration) => {
// Cast to any to work around TypeScript sync API limitations
return (registration as any).sync.register('background-sync-bookmarks');
})
.catch((err) => {
log('Offline', ' Background sync failed:', err);
});
}
};
@@ -76,7 +78,7 @@ async function registerServiceWorker() {
try {
const registration = await navigator.serviceWorker.register('/sw.js', {
scope: '/'
scope: '/',
});
serviceWorkerRegistered.set(true);
@@ -86,7 +88,7 @@ async function registerServiceWorker() {
offlineCapabilities.set({
cacheEnabled: true,
backgroundSync: 'sync' in (registration as any),
pushNotifications: 'showNotification' in registration
pushNotifications: 'showNotification' in registration,
});
// Listen for service worker updates
@@ -119,7 +121,6 @@ async function registerServiceWorker() {
log('SW', ' Unknown message type:', type);
}
});
} catch (error) {
log('SW', 'Service worker registration failed:', error);
serviceWorkerRegistered.set(false);
@@ -130,32 +131,36 @@ async function registerServiceWorker() {
export function cacheBookmark(url: string) {
if (!browser || !('serviceWorker' in navigator)) return;
navigator.serviceWorker.ready.then(registration => {
if (registration.active) {
registration.active.postMessage({
type: 'CACHE_BOOKMARK',
url: url
});
}
}).catch(error => {
log('SW', ' Failed to cache bookmark:', error);
});
navigator.serviceWorker.ready
.then((registration) => {
if (registration.active) {
registration.active.postMessage({
type: 'CACHE_BOOKMARK',
url: url,
});
}
})
.catch((error) => {
log('SW', ' Failed to cache bookmark:', error);
});
}
// Cache all bookmarks at once
export function cacheAllBookmarks(bookmarks: any[]) {
if (!browser || !('serviceWorker' in navigator)) return;
navigator.serviceWorker.ready.then(registration => {
if (registration.active) {
registration.active.postMessage({
type: 'CACHE_ALL_BOOKMARKS',
bookmarks: bookmarks
});
}
}).catch(error => {
log('SW', ' Failed to cache all bookmarks:', error);
});
navigator.serviceWorker.ready
.then((registration) => {
if (registration.active) {
registration.active.postMessage({
type: 'CACHE_ALL_BOOKMARKS',
bookmarks: bookmarks,
});
}
})
.catch((error) => {
log('SW', ' Failed to cache all bookmarks:', error);
});
}
// Sync bookmarks data (called by service worker)
@@ -176,8 +181,8 @@ function getAllToolRoutes(): string[] {
const toolRoutes: string[] = [];
// Iterate through all sections in SUB_NAV
Object.values(SUB_NAV).forEach(sectionItems => {
sectionItems.forEach(item => {
Object.values(SUB_NAV).forEach((sectionItems) => {
sectionItems.forEach((item) => {
if ('href' in item && item.href) {
// Extract the route pattern from the href
const pathParts = item.href.split('/').filter(Boolean);
@@ -189,7 +194,7 @@ function getAllToolRoutes(): string[] {
}
} else if ('items' in item && item.items) {
// Handle NavGroup - extract routes from nested items
item.items.forEach(subItem => {
item.items.forEach((subItem) => {
if (subItem.href) {
const pathParts = subItem.href.split('/').filter(Boolean);
if (pathParts.length >= 2) {
@@ -210,11 +215,11 @@ function getAllToolRoutes(): string[] {
// Check if a URL is an actual downloadable tool (not just a regular page)
export function isDownloadableTool(url: string): boolean {
const toolRoutes = getAllToolRoutes();
return toolRoutes.some(route => url.includes(route));
return toolRoutes.some((route) => url.includes(route));
}
// Derived store for offline-ready status
export const offlineReady = derived(
[serviceWorkerRegistered, offlineCapabilities],
([$registered, $capabilities]) => $registered && $capabilities.cacheEnabled
([$registered, $capabilities]) => $registered && $capabilities.cacheEnabled,
);
+1 -1
View File
@@ -23,4 +23,4 @@ export async function initializeVersion() {
log('Failed to fetch version from API, using fallback');
// Keep fallback version
}
}
}
+2 -2
View File
@@ -11,6 +11,6 @@ export const load: PageServerLoad = async () => {
return {
breadcrumbJsonLd: null, // No breadcrumbs needed for offline page
version: '0.2.5', // Hardcoded fallback version for offline page
isOfflinePage: true // Flag to indicate this is the special offline page
isOfflinePage: true, // Flag to indicate this is the special offline page
};
};
};
+36 -36
View File
@@ -11,7 +11,7 @@
const handleOnline = () => {
isOnline = true;
setTimeout(() => window.location.href = '/', 1000);
setTimeout(() => (window.location.href = '/'), 1000);
};
const handleOffline = () => {
@@ -35,14 +35,14 @@
<div class="offline-page">
<div class="status-section">
<Icon name={isOnline ? "online" : "offline"} size="lg" />
<Icon name={isOnline ? 'online' : 'offline'} size="lg" />
<h1>
{isOnline ? "Back Online" : "You're Offline"}
{isOnline ? 'Back Online' : "You're Offline"}
</h1>
<p class="status" class:online={isOnline} class:offline={!isOnline}>
{isOnline ? "Connection restored! Redirecting..." : "Your bookmarked tools work offline"}
{isOnline ? 'Connection restored! Redirecting...' : 'Your bookmarked tools work offline'}
</p>
</div>
@@ -59,48 +59,48 @@
</div>
<style lang="scss">
.offline-page {
width: 100%;
max-width: none;
padding: 2rem;
}
.status-section {
text-align: center;
margin-bottom: 3rem;
h1 {
margin: 1rem 0 0.5rem;
.offline-page {
width: 100%;
max-width: none;
padding: 2rem;
}
.status {
font-weight: 500;
padding: 0.75rem;
border-radius: var(--radius);
.status-section {
text-align: center;
margin-bottom: 3rem;
&.online {
color: var(--color-success);
background: color-mix(in srgb, var(--color-success), transparent 90%);
h1 {
margin: 1rem 0 0.5rem;
}
&.offline {
color: var(--color-warning);
background: color-mix(in srgb, var(--color-warning), transparent 90%);
.status {
font-weight: 500;
padding: 0.75rem;
border-radius: var(--radius);
&.online {
color: var(--color-success);
background: color-mix(in srgb, var(--color-success), transparent 90%);
}
&.offline {
color: var(--color-warning);
background: color-mix(in srgb, var(--color-warning), transparent 90%);
}
}
}
}
.empty-state {
text-align: center;
color: var(--color-text-muted);
.empty-state {
text-align: center;
color: var(--color-text-muted);
a {
color: var(--color-primary);
text-decoration: none;
a {
color: var(--color-primary);
text-decoration: none;
&:hover {
text-decoration: underline;
&:hover {
text-decoration: underline;
}
}
}
}
</style>
+10 -7
View File
@@ -7,13 +7,16 @@ export async function GET() {
const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
return json({
version: pkg.version,
timestamp: Date.now()
timestamp: Date.now(),
});
} catch {
return json({
version: 'unknown',
timestamp: Date.now(),
error: 'Failed to read version'
}, { status: 500 });
return json(
{
version: 'unknown',
timestamp: Date.now(),
error: 'Failed to read version',
},
{ status: 500 },
);
}
}
}