Skip to content

Commit 8f757b1

Browse files
debug: add visible debug panel and direct API test button
- Add debug panel that shows on GitHub Pages - Add Test API button for direct fetch call - Add comprehensive logging throughout initialization - This will help identify where the issue is occurring
1 parent e1b8b77 commit 8f757b1

File tree

4 files changed

+111
-19
lines changed

4 files changed

+111
-19
lines changed

app/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TabNav from '@/components/TabNav';
55
import StandupTab from '@/components/StandupTab';
66
import SurveyTab from '@/components/SurveyTab';
77
import ResultsTab from '@/components/ResultsTab';
8+
import DebugPanel from '@/components/DebugPanel';
89
import { dataService } from '@/lib/dataService';
910
import { setupNetworkDebugging, checkEnvironment } from '@/lib/debug';
1011

@@ -57,6 +58,7 @@ export default function Home() {
5758
</div>
5859
</div>
5960
</div>
61+
<DebugPanel />
6062
</div>
6163
);
6264
}

components/DebugPanel.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use client';
2+
3+
import { useState, useEffect } from 'react';
4+
5+
export default function DebugPanel() {
6+
const [logs, setLogs] = useState<string[]>([]);
7+
const [isVisible, setIsVisible] = useState(false);
8+
9+
useEffect(() => {
10+
// Only show in production
11+
if (typeof window !== 'undefined' && window.location.hostname.includes('github.io')) {
12+
setIsVisible(true);
13+
14+
// Override console methods to capture logs
15+
const originalLog = console.log;
16+
const originalError = console.error;
17+
const originalWarn = console.warn;
18+
19+
const addLog = (type: string, ...args: any[]) => {
20+
const message = `[${type}] ${args.map(arg =>
21+
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
22+
).join(' ')}`;
23+
setLogs(prev => [...prev.slice(-19), message]);
24+
25+
// Call original console method
26+
if (type === 'LOG') originalLog(...args);
27+
if (type === 'ERROR') originalError(...args);
28+
if (type === 'WARN') originalWarn(...args);
29+
};
30+
31+
console.log = (...args) => addLog('LOG', ...args);
32+
console.error = (...args) => addLog('ERROR', ...args);
33+
console.warn = (...args) => addLog('WARN', ...args);
34+
35+
// Initial debug info
36+
console.log('Debug panel active');
37+
console.log('URL:', window.location.href);
38+
console.log('Supabase loaded:', typeof window !== 'undefined' && 'supabase' in window);
39+
40+
return () => {
41+
// Restore original console methods
42+
console.log = originalLog;
43+
console.error = originalError;
44+
console.warn = originalWarn;
45+
};
46+
}
47+
}, []);
48+
49+
if (!isVisible) return null;
50+
51+
return (
52+
<div className="fixed bottom-4 right-4 w-96 max-h-64 bg-black text-green-400 p-4 rounded-lg shadow-lg overflow-y-auto font-mono text-xs z-50">
53+
<div className="mb-2 text-yellow-400">🔍 Debug Console</div>
54+
{logs.length === 0 ? (
55+
<div className="text-gray-400">No logs yet...</div>
56+
) : (
57+
logs.map((log, i) => (
58+
<div key={i} className="mb-1 whitespace-pre-wrap break-all">
59+
{log}
60+
</div>
61+
))
62+
)}
63+
</div>
64+
);
65+
}

components/ResultsTab.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,42 @@ export default function ResultsTab() {
308308
<h2 className="text-2xl font-semibold text-gray-800" style={{ fontFamily: 'var(--font-roboto-serif)' }}>
309309
Team health metrics over time
310310
</h2>
311-
<button
312-
onClick={() => {
313-
setLoading(true);
314-
fetchResponses();
315-
}}
316-
className="px-4 py-2 bg-[#2C6496] text-white rounded-lg hover:bg-[#1e4268] transition-colors"
317-
style={{ fontFamily: 'var(--font-roboto)' }}
318-
>
319-
Refresh
320-
</button>
311+
<div className="flex gap-2">
312+
<button
313+
onClick={async () => {
314+
console.log('Test button clicked');
315+
try {
316+
console.log('Making direct Supabase call...');
317+
const response = await fetch('https://mbhrkgzrswaysrmpdehz.supabase.co/rest/v1/survey_responses', {
318+
headers: {
319+
'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1iaHJrZ3pyc3dheXNybXBkZWh6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ1MTU2NjAsImV4cCI6MjA3MDA5MTY2MH0._JP4S6jVxYt0w7mSL2Rci59pSii0kDK1g9qfgFFtXKI',
320+
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1iaHJrZ3pyc3dheXNybXBkZWh6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ1MTU2NjAsImV4cCI6MjA3MDA5MTY2MH0._JP4S6jVxYt0w7mSL2Rci59pSii0kDK1g9qfgFFtXKI'
321+
}
322+
});
323+
const data = await response.json();
324+
console.log('Direct fetch result:', data);
325+
alert('Check console - got ' + (Array.isArray(data) ? data.length : 0) + ' records');
326+
} catch (err) {
327+
console.error('Direct fetch error:', err);
328+
alert('Error: ' + err);
329+
}
330+
}}
331+
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors"
332+
style={{ fontFamily: 'var(--font-roboto)' }}
333+
>
334+
Test API
335+
</button>
336+
<button
337+
onClick={() => {
338+
setLoading(true);
339+
fetchResponses();
340+
}}
341+
className="px-4 py-2 bg-[#2C6496] text-white rounded-lg hover:bg-[#1e4268] transition-colors"
342+
style={{ fontFamily: 'var(--font-roboto)' }}
343+
>
344+
Refresh
345+
</button>
346+
</div>
321347
</div>
322348

323349
<div ref={chartContainerRef}></div>

lib/supabase.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import { createClient } from '@supabase/supabase-js';
44
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://mbhrkgzrswaysrmpdehz.supabase.co';
55
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1iaHJrZ3pyc3dheXNybXBkZWh6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ1MTU2NjAsImV4cCI6MjA3MDA5MTY2MH0._JP4S6jVxYt0w7mSL2Rci59pSii0kDK1g9qfgFFtXKI';
66

7-
// Only log in browser environment
8-
if (typeof window !== 'undefined') {
9-
console.log('Supabase initialization:', {
10-
url: supabaseUrl,
11-
keyLength: supabaseAnonKey?.length,
12-
keyPrefix: supabaseAnonKey?.substring(0, 20) + '...',
13-
env: 'browser'
14-
});
15-
}
7+
// Always log, even during SSR
8+
console.log('=== SUPABASE INIT START ===');
9+
console.log('URL:', supabaseUrl);
10+
console.log('Key exists:', !!supabaseAnonKey);
11+
console.log('Environment:', typeof window !== 'undefined' ? 'browser' : 'server');
1612

1713
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
1814
auth: {
@@ -26,6 +22,9 @@ export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
2622
}
2723
});
2824

25+
console.log('Supabase client created:', !!supabase);
26+
console.log('=== SUPABASE INIT END ===');
27+
2928
// Add request interceptor for debugging only in browser
3029
if (typeof window !== 'undefined') {
3130
const originalFrom = supabase.from.bind(supabase);

0 commit comments

Comments
 (0)