Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions app/components/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
);
}

// Render without Dynamic until explicitly initialized
if (!isDynamicInitialized) {
return (
<AuthContext.Provider
value={{
isAuthenticated,
user,
hasActiveSubscription,
checkingSubscription,
subscriptionData,
refreshSubscription,
initializeDynamic,
isDynamicInitialized,
openAuthModal: () => {},
}}
>
{children}
</AuthContext.Provider>
);
}

// Always render DynamicContextProvider to avoid unmounting/remounting children
// Control visibility through isDynamicInitialized flag
return (
<DynamicContextProvider
settings={{
Expand All @@ -298,10 +279,12 @@ export function AuthProvider({ children }: { children: ReactNode }) {
},
}}
>
<AuthStateSync
onAuthStateChange={handleAuthStateChange}
onOpenAuthModal={handleOpenAuthModal}
/>
{isDynamicInitialized && (
<AuthStateSync
onAuthStateChange={handleAuthStateChange}
onOpenAuthModal={handleOpenAuthModal}
/>
)}
<AuthContext.Provider
value={{
isAuthenticated,
Expand Down
47 changes: 36 additions & 11 deletions app/components/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ export default function MenuBar() {
const [cacheInfo, setCacheInfo] = useState<{ studies: number; sizeMB: number } | null>(null);
const [llmProvider, setLlmProvider] = useState<string>('');

// Extract loadCacheInfo for reusability
const loadCacheInfo = async () => {
const { gwasDB } = await import('@/lib/gwas-db');
const metadata = await gwasDB.getMetadata();
if (metadata) {
const size = await gwasDB.getStorageSize();
setCacheInfo({
studies: metadata.totalStudies,
sizeMB: Math.round(size / 1024 / 1024)
});
} else {
setCacheInfo(null);
}
};

useEffect(() => {
// Mark component as mounted
setMounted(true);
Expand All @@ -45,19 +60,29 @@ export default function MenuBar() {
const config = getLLMConfig();
setLlmProvider(getProviderDisplayName(config.provider));

// Load cache info
const loadCacheInfo = async () => {
const { gwasDB } = await import('@/lib/gwas-db');
const metadata = await gwasDB.getMetadata();
if (metadata) {
const size = await gwasDB.getStorageSize();
setCacheInfo({
studies: metadata.totalStudies,
sizeMB: Math.round(size / 1024 / 1024)
});
// Load cache info on mount
loadCacheInfo();

// Listen for cache updates
const handleCacheUpdated = () => {
console.log('[MenuBar] Cache updated event received, refreshing cache info');
loadCacheInfo();
};

// Listen for visibility changes to refresh cache when user returns to tab
const handleVisibilityChange = () => {
if (document.visibilityState === 'visible') {
loadCacheInfo();
}
};
loadCacheInfo();

window.addEventListener('cacheUpdated', handleCacheUpdated);
document.addEventListener('visibilitychange', handleVisibilityChange);

return () => {
window.removeEventListener('cacheUpdated', handleCacheUpdated);
document.removeEventListener('visibilitychange', handleVisibilityChange);
};
}, []);

useEffect(() => {
Expand Down
13 changes: 12 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Metadata } from "next";
import Script from "next/script";
import "./globals.css";
import { AuthProvider } from "./components/AuthProvider";
import { GenotypeProvider } from "./components/UserDataUpload";
import { ResultsProvider } from "./components/ResultsContext";
import { CustomizationProvider } from "./components/CustomizationContext";

export const metadata: Metadata = {
title: "Monadic DNA Explorer",
Expand Down Expand Up @@ -72,7 +75,15 @@ export default function RootLayout({
</Script>
</head>
<body>
<AuthProvider>{children}</AuthProvider>
<AuthProvider>
<GenotypeProvider>
<ResultsProvider>
<CustomizationProvider>
{children}
</CustomizationProvider>
</ResultsProvider>
</GenotypeProvider>
</AuthProvider>
</body>
</html>
);
Expand Down
22 changes: 8 additions & 14 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use client";

import { useEffect, useMemo, useState, useCallback, useRef } from "react";
import { GenotypeProvider, useGenotype } from "./components/UserDataUpload";
import { ResultsProvider, useResults } from "./components/ResultsContext";
import { CustomizationProvider } from "./components/CustomizationContext";
import { useGenotype } from "./components/UserDataUpload";
import { useResults } from "./components/ResultsContext";
import { AuthButton, useAuth } from "./components/AuthProvider";
import { RunAllIcon, LLMChatIcon, OverviewReportIcon } from "./components/Icons";
import StudyResultReveal from "./components/StudyResultReveal";
Expand Down Expand Up @@ -100,7 +99,7 @@ type QualitySummary = {
};

const defaultFilters: Filters = {
search: "",
search: "sleep",
searchMode: "similarity",
trait: "",
minSampleSize: "500",
Expand All @@ -110,7 +109,7 @@ const defaultFilters: Filters = {
requireUserSNPs: false,
sort: "relevance",
sortDirection: "desc",
limit: 200,
limit: 1000,
confidenceBand: null,
offset: 0,
};
Expand Down Expand Up @@ -625,6 +624,9 @@ function MainContent() {
await addResultsBatch(results); // Embeddings will be fetched on-demand during LLM analysis
const addTime = Date.now() - startAdd;
console.log(`Finished adding ${results.length} results in ${addTime}ms`);

// Notify MenuBar that cache has been updated
window.dispatchEvent(new CustomEvent('cacheUpdated'));
} catch (error) {
console.error('Run All failed:', error);
setRunAllStatus(prev => ({
Expand Down Expand Up @@ -1412,13 +1414,5 @@ function MainContent() {
}

export default function HomePage() {
return (
<GenotypeProvider>
<ResultsProvider>
<CustomizationProvider>
<MainContent />
</CustomizationProvider>
</ResultsProvider>
</GenotypeProvider>
);
return <MainContent />;
}
Loading