Compare commits
10 Commits
40d9489395
...
production
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ede591c89e | ||
|
|
2defd7a4a9 | ||
|
|
9cc03bc475 | ||
|
|
832b468ea7 | ||
|
|
2a260abe0a | ||
|
|
80f2ac61ac | ||
|
|
a980ee8fcd | ||
|
|
ca2ed13446 | ||
|
|
20f0ccb85b | ||
|
|
59cc8ee154 |
@@ -38,7 +38,8 @@ export async function GET(request: NextRequest) {
|
|||||||
cls: ((p.performance as Record<string, unknown>)?.coreWebVitals as Record<string, unknown>)?.cls as number || 0
|
cls: ((p.performance as Record<string, unknown>)?.coreWebVitals as Record<string, unknown>)?.cls as number || 0
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const avgLighthouse = projectsWithPerformance.length > 0
|
// Calculate average lighthouse score (currently unused but kept for future use)
|
||||||
|
const _avgLighthouse = projectsWithPerformance.length > 0
|
||||||
? Math.round(projectsWithPerformance.reduce((sum, p) => sum + p.lighthouse, 0) / projectsWithPerformance.length)
|
? Math.round(projectsWithPerformance.reduce((sum, p) => sum + p.lighthouse, 0) / projectsWithPerformance.length)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
|
|||||||
@@ -126,29 +126,30 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
await prisma.project.update({
|
await prisma.project.update({
|
||||||
where: { id: projectIdNum },
|
where: { id: projectIdNum },
|
||||||
data: {
|
data: {
|
||||||
performance: {
|
performance: {
|
||||||
...perf,
|
...perf,
|
||||||
lighthouse: lighthouseScore,
|
lighthouse: lighthouseScore,
|
||||||
loadTime: performance.loadTime || perf.loadTime || 0,
|
loadTime: performance.loadTime || perf.loadTime || 0,
|
||||||
firstContentfulPaint: fcp || perf.firstContentfulPaint || 0,
|
firstContentfulPaint: fcp || perf.firstContentfulPaint || 0,
|
||||||
largestContentfulPaint: lcp || perf.largestContentfulPaint || 0,
|
largestContentfulPaint: lcp || perf.largestContentfulPaint || 0,
|
||||||
cumulativeLayoutShift: cls || perf.cumulativeLayoutShift || 0,
|
cumulativeLayoutShift: cls || perf.cumulativeLayoutShift || 0,
|
||||||
totalBlockingTime: performance.tbt || perf.totalBlockingTime || 0,
|
totalBlockingTime: performance.tbt || perf.totalBlockingTime || 0,
|
||||||
speedIndex: performance.si || perf.speedIndex || 0,
|
speedIndex: performance.si || perf.speedIndex || 0,
|
||||||
coreWebVitals: {
|
coreWebVitals: {
|
||||||
lcp: lcp || (perf.coreWebVitals as Record<string, unknown>)?.lcp || 0,
|
lcp: lcp || (perf.coreWebVitals as Record<string, unknown>)?.lcp || 0,
|
||||||
fid: fid || (perf.coreWebVitals as Record<string, unknown>)?.fid || 0,
|
fid: fid || (perf.coreWebVitals as Record<string, unknown>)?.fid || 0,
|
||||||
cls: cls || (perf.coreWebVitals as Record<string, unknown>)?.cls || 0
|
cls: cls || (perf.coreWebVitals as Record<string, unknown>)?.cls || 0
|
||||||
|
},
|
||||||
|
lastUpdated: new Date().toISOString()
|
||||||
},
|
},
|
||||||
lastUpdated: new Date().toISOString()
|
analytics: {
|
||||||
},
|
...analytics,
|
||||||
analytics: {
|
lastUpdated: new Date().toISOString()
|
||||||
...analytics,
|
}
|
||||||
lastUpdated: new Date().toISOString()
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,137 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { type NextRequest, NextResponse } from "next/server";
|
||||||
|
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
|
||||||
|
import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
// In a real app, you would check for admin session here
|
const { searchParams } = new URL(request.url);
|
||||||
// For now, we trust the 'x-admin-request' header if it's set by the server-side component or middleware
|
const filter = searchParams.get('filter') || 'all';
|
||||||
// but typically you'd verify the session cookie/token
|
const limit = parseInt(searchParams.get('limit') || '50');
|
||||||
|
const offset = parseInt(searchParams.get('offset') || '0');
|
||||||
|
|
||||||
const contacts = await prisma.contact.findMany({
|
let whereClause = {};
|
||||||
orderBy: {
|
|
||||||
createdAt: 'desc',
|
|
||||||
},
|
|
||||||
take: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
return NextResponse.json({ contacts });
|
switch (filter) {
|
||||||
} catch (error) {
|
case 'unread':
|
||||||
console.error('Error fetching contacts:', error);
|
whereClause = { responded: false };
|
||||||
return NextResponse.json(
|
break;
|
||||||
{ error: 'Failed to fetch contacts' },
|
case 'responded':
|
||||||
{ status: 500 }
|
whereClause = { responded: true };
|
||||||
);
|
break;
|
||||||
}
|
default:
|
||||||
|
whereClause = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const [contacts, total] = await Promise.all([
|
||||||
|
prisma.contact.findMany({
|
||||||
|
where: whereClause,
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: limit,
|
||||||
|
skip: offset,
|
||||||
|
}),
|
||||||
|
prisma.contact.count({ where: whereClause })
|
||||||
|
]);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
contacts,
|
||||||
|
total,
|
||||||
|
hasMore: offset + contacts.length < total
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
// Handle missing database table gracefully
|
||||||
|
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Contact table does not exist. Returning empty result.');
|
||||||
|
}
|
||||||
|
return NextResponse.json({
|
||||||
|
contacts: [],
|
||||||
|
total: 0,
|
||||||
|
hasMore: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error('Error fetching contacts:', error);
|
||||||
|
}
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Failed to fetch contacts' },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
try {
|
||||||
|
// Rate limiting for POST requests
|
||||||
|
const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
|
||||||
|
if (!checkRateLimit(ip, 5, 60000)) { // 5 requests per minute
|
||||||
|
return new NextResponse(
|
||||||
|
JSON.stringify({ error: 'Rate limit exceeded' }),
|
||||||
|
{
|
||||||
|
status: 429,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...getRateLimitHeaders(ip, 5, 60000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await request.json();
|
||||||
|
const { name, email, subject, message } = body;
|
||||||
|
|
||||||
|
// Validate required fields
|
||||||
|
if (!name || !email || !subject || !message) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'All fields are required' },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate email format
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Invalid email format' },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const contact = await prisma.contact.create({
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
subject,
|
||||||
|
message,
|
||||||
|
responded: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
message: 'Contact created successfully',
|
||||||
|
contact
|
||||||
|
}, { status: 201 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
// Handle missing database table gracefully
|
||||||
|
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Contact table does not exist.');
|
||||||
|
}
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Database table not found. Please run migrations.' },
|
||||||
|
{ status: 503 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error('Error creating contact:', error);
|
||||||
|
}
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Failed to create contact' },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
import { type NextRequest, NextResponse } from "next/server";
|
|
||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
|
|
||||||
import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
|
||||||
try {
|
|
||||||
const { searchParams } = new URL(request.url);
|
|
||||||
const filter = searchParams.get('filter') || 'all';
|
|
||||||
const limit = parseInt(searchParams.get('limit') || '50');
|
|
||||||
const offset = parseInt(searchParams.get('offset') || '0');
|
|
||||||
|
|
||||||
let whereClause = {};
|
|
||||||
|
|
||||||
switch (filter) {
|
|
||||||
case 'unread':
|
|
||||||
whereClause = { responded: false };
|
|
||||||
break;
|
|
||||||
case 'responded':
|
|
||||||
whereClause = { responded: true };
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
whereClause = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const [contacts, total] = await Promise.all([
|
|
||||||
prisma.contact.findMany({
|
|
||||||
where: whereClause,
|
|
||||||
orderBy: { createdAt: 'desc' },
|
|
||||||
take: limit,
|
|
||||||
skip: offset,
|
|
||||||
}),
|
|
||||||
prisma.contact.count({ where: whereClause })
|
|
||||||
]);
|
|
||||||
|
|
||||||
return NextResponse.json({
|
|
||||||
contacts,
|
|
||||||
total,
|
|
||||||
hasMore: offset + contacts.length < total
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
// Handle missing database table gracefully
|
|
||||||
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
console.warn('Contact table does not exist. Returning empty result.');
|
|
||||||
}
|
|
||||||
return NextResponse.json({
|
|
||||||
contacts: [],
|
|
||||||
total: 0,
|
|
||||||
hasMore: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
console.error('Error fetching contacts:', error);
|
|
||||||
}
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'Failed to fetch contacts' },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
|
||||||
try {
|
|
||||||
// Rate limiting for POST requests
|
|
||||||
const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
|
|
||||||
if (!checkRateLimit(ip, 5, 60000)) { // 5 requests per minute
|
|
||||||
return new NextResponse(
|
|
||||||
JSON.stringify({ error: 'Rate limit exceeded' }),
|
|
||||||
{
|
|
||||||
status: 429,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
...getRateLimitHeaders(ip, 5, 60000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await request.json();
|
|
||||||
const { name, email, subject, message } = body;
|
|
||||||
|
|
||||||
// Validate required fields
|
|
||||||
if (!name || !email || !subject || !message) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'All fields are required' },
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate email format
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(email)) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'Invalid email format' },
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const contact = await prisma.contact.create({
|
|
||||||
data: {
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
subject,
|
|
||||||
message,
|
|
||||||
responded: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return NextResponse.json({
|
|
||||||
message: 'Contact created successfully',
|
|
||||||
contact
|
|
||||||
}, { status: 201 });
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
// Handle missing database table gracefully
|
|
||||||
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
console.warn('Contact table does not exist.');
|
|
||||||
}
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'Database table not found. Please run migrations.' },
|
|
||||||
{ status: 503 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
console.error('Error creating contact:', error);
|
|
||||||
}
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'Failed to create contact' },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,61 +50,116 @@ interface StatusData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ActivityFeed() {
|
export default function ActivityFeed() {
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
const [data, setData] = useState<StatusData | null>(null);
|
const [data, setData] = useState<StatusData | null>(null);
|
||||||
const [isExpanded, setIsExpanded] = useState(true);
|
const [isExpanded, setIsExpanded] = useState(true);
|
||||||
const [isMinimized, setIsMinimized] = useState(false);
|
const [isMinimized, setIsMinimized] = useState(false);
|
||||||
const [hasActivity, setHasActivity] = useState(false);
|
const [hasActivity, setHasActivity] = useState(false);
|
||||||
const [isTrackingEnabled, setIsTrackingEnabled] = useState(() => {
|
// Initialize with default value to prevent hydration mismatch
|
||||||
// Check localStorage for tracking preference
|
const [isTrackingEnabled, setIsTrackingEnabled] = useState(true);
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
const stored = localStorage.getItem("activityTrackingEnabled");
|
|
||||||
return stored !== "false"; // Default to true if not set
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
const [quote, setQuote] = useState<{
|
const [quote, setQuote] = useState<{
|
||||||
content: string;
|
content: string;
|
||||||
author: string;
|
author: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
// Load tracking preference from localStorage after mount to prevent hydration mismatch
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem("activityTrackingEnabled");
|
||||||
|
setIsTrackingEnabled(stored !== "false"); // Default to true if not set
|
||||||
|
} catch (error) {
|
||||||
|
// localStorage might be disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Failed to read tracking preference:', error);
|
||||||
|
}
|
||||||
|
setIsTrackingEnabled(true); // Default to enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Fetch data every 30 seconds (optimized to match server cache)
|
// Fetch data every 30 seconds (optimized to match server cache)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Don't fetch if tracking is disabled
|
// Don't fetch if tracking is disabled or during SSR
|
||||||
if (!isTrackingEnabled) {
|
if (!isTrackingEnabled || typeof window === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
|
// Check if fetch is available (should be, but safety check)
|
||||||
|
if (typeof fetch === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add timestamp to prevent aggressive caching but respect server cache
|
// Add timestamp to prevent aggressive caching but respect server cache
|
||||||
const res = await fetch("/api/n8n/status", {
|
const res = await fetch("/api/n8n/status", {
|
||||||
cache: "default",
|
cache: "default",
|
||||||
|
}).catch((fetchError) => {
|
||||||
|
// Handle network errors gracefully
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('ActivityFeed: Fetch failed:', fetchError);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
if (!res.ok) return;
|
|
||||||
let json = await res.json();
|
|
||||||
|
|
||||||
console.log("ActivityFeed data (raw):", json);
|
if (!res || !res.ok) {
|
||||||
|
if (process.env.NODE_ENV === 'development' && res) {
|
||||||
|
console.warn('ActivityFeed: API returned non-OK status:', res.status);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let json: unknown;
|
||||||
|
try {
|
||||||
|
json = await res.json();
|
||||||
|
} catch (parseError) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('ActivityFeed: Failed to parse JSON response:', parseError);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.log("ActivityFeed data (raw):", json);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle array response if API returns it wrapped
|
// Handle array response if API returns it wrapped
|
||||||
if (Array.isArray(json)) {
|
if (Array.isArray(json)) {
|
||||||
json = json[0] || null;
|
json = json[0] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("ActivityFeed data (processed):", json);
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.log("ActivityFeed data (processed):", json);
|
||||||
|
}
|
||||||
|
|
||||||
setData(json);
|
if (!json || typeof json !== 'object') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type assertion - API should return StatusData format
|
||||||
|
const activityData = json as StatusData;
|
||||||
|
setData(activityData);
|
||||||
|
|
||||||
// Check if there's any active activity
|
// Check if there's any active activity
|
||||||
const hasActiveActivity =
|
const coding = activityData.coding;
|
||||||
json.coding?.isActive ||
|
const gaming = activityData.gaming;
|
||||||
json.gaming?.isPlaying ||
|
const music = activityData.music;
|
||||||
json.music?.isPlaying;
|
|
||||||
|
|
||||||
console.log("Has activity:", hasActiveActivity, {
|
const hasActiveActivity = Boolean(
|
||||||
coding: json.coding?.isActive,
|
coding?.isActive ||
|
||||||
gaming: json.gaming?.isPlaying,
|
gaming?.isPlaying ||
|
||||||
music: json.music?.isPlaying,
|
music?.isPlaying
|
||||||
});
|
);
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.log("Has activity:", hasActiveActivity, {
|
||||||
|
coding: coding?.isActive,
|
||||||
|
gaming: gaming?.isPlaying,
|
||||||
|
music: music?.isPlaying,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setHasActivity(hasActiveActivity);
|
setHasActivity(hasActiveActivity);
|
||||||
|
|
||||||
@@ -112,8 +167,12 @@ export default function ActivityFeed() {
|
|||||||
if (hasActiveActivity && !isMinimized) {
|
if (hasActiveActivity && !isMinimized) {
|
||||||
setIsExpanded(true);
|
setIsExpanded(true);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch activity", e);
|
// Silently fail - activity feed is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error("Failed to fetch activity:", error);
|
||||||
|
}
|
||||||
|
// Don't set error state - just fail silently
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1385,7 +1444,14 @@ export default function ActivityFeed() {
|
|||||||
const newValue = !isTrackingEnabled;
|
const newValue = !isTrackingEnabled;
|
||||||
setIsTrackingEnabled(newValue);
|
setIsTrackingEnabled(newValue);
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
localStorage.setItem("activityTrackingEnabled", String(newValue));
|
try {
|
||||||
|
localStorage.setItem("activityTrackingEnabled", String(newValue));
|
||||||
|
} catch (error) {
|
||||||
|
// localStorage might be full or disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Failed to save tracking preference:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Clear data when disabling
|
// Clear data when disabling
|
||||||
if (!newValue) {
|
if (!newValue) {
|
||||||
@@ -1394,6 +1460,9 @@ export default function ActivityFeed() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Don't render until mounted to prevent hydration mismatch
|
||||||
|
if (!mounted) return null;
|
||||||
|
|
||||||
// Don't render if tracking is disabled and no data
|
// Don't render if tracking is disabled and no data
|
||||||
if (!isTrackingEnabled && !data) return null;
|
if (!isTrackingEnabled && !data) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,47 @@ interface Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ChatWidget() {
|
export default function ChatWidget() {
|
||||||
|
// Prevent hydration mismatch by only rendering after mount
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [messages, setMessages] = useState<Message[]>([]);
|
const [messages, setMessages] = useState<Message[]>([]);
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [conversationId, setConversationId] = useState(() => {
|
const [conversationId, setConversationId] = useState<string>("default");
|
||||||
// Generate or retrieve conversation ID
|
|
||||||
if (typeof window !== "undefined") {
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
// Generate or retrieve conversation ID only on client
|
||||||
|
try {
|
||||||
const stored = localStorage.getItem("chatSessionId");
|
const stored = localStorage.getItem("chatSessionId");
|
||||||
if (stored) return stored;
|
if (stored) {
|
||||||
const newId = crypto.randomUUID();
|
setConversationId(stored);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate UUID with fallback for browsers without crypto.randomUUID
|
||||||
|
let newId: string;
|
||||||
|
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
||||||
|
newId = crypto.randomUUID();
|
||||||
|
} else {
|
||||||
|
// Fallback UUID generation
|
||||||
|
newId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
|
const r = Math.random() * 16 | 0;
|
||||||
|
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
localStorage.setItem("chatSessionId", newId);
|
localStorage.setItem("chatSessionId", newId);
|
||||||
return newId;
|
setConversationId(newId);
|
||||||
|
} catch (error) {
|
||||||
|
// localStorage might be disabled or full
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Failed to access localStorage for chat session:', error);
|
||||||
|
}
|
||||||
|
setConversationId(`session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
|
||||||
}
|
}
|
||||||
return "default";
|
}, []);
|
||||||
});
|
|
||||||
|
|
||||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -62,22 +88,55 @@ export default function ChatWidget() {
|
|||||||
// Load messages from localStorage
|
// Load messages from localStorage
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
const stored = localStorage.getItem("chatMessages");
|
try {
|
||||||
if (stored) {
|
const stored = localStorage.getItem("chatMessages");
|
||||||
try {
|
if (stored) {
|
||||||
const parsed = JSON.parse(stored);
|
try {
|
||||||
setMessages(
|
const parsed = JSON.parse(stored);
|
||||||
parsed.map((m: Message) => ({
|
setMessages(
|
||||||
...m,
|
parsed.map((m: Message) => ({
|
||||||
text: decodeHtmlEntities(m.text), // Decode HTML entities when loading
|
...m,
|
||||||
timestamp: new Date(m.timestamp),
|
text: decodeHtmlEntities(m.text), // Decode HTML entities when loading
|
||||||
})),
|
timestamp: new Date(m.timestamp),
|
||||||
);
|
})),
|
||||||
} catch (e) {
|
);
|
||||||
console.error("Failed to load chat history", e);
|
} catch (e) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error("Failed to parse chat history", e);
|
||||||
|
}
|
||||||
|
// Clear corrupted data
|
||||||
|
try {
|
||||||
|
localStorage.removeItem("chatMessages");
|
||||||
|
} catch {
|
||||||
|
// Ignore cleanup errors
|
||||||
|
}
|
||||||
|
// Add welcome message
|
||||||
|
setMessages([
|
||||||
|
{
|
||||||
|
id: "welcome",
|
||||||
|
text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀",
|
||||||
|
sender: "bot",
|
||||||
|
timestamp: new Date(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add welcome message
|
||||||
|
setMessages([
|
||||||
|
{
|
||||||
|
id: "welcome",
|
||||||
|
text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀",
|
||||||
|
sender: "bot",
|
||||||
|
timestamp: new Date(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
} catch (error) {
|
||||||
// Add welcome message
|
// localStorage might be disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn("Failed to load chat history from localStorage:", error);
|
||||||
|
}
|
||||||
|
// Add welcome message anyway
|
||||||
setMessages([
|
setMessages([
|
||||||
{
|
{
|
||||||
id: "welcome",
|
id: "welcome",
|
||||||
@@ -93,7 +152,14 @@ export default function ChatWidget() {
|
|||||||
// Save messages to localStorage
|
// Save messages to localStorage
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== "undefined" && messages.length > 0) {
|
if (typeof window !== "undefined" && messages.length > 0) {
|
||||||
localStorage.setItem("chatMessages", JSON.stringify(messages));
|
try {
|
||||||
|
localStorage.setItem("chatMessages", JSON.stringify(messages));
|
||||||
|
} catch (error) {
|
||||||
|
// localStorage might be full or disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn("Failed to save chat messages to localStorage:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
@@ -204,6 +270,11 @@ export default function ChatWidget() {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Don't render until mounted to prevent hydration mismatch
|
||||||
|
if (!mounted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Chat Button */}
|
{/* Chat Button */}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState, Suspense, lazy } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
import { ToastProvider } from "@/components/Toast";
|
import { ToastProvider } from "@/components/Toast";
|
||||||
|
import ErrorBoundary from "@/components/ErrorBoundary";
|
||||||
import { AnalyticsProvider } from "@/components/AnalyticsProvider";
|
import { AnalyticsProvider } from "@/components/AnalyticsProvider";
|
||||||
|
|
||||||
// Lazy load heavy components to avoid webpack issues
|
// Dynamic import with SSR disabled to avoid framer-motion issues
|
||||||
const BackgroundBlobs = lazy(() => import("@/components/BackgroundBlobs"));
|
const BackgroundBlobs = dynamic(() => import("@/components/BackgroundBlobs").catch(() => ({ default: () => null })), {
|
||||||
const ChatWidget = lazy(() => import("./ChatWidget"));
|
ssr: false,
|
||||||
|
loading: () => null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const ChatWidget = dynamic(() => import("./ChatWidget").catch(() => ({ default: () => null })), {
|
||||||
|
ssr: false,
|
||||||
|
loading: () => null,
|
||||||
|
});
|
||||||
|
|
||||||
export default function ClientProviders({
|
export default function ClientProviders({
|
||||||
children,
|
children,
|
||||||
@@ -16,37 +25,61 @@ export default function ClientProviders({
|
|||||||
}) {
|
}) {
|
||||||
const [mounted, setMounted] = useState(false);
|
const [mounted, setMounted] = useState(false);
|
||||||
const [is404Page, setIs404Page] = useState(false);
|
const [is404Page, setIs404Page] = useState(false);
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMounted(true);
|
setMounted(true);
|
||||||
// Check if we're on a 404 page by looking for the data attribute
|
// Check if we're on a 404 page by looking for the data attribute or pathname
|
||||||
const check404 = () => {
|
const check404 = () => {
|
||||||
if (typeof window !== "undefined") {
|
try {
|
||||||
const has404Component = document.querySelector('[data-404-page]');
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
||||||
setIs404Page(!!has404Component);
|
const has404Component = document.querySelector('[data-404-page]');
|
||||||
|
const is404Path = pathname === '/404' || (window.location && (window.location.pathname === '/404' || window.location.pathname.includes('404')));
|
||||||
|
setIs404Page(!!has404Component || is404Path);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - 404 detection is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error checking 404 status:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Check immediately and after a short delay
|
// Check immediately and after a short delay
|
||||||
check404();
|
try {
|
||||||
const timeout = setTimeout(check404, 100);
|
check404();
|
||||||
return () => clearTimeout(timeout);
|
const timeout = setTimeout(check404, 100);
|
||||||
}, []);
|
const interval = setInterval(check404, 500);
|
||||||
|
return () => {
|
||||||
|
try {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
clearInterval(interval);
|
||||||
|
} catch {
|
||||||
|
// Silently fail during cleanup
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// If setup fails, just return empty cleanup
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error setting up 404 check:', error);
|
||||||
|
}
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
// Wrap in multiple error boundaries to isolate failures
|
||||||
return (
|
return (
|
||||||
<AnalyticsProvider>
|
<ErrorBoundary>
|
||||||
<ToastProvider>
|
<ErrorBoundary>
|
||||||
{mounted && (
|
<AnalyticsProvider>
|
||||||
<Suspense fallback={null}>
|
<ErrorBoundary>
|
||||||
<BackgroundBlobs />
|
<ToastProvider>
|
||||||
</Suspense>
|
{mounted && <BackgroundBlobs />}
|
||||||
)}
|
<div className="relative z-10">{children}</div>
|
||||||
<div className="relative z-10">{children}</div>
|
{mounted && !is404Page && <ChatWidget />}
|
||||||
{mounted && !is404Page && (
|
</ToastProvider>
|
||||||
<Suspense fallback={null}>
|
</ErrorBoundary>
|
||||||
<ChatWidget />
|
</AnalyticsProvider>
|
||||||
</Suspense>
|
</ErrorBoundary>
|
||||||
)}
|
</ErrorBoundary>
|
||||||
</ToastProvider>
|
|
||||||
</AnalyticsProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export default function KernelPanic404() {
|
|||||||
const inputContainerRef = useRef<HTMLDivElement>(null);
|
const inputContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const overlayRef = useRef<HTMLDivElement>(null);
|
const overlayRef = useRef<HTMLDivElement>(null);
|
||||||
const bodyRef = useRef<HTMLDivElement>(null); // We'll use a wrapper div instead of document.body for some effects if possible, but strict effects might need body.
|
const bodyRef = useRef<HTMLDivElement>(null); // We'll use a wrapper div instead of document.body for some effects if possible, but strict effects might need body.
|
||||||
|
const bootStartedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
/* --- SYSTEM CORE --- */
|
/* --- SYSTEM CORE --- */
|
||||||
@@ -21,20 +22,24 @@ export default function KernelPanic404() {
|
|||||||
|
|
||||||
if (!output || !input || !inputContainer || !overlay) return;
|
if (!output || !input || !inputContainer || !overlay) return;
|
||||||
|
|
||||||
|
// Prevent double initialization - check if boot already started or output has content
|
||||||
|
if (bootStartedRef.current || output.children.length > 0) return;
|
||||||
|
bootStartedRef.current = true;
|
||||||
|
|
||||||
let audioCtx: AudioContext | null = null;
|
let audioCtx: AudioContext | null = null;
|
||||||
let systemFrozen = false;
|
let systemFrozen = false;
|
||||||
let currentMusic: any = null;
|
let currentMusic: { stop: () => void } | null = null;
|
||||||
let hawkinsActive = false;
|
let hawkinsActive = false;
|
||||||
let fsocietyActive = false;
|
let fsocietyActive = false;
|
||||||
|
|
||||||
// Timers storage to clear on unmount
|
// Timers storage to clear on unmount
|
||||||
const timers: (NodeJS.Timeout | number)[] = [];
|
const timers: (NodeJS.Timeout | number)[] = [];
|
||||||
const interval = (fn: Function, ms: number) => {
|
const interval = (fn: () => void, ms: number) => {
|
||||||
const id = setInterval(fn, ms);
|
const id = setInterval(fn, ms);
|
||||||
timers.push(id);
|
timers.push(id);
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
const timeout = (fn: Function, ms: number) => {
|
const timeout = (fn: () => void, ms: number) => {
|
||||||
const id = setTimeout(fn, ms);
|
const id = setTimeout(fn, ms);
|
||||||
timers.push(id);
|
timers.push(id);
|
||||||
return id;
|
return id;
|
||||||
@@ -44,7 +49,7 @@ export default function KernelPanic404() {
|
|||||||
function initAudio() {
|
function initAudio() {
|
||||||
if (!audioCtx) {
|
if (!audioCtx) {
|
||||||
const AudioContextClass =
|
const AudioContextClass =
|
||||||
window.AudioContext || (window as any).webkitAudioContext;
|
window.AudioContext || (window as typeof window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
|
||||||
if (AudioContextClass) {
|
if (AudioContextClass) {
|
||||||
audioCtx = new AudioContextClass();
|
audioCtx = new AudioContextClass();
|
||||||
}
|
}
|
||||||
@@ -439,6 +444,7 @@ export default function KernelPanic404() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --- FILE SYSTEM --- */
|
/* --- FILE SYSTEM --- */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const fileSystem: any = {
|
const fileSystem: any = {
|
||||||
home: {
|
home: {
|
||||||
type: "dir",
|
type: "dir",
|
||||||
@@ -546,7 +552,7 @@ export default function KernelPanic404() {
|
|||||||
|
|
||||||
let currentPath = fileSystem.home.children.guest;
|
let currentPath = fileSystem.home.children.guest;
|
||||||
let pathStr = "~";
|
let pathStr = "~";
|
||||||
let commandHistory: string[] = [];
|
const commandHistory: string[] = [];
|
||||||
let historyIndex = -1;
|
let historyIndex = -1;
|
||||||
|
|
||||||
/* --- UTILS --- */
|
/* --- UTILS --- */
|
||||||
@@ -554,12 +560,19 @@ export default function KernelPanic404() {
|
|||||||
if (!output) return;
|
if (!output) return;
|
||||||
const d = document.createElement("div");
|
const d = document.createElement("div");
|
||||||
d.innerHTML = text;
|
d.innerHTML = text;
|
||||||
if (type === "log-warn") d.style.color = "#ffb000";
|
// Default color for normal text - use setProperty with important to override globals.css
|
||||||
|
if (!type || (type !== "log-warn" && type !== "log-err" && type !== "alert" && type !== "log-sys" && type !== "log-k" && type !== "log-dim")) {
|
||||||
|
d.style.setProperty("color", "var(--phosphor)", "important");
|
||||||
|
}
|
||||||
|
if (type === "log-warn") d.style.setProperty("color", "#ffb000", "important");
|
||||||
if (type === "log-err" || type === "alert")
|
if (type === "log-err" || type === "alert")
|
||||||
d.style.color = "var(--alert)";
|
d.style.setProperty("color", "var(--alert)", "important");
|
||||||
if (type === "log-dim") d.style.opacity = "0.6";
|
if (type === "log-dim") {
|
||||||
if (type === "log-sys") d.style.color = "cyan";
|
d.style.opacity = "0.6";
|
||||||
if (type === "log-k") d.style.color = "#fff";
|
d.style.setProperty("color", "var(--phosphor)", "important");
|
||||||
|
}
|
||||||
|
if (type === "log-sys") d.style.setProperty("color", "cyan", "important");
|
||||||
|
if (type === "log-k") d.style.setProperty("color", "#fff", "important");
|
||||||
if (type === "pulse-red") d.classList.add("pulse-red");
|
if (type === "pulse-red") d.classList.add("pulse-red");
|
||||||
if (type === "fsociety-mask") d.classList.add("fsociety-mask");
|
if (type === "fsociety-mask") d.classList.add("fsociety-mask");
|
||||||
if (type === "memory-error") d.classList.add("memory-error");
|
if (type === "memory-error") d.classList.add("memory-error");
|
||||||
@@ -659,7 +672,7 @@ export default function KernelPanic404() {
|
|||||||
// Clear initial output
|
// Clear initial output
|
||||||
output!.innerHTML = "";
|
output!.innerHTML = "";
|
||||||
|
|
||||||
for (let msg of bootMessages) {
|
for (const msg of bootMessages) {
|
||||||
printLine(msg.t, msg.type);
|
printLine(msg.t, msg.type);
|
||||||
await sleep(msg.d);
|
await sleep(msg.d);
|
||||||
}
|
}
|
||||||
@@ -782,7 +795,7 @@ export default function KernelPanic404() {
|
|||||||
if (suggestions.length === 0) {
|
if (suggestions.length === 0) {
|
||||||
try {
|
try {
|
||||||
playSynth("beep");
|
playSynth("beep");
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -805,13 +818,13 @@ export default function KernelPanic404() {
|
|||||||
input.setSelectionRange(input.value.length, input.value.length);
|
input.setSelectionRange(input.value.length, input.value.length);
|
||||||
try {
|
try {
|
||||||
playSynth("beep");
|
playSynth("beep");
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
} else {
|
} else {
|
||||||
// Multiple matches
|
// Multiple matches
|
||||||
printLine(`Possible completions: ${suggestions.join(" ")}`, "log-dim");
|
printLine(`Possible completions: ${suggestions.join(" ")}`, "log-dim");
|
||||||
try {
|
try {
|
||||||
playSynth("beep");
|
playSynth("beep");
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -820,7 +833,7 @@ export default function KernelPanic404() {
|
|||||||
if (systemFrozen || !input) {
|
if (systemFrozen || !input) {
|
||||||
try {
|
try {
|
||||||
playSynth("beep");
|
playSynth("beep");
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -859,7 +872,7 @@ export default function KernelPanic404() {
|
|||||||
args.includes("-a") || args.includes("-la") || args.includes("-l");
|
args.includes("-a") || args.includes("-la") || args.includes("-l");
|
||||||
const longFormat = args.includes("-l") || args.includes("-la");
|
const longFormat = args.includes("-l") || args.includes("-la");
|
||||||
|
|
||||||
let items = Object.keys(currentPath.children).filter(
|
const items = Object.keys(currentPath.children).filter(
|
||||||
(n) => !n.startsWith(".") || showHidden,
|
(n) => !n.startsWith(".") || showHidden,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1165,7 +1178,7 @@ export default function KernelPanic404() {
|
|||||||
overlay.style.display = "none";
|
overlay.style.display = "none";
|
||||||
overlay.innerHTML = "";
|
overlay.innerHTML = "";
|
||||||
|
|
||||||
const sporeInterval = interval(() => {
|
const _sporeInterval = interval(() => {
|
||||||
const spore = document.createElement("div");
|
const spore = document.createElement("div");
|
||||||
spore.className = "spore";
|
spore.className = "spore";
|
||||||
spore.style.left = Math.random() * 100 + "%";
|
spore.style.left = Math.random() * 100 + "%";
|
||||||
@@ -1175,7 +1188,7 @@ export default function KernelPanic404() {
|
|||||||
setTimeout(() => spore.remove(), 3000);
|
setTimeout(() => spore.remove(), 3000);
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
const glitchInterval = interval(() => {
|
const _glitchInterval = interval(() => {
|
||||||
if (!hawkinsActive) return;
|
if (!hawkinsActive) return;
|
||||||
body.style.filter = "hue-rotate(180deg) contrast(1.3) brightness(0.9)";
|
body.style.filter = "hue-rotate(180deg) contrast(1.3) brightness(0.9)";
|
||||||
setTimeout(
|
setTimeout(
|
||||||
@@ -1400,7 +1413,7 @@ export default function KernelPanic404() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
playSynth("key");
|
playSynth("key");
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
|
|
||||||
if (e.key === "ArrowUp" && historyIndex > 0) {
|
if (e.key === "ArrowUp" && historyIndex > 0) {
|
||||||
historyIndex--;
|
historyIndex--;
|
||||||
@@ -1442,18 +1455,40 @@ export default function KernelPanic404() {
|
|||||||
--phosphor: #33ff00;
|
--phosphor: #33ff00;
|
||||||
--phosphor-sec: #008f11;
|
--phosphor-sec: #008f11;
|
||||||
--alert: #ff3333;
|
--alert: #ff3333;
|
||||||
--font: "Courier New", Courier, monospace;
|
--font: 'Courier New', Courier, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: var(--bg-color);
|
||||||
|
margin: 0;
|
||||||
|
height: 100vh;
|
||||||
|
overflow: hidden;
|
||||||
|
font-family: var(--font);
|
||||||
|
color: var(--phosphor);
|
||||||
|
user-select: none;
|
||||||
|
cursor: default;
|
||||||
|
transition: filter 0.5s, transform 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- CRT EFFECTS --- */
|
/* --- CRT EFFECTS --- */
|
||||||
.crt-wrap {
|
.crt-wrap {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
padding: 30px;
|
padding: 30px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: radial-gradient(circle at center, #111 0%, #000 100%);
|
background: radial-gradient(circle at center, #111 0%, #000 100%);
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
}
|
||||||
|
|
||||||
|
/* Override globals.css div color rule for 404 page - must be very specific */
|
||||||
|
html body:has([data-404-page]) .crt-wrap,
|
||||||
|
html body:has([data-404-page]) .crt-wrap *,
|
||||||
|
html body:has([data-404-page]) #output,
|
||||||
|
html body:has([data-404-page]) #output div,
|
||||||
|
html body:has([data-404-page]) #output * {
|
||||||
|
color: var(--phosphor) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.crt-wrap::before {
|
.crt-wrap::before {
|
||||||
@@ -1463,25 +1498,22 @@ export default function KernelPanic404() {
|
|||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background:
|
background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
|
||||||
linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
|
linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
|
||||||
linear-gradient(
|
background-size: 100% 4px, 3px 100%;
|
||||||
90deg,
|
|
||||||
rgba(255, 0, 0, 0.06),
|
|
||||||
rgba(0, 255, 0, 0.02),
|
|
||||||
rgba(0, 0, 255, 0.06)
|
|
||||||
);
|
|
||||||
background-size:
|
|
||||||
100% 4px,
|
|
||||||
3px 100%;
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 90;
|
z-index: 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
.glow {
|
.glow {
|
||||||
text-shadow:
|
text-shadow: 0 0 2px var(--phosphor-sec), 0 0 8px var(--phosphor);
|
||||||
0 0 2px var(--phosphor-sec),
|
}
|
||||||
0 0 8px var(--phosphor);
|
|
||||||
|
/* Hide chat widget on 404 page */
|
||||||
|
body:has([data-404-page]) [data-chat-widget] {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
opacity: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- TERMINAL --- */
|
/* --- TERMINAL --- */
|
||||||
@@ -1502,7 +1534,6 @@ export default function KernelPanic404() {
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
color: var(--phosphor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#output::-webkit-scrollbar {
|
#output::-webkit-scrollbar {
|
||||||
@@ -1522,7 +1553,6 @@ export default function KernelPanic404() {
|
|||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
color: var(--phosphor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#cmd-input {
|
#cmd-input {
|
||||||
@@ -1847,7 +1877,7 @@ export default function KernelPanic404() {
|
|||||||
|
|
||||||
<div id="flash-overlay" ref={overlayRef}></div>
|
<div id="flash-overlay" ref={overlayRef}></div>
|
||||||
|
|
||||||
<div className="crt-wrap glow" ref={bodyRef}>
|
<div className="crt-wrap glow" ref={bodyRef} data-404-page="true">
|
||||||
<div id="terminal">
|
<div id="terminal">
|
||||||
<div id="output" ref={outputRef}></div>
|
<div id="output" ref={outputRef}></div>
|
||||||
<div
|
<div
|
||||||
|
|||||||
41
app/components/KernelPanic404Wrapper.tsx
Normal file
41
app/components/KernelPanic404Wrapper.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export default function KernelPanic404Wrapper() {
|
||||||
|
useEffect(() => {
|
||||||
|
// Ensure body and html don't interfere
|
||||||
|
document.body.style.background = "#020202";
|
||||||
|
document.body.style.color = "#33ff00";
|
||||||
|
document.documentElement.style.background = "#020202";
|
||||||
|
document.documentElement.style.color = "#33ff00";
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Cleanup
|
||||||
|
document.body.style.background = "";
|
||||||
|
document.body.style.color = "";
|
||||||
|
document.documentElement.style.background = "";
|
||||||
|
document.documentElement.style.color = "";
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<iframe
|
||||||
|
src="/404-terminal.html"
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: "100vw",
|
||||||
|
height: "100vh",
|
||||||
|
border: "none",
|
||||||
|
zIndex: 9999,
|
||||||
|
margin: 0,
|
||||||
|
padding: 0,
|
||||||
|
backgroundColor: "#020202",
|
||||||
|
}}
|
||||||
|
data-404-page="true"
|
||||||
|
allowTransparency={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { motion, Variants } from "framer-motion";
|
import { motion, Variants } from "framer-motion";
|
||||||
import { ExternalLink, Github, Layers, ArrowRight, ArrowLeft, Calendar } from "lucide-react";
|
import { ExternalLink, Github, ArrowRight, Calendar } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ function EditorPageContent() {
|
|||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
const [isCreating, setIsCreating] = useState(!projectId);
|
const [isCreating, setIsCreating] = useState(!projectId);
|
||||||
const [showPreview, setShowPreview] = useState(false);
|
const [showPreview, setShowPreview] = useState(false);
|
||||||
const [isTyping, setIsTyping] = useState(false);
|
const [_isTyping, setIsTyping] = useState(false);
|
||||||
const [history, setHistory] = useState<typeof formData[]>([]);
|
const [history, setHistory] = useState<typeof formData[]>([]);
|
||||||
const [historyIndex, setHistoryIndex] = useState(-1);
|
const [historyIndex, setHistoryIndex] = useState(-1);
|
||||||
const [originalFormData, setOriginalFormData] = useState<typeof formData | null>(null);
|
const [originalFormData, setOriginalFormData] = useState<typeof formData | null>(null);
|
||||||
|
|||||||
@@ -57,25 +57,42 @@ const AdminPage = () => {
|
|||||||
|
|
||||||
// Check if user is locked out
|
// Check if user is locked out
|
||||||
const checkLockout = useCallback(() => {
|
const checkLockout = useCallback(() => {
|
||||||
const lockoutData = localStorage.getItem('admin_lockout');
|
if (typeof window === 'undefined') return false;
|
||||||
if (lockoutData) {
|
|
||||||
try {
|
|
||||||
const { timestamp, attempts } = JSON.parse(lockoutData);
|
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
if (now - timestamp < LOCKOUT_DURATION) {
|
try {
|
||||||
setAuthState(prev => ({
|
const lockoutData = localStorage.getItem('admin_lockout');
|
||||||
...prev,
|
if (lockoutData) {
|
||||||
isLocked: true,
|
try {
|
||||||
attempts,
|
const { timestamp, attempts } = JSON.parse(lockoutData);
|
||||||
isLoading: false
|
const now = Date.now();
|
||||||
}));
|
|
||||||
return true;
|
if (now - timestamp < LOCKOUT_DURATION) {
|
||||||
} else {
|
setAuthState(prev => ({
|
||||||
localStorage.removeItem('admin_lockout');
|
...prev,
|
||||||
|
isLocked: true,
|
||||||
|
attempts,
|
||||||
|
isLoading: false
|
||||||
|
}));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem('admin_lockout');
|
||||||
|
} catch {
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem('admin_lockout');
|
||||||
|
} catch {
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
localStorage.removeItem('admin_lockout');
|
} catch (error) {
|
||||||
|
// localStorage might be disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Failed to check lockout status:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -197,7 +214,11 @@ const AdminPage = () => {
|
|||||||
attempts: 0,
|
attempts: 0,
|
||||||
isLoading: false
|
isLoading: false
|
||||||
}));
|
}));
|
||||||
localStorage.removeItem('admin_lockout');
|
try {
|
||||||
|
localStorage.removeItem('admin_lockout');
|
||||||
|
} catch {
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const newAttempts = authState.attempts + 1;
|
const newAttempts = authState.attempts + 1;
|
||||||
setAuthState(prev => ({
|
setAuthState(prev => ({
|
||||||
@@ -208,10 +229,17 @@ const AdminPage = () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
if (newAttempts >= 5) {
|
if (newAttempts >= 5) {
|
||||||
localStorage.setItem('admin_lockout', JSON.stringify({
|
try {
|
||||||
timestamp: Date.now(),
|
localStorage.setItem('admin_lockout', JSON.stringify({
|
||||||
attempts: newAttempts
|
timestamp: Date.now(),
|
||||||
}));
|
attempts: newAttempts
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
// localStorage might be full or disabled
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Failed to save lockout data:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
setAuthState(prev => ({
|
setAuthState(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
isLocked: true,
|
isLocked: true,
|
||||||
@@ -252,7 +280,11 @@ const AdminPage = () => {
|
|||||||
<p className="text-stone-500">Too many failed attempts. Please try again in 15 minutes.</p>
|
<p className="text-stone-500">Too many failed attempts. Please try again in 15 minutes.</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
localStorage.removeItem('admin_lockout');
|
try {
|
||||||
|
localStorage.removeItem('admin_lockout');
|
||||||
|
} catch {
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
className="mt-4 px-6 py-2 bg-stone-900 text-stone-50 rounded-xl hover:bg-stone-800 transition-colors"
|
className="mt-4 px-6 py-2 bg-stone-900 text-stone-50 rounded-xl hover:bg-stone-800 transition-colors"
|
||||||
|
|||||||
@@ -1,30 +1,80 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Suspense } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
// Dynamically import KernelPanic404 to avoid SSR issues
|
// Dynamically import KernelPanic404Wrapper to avoid SSR issues
|
||||||
const KernelPanic404 = dynamic(() => import("./components/KernelPanic404"), {
|
const KernelPanic404 = dynamic(() => import("./components/KernelPanic404Wrapper"), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
loading: () => (
|
loading: () => (
|
||||||
<div className="flex items-center justify-center min-h-screen bg-black text-[#33ff00] font-mono">
|
<div style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
backgroundColor: "#020202",
|
||||||
|
color: "#33ff00",
|
||||||
|
fontFamily: "monospace"
|
||||||
|
}}>
|
||||||
<div>Loading terminal...</div>
|
<div>Loading terminal...</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function NotFound() {
|
export default function NotFound() {
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: "100vw",
|
||||||
|
height: "100vh",
|
||||||
|
margin: 0,
|
||||||
|
padding: 0,
|
||||||
|
overflow: "hidden",
|
||||||
|
backgroundColor: "#020202",
|
||||||
|
zIndex: 9998
|
||||||
|
}}>
|
||||||
|
<div style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
color: "#33ff00",
|
||||||
|
fontFamily: "monospace"
|
||||||
|
}}>
|
||||||
|
Loading terminal...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen w-full bg-black overflow-hidden relative">
|
<div style={{
|
||||||
<Suspense
|
position: "fixed",
|
||||||
fallback={
|
top: 0,
|
||||||
<div className="flex items-center justify-center min-h-screen bg-black text-[#33ff00] font-mono">
|
left: 0,
|
||||||
<div>Loading terminal...</div>
|
width: "100vw",
|
||||||
</div>
|
height: "100vh",
|
||||||
}
|
margin: 0,
|
||||||
>
|
padding: 0,
|
||||||
<KernelPanic404 />
|
overflow: "hidden",
|
||||||
</Suspense>
|
backgroundColor: "#020202",
|
||||||
</main>
|
zIndex: 9998
|
||||||
|
}}>
|
||||||
|
<KernelPanic404 />
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import Projects from "./components/Projects";
|
|||||||
import Contact from "./components/Contact";
|
import Contact from "./components/Contact";
|
||||||
import Footer from "./components/Footer";
|
import Footer from "./components/Footer";
|
||||||
import Script from "next/script";
|
import Script from "next/script";
|
||||||
import ActivityFeed from "./components/ActivityFeed";
|
import ErrorBoundary from "@/components/ErrorBoundary";
|
||||||
|
import ActivityFeed from "./components/ActivityFeed";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
@@ -35,7 +36,9 @@ export default function Home() {
|
|||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ActivityFeed />
|
<ErrorBoundary>
|
||||||
|
<ActivityFeed />
|
||||||
|
</ErrorBoundary>
|
||||||
<Header />
|
<Header />
|
||||||
{/* Spacer to prevent navbar overlap */}
|
{/* Spacer to prevent navbar overlap */}
|
||||||
<div className="h-24 md:h-32" aria-hidden="true"></div>
|
<div className="h-24 md:h-32" aria-hidden="true"></div>
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { ExternalLink, Calendar, Tag, ArrowLeft, Github as GithubIcon, Share2 } from 'lucide-react';
|
import { ExternalLink, Calendar, ArrowLeft, Github as GithubIcon, Share2 } from 'lucide-react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useParams } from 'next/navigation';
|
import { useParams } from 'next/navigation';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import Image from 'next/image';
|
|
||||||
|
|
||||||
interface Project {
|
interface Project {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import { useState, useEffect, useCallback } from 'react';
|
|||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import {
|
import {
|
||||||
BarChart3,
|
BarChart3,
|
||||||
TrendingUp,
|
|
||||||
Eye,
|
Eye,
|
||||||
Heart,
|
|
||||||
Zap,
|
Zap,
|
||||||
Globe,
|
Globe,
|
||||||
Activity,
|
Activity,
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ interface AnalyticsProviderProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }) => {
|
export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }) => {
|
||||||
// Initialize Web Vitals tracking
|
// Initialize Web Vitals tracking - wrapped to prevent crashes
|
||||||
|
// Hooks must be called unconditionally, but the hook itself handles errors
|
||||||
useWebVitals();
|
useWebVitals();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|
||||||
|
// Wrap entire effect in try-catch to prevent any errors from breaking the app
|
||||||
|
try {
|
||||||
|
|
||||||
// Track page view
|
// Track page view
|
||||||
const trackPageView = async () => {
|
const trackPageView = async () => {
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
@@ -49,8 +53,15 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track page load performance
|
// Track page load performance - wrapped in try-catch
|
||||||
trackPageLoad();
|
try {
|
||||||
|
trackPageLoad();
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking page load:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Track initial page view
|
// Track initial page view
|
||||||
trackPageView();
|
trackPageView();
|
||||||
@@ -65,36 +76,43 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
|||||||
|
|
||||||
// Wait for page to fully load
|
// Wait for page to fully load
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;
|
try {
|
||||||
const paintEntries = performance.getEntriesByType('paint');
|
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming | undefined;
|
||||||
const lcpEntries = performance.getEntriesByType('largest-contentful-paint');
|
const paintEntries = performance.getEntriesByType('paint');
|
||||||
|
const lcpEntries = performance.getEntriesByType('largest-contentful-paint');
|
||||||
|
|
||||||
const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint');
|
const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint');
|
||||||
const lcp = lcpEntries[lcpEntries.length - 1];
|
const lcp = lcpEntries.length > 0 ? lcpEntries[lcpEntries.length - 1] : undefined;
|
||||||
|
|
||||||
const performanceData = {
|
const performanceData = {
|
||||||
loadTime: navigation ? navigation.loadEventEnd - navigation.fetchStart : 0,
|
loadTime: navigation && navigation.loadEventEnd && navigation.fetchStart ? navigation.loadEventEnd - navigation.fetchStart : 0,
|
||||||
fcp: fcp ? fcp.startTime : 0,
|
fcp: fcp ? fcp.startTime : 0,
|
||||||
lcp: lcp ? lcp.startTime : 0,
|
lcp: lcp ? lcp.startTime : 0,
|
||||||
ttfb: navigation ? navigation.responseStart - navigation.fetchStart : 0,
|
ttfb: navigation && navigation.responseStart && navigation.fetchStart ? navigation.responseStart - navigation.fetchStart : 0,
|
||||||
cls: 0, // Will be updated by CLS observer
|
cls: 0, // Will be updated by CLS observer
|
||||||
fid: 0, // Will be updated by FID observer
|
fid: 0, // Will be updated by FID observer
|
||||||
si: 0 // Speed Index - would need to calculate
|
si: 0 // Speed Index - would need to calculate
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send performance data
|
// Send performance data
|
||||||
await fetch('/api/analytics/track', {
|
await fetch('/api/analytics/track', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
type: 'performance',
|
type: 'performance',
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
page: path,
|
page: path,
|
||||||
performance: performanceData
|
performance: performanceData
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - performance tracking is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error collecting performance data:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 2000); // Wait 2 seconds for page to stabilize
|
}, 2000); // Wait 2 seconds for page to stabilize
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Silently fail
|
// Silently fail
|
||||||
@@ -124,48 +142,84 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
|||||||
|
|
||||||
// Track user interactions
|
// Track user interactions
|
||||||
const handleClick = (event: MouseEvent) => {
|
const handleClick = (event: MouseEvent) => {
|
||||||
const target = event.target as HTMLElement;
|
try {
|
||||||
const element = target.tagName.toLowerCase();
|
if (typeof window === 'undefined') return;
|
||||||
const className = target.className;
|
|
||||||
const id = target.id;
|
|
||||||
|
|
||||||
trackEvent('click', {
|
const target = event.target as HTMLElement | null;
|
||||||
element,
|
if (!target) return;
|
||||||
className: (typeof className === 'string' && className) ? className.split(' ')[0] : undefined,
|
|
||||||
id: id || undefined,
|
const element = target.tagName ? target.tagName.toLowerCase() : 'unknown';
|
||||||
url: window.location.pathname,
|
const className = target.className;
|
||||||
});
|
const id = target.id;
|
||||||
|
|
||||||
|
trackEvent('click', {
|
||||||
|
element,
|
||||||
|
className: (typeof className === 'string' && className) ? className.split(' ')[0] : undefined,
|
||||||
|
id: id || undefined,
|
||||||
|
url: window.location.pathname,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - click tracking is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking click:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track form submissions
|
// Track form submissions
|
||||||
const handleSubmit = (event: SubmitEvent) => {
|
const handleSubmit = (event: SubmitEvent) => {
|
||||||
const form = event.target as HTMLFormElement;
|
try {
|
||||||
trackEvent('form-submit', {
|
if (typeof window === 'undefined') return;
|
||||||
formId: form.id || undefined,
|
|
||||||
formClass: form.className || undefined,
|
const form = event.target as HTMLFormElement | null;
|
||||||
url: window.location.pathname,
|
if (!form) return;
|
||||||
});
|
|
||||||
|
trackEvent('form-submit', {
|
||||||
|
formId: form.id || undefined,
|
||||||
|
formClass: form.className || undefined,
|
||||||
|
url: window.location.pathname,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - form tracking is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking form submit:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track scroll depth
|
// Track scroll depth
|
||||||
let maxScrollDepth = 0;
|
let maxScrollDepth = 0;
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
const scrollDepth = Math.round(
|
try {
|
||||||
(window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100
|
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
||||||
);
|
|
||||||
|
|
||||||
if (scrollDepth > maxScrollDepth) {
|
const scrollHeight = document.documentElement.scrollHeight;
|
||||||
maxScrollDepth = scrollDepth;
|
const innerHeight = window.innerHeight;
|
||||||
|
|
||||||
// Track scroll milestones
|
if (scrollHeight <= innerHeight) return; // No scrollable content
|
||||||
if (scrollDepth >= 25 && scrollDepth < 50 && maxScrollDepth >= 25) {
|
|
||||||
trackEvent('scroll-depth', { depth: 25, url: window.location.pathname });
|
const scrollDepth = Math.round(
|
||||||
} else if (scrollDepth >= 50 && scrollDepth < 75 && maxScrollDepth >= 50) {
|
(window.scrollY / (scrollHeight - innerHeight)) * 100
|
||||||
trackEvent('scroll-depth', { depth: 50, url: window.location.pathname });
|
);
|
||||||
} else if (scrollDepth >= 75 && scrollDepth < 90 && maxScrollDepth >= 75) {
|
|
||||||
trackEvent('scroll-depth', { depth: 75, url: window.location.pathname });
|
if (scrollDepth > maxScrollDepth) {
|
||||||
} else if (scrollDepth >= 90 && maxScrollDepth >= 90) {
|
maxScrollDepth = scrollDepth;
|
||||||
trackEvent('scroll-depth', { depth: 90, url: window.location.pathname });
|
|
||||||
|
// Track scroll milestones
|
||||||
|
if (scrollDepth >= 25 && scrollDepth < 50 && maxScrollDepth >= 25) {
|
||||||
|
trackEvent('scroll-depth', { depth: 25, url: window.location.pathname });
|
||||||
|
} else if (scrollDepth >= 50 && scrollDepth < 75 && maxScrollDepth >= 50) {
|
||||||
|
trackEvent('scroll-depth', { depth: 50, url: window.location.pathname });
|
||||||
|
} else if (scrollDepth >= 75 && scrollDepth < 90 && maxScrollDepth >= 75) {
|
||||||
|
trackEvent('scroll-depth', { depth: 75, url: window.location.pathname });
|
||||||
|
} else if (scrollDepth >= 90 && maxScrollDepth >= 90) {
|
||||||
|
trackEvent('scroll-depth', { depth: 90, url: window.location.pathname });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - scroll tracking is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking scroll:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -177,35 +231,64 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
|||||||
|
|
||||||
// Track errors
|
// Track errors
|
||||||
const handleError = (event: ErrorEvent) => {
|
const handleError = (event: ErrorEvent) => {
|
||||||
trackEvent('error', {
|
try {
|
||||||
message: event.message,
|
if (typeof window === 'undefined') return;
|
||||||
filename: event.filename,
|
trackEvent('error', {
|
||||||
lineno: event.lineno,
|
message: event.message || 'Unknown error',
|
||||||
colno: event.colno,
|
filename: event.filename || undefined,
|
||||||
url: window.location.pathname,
|
lineno: event.lineno || undefined,
|
||||||
});
|
colno: event.colno || undefined,
|
||||||
|
url: window.location.pathname,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - error tracking should not cause more errors
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking error event:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
|
const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
|
||||||
trackEvent('unhandled-rejection', {
|
try {
|
||||||
reason: event.reason?.toString(),
|
if (typeof window === 'undefined') return;
|
||||||
url: window.location.pathname,
|
trackEvent('unhandled-rejection', {
|
||||||
});
|
reason: event.reason?.toString() || 'Unknown rejection',
|
||||||
|
url: window.location.pathname,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - error tracking should not cause more errors
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking unhandled rejection:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('error', handleError);
|
window.addEventListener('error', handleError);
|
||||||
window.addEventListener('unhandledrejection', handleUnhandledRejection);
|
window.addEventListener('unhandledrejection', handleUnhandledRejection);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('popstate', handleRouteChange);
|
try {
|
||||||
document.removeEventListener('click', handleClick);
|
window.removeEventListener('popstate', handleRouteChange);
|
||||||
document.removeEventListener('submit', handleSubmit);
|
document.removeEventListener('click', handleClick);
|
||||||
window.removeEventListener('scroll', handleScroll);
|
document.removeEventListener('submit', handleSubmit);
|
||||||
window.removeEventListener('error', handleError);
|
window.removeEventListener('scroll', handleScroll);
|
||||||
window.removeEventListener('unhandledrejection', handleUnhandledRejection);
|
window.removeEventListener('error', handleError);
|
||||||
};
|
window.removeEventListener('unhandledrejection', handleUnhandledRejection);
|
||||||
|
} catch {
|
||||||
|
// Silently fail during cleanup
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// If anything fails, log but don't break the app
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error('AnalyticsProvider initialization error:', error);
|
||||||
|
}
|
||||||
|
// Return empty cleanup function
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Always render children, even if analytics fails
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,16 @@ const BackgroundBlobs = () => {
|
|||||||
const x5 = useTransform(springX, (value) => value / 15);
|
const x5 = useTransform(springX, (value) => value / 15);
|
||||||
const y5 = useTransform(springY, (value) => value / 15);
|
const y5 = useTransform(springY, (value) => value / 15);
|
||||||
|
|
||||||
|
// Prevent hydration mismatch
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
const handleMouseMove = (e: MouseEvent) => {
|
const handleMouseMove = (e: MouseEvent) => {
|
||||||
const x = e.clientX - window.innerWidth / 2;
|
const x = e.clientX - window.innerWidth / 2;
|
||||||
const y = e.clientY - window.innerHeight / 2;
|
const y = e.clientY - window.innerHeight / 2;
|
||||||
@@ -37,14 +46,7 @@ const BackgroundBlobs = () => {
|
|||||||
|
|
||||||
window.addEventListener("mousemove", handleMouseMove);
|
window.addEventListener("mousemove", handleMouseMove);
|
||||||
return () => window.removeEventListener("mousemove", handleMouseMove);
|
return () => window.removeEventListener("mousemove", handleMouseMove);
|
||||||
}, [mouseX, mouseY]);
|
}, [mouseX, mouseY, mounted]);
|
||||||
|
|
||||||
// Prevent hydration mismatch
|
|
||||||
const [mounted, setMounted] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMounted(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!mounted) return null;
|
if (!mounted) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -22,17 +22,19 @@ export default class ErrorBoundary extends React.Component<
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.hasError) {
|
if (this.state.hasError) {
|
||||||
return (
|
// Still render children to prevent white screen - just log the error
|
||||||
<div className="p-4 m-4 bg-red-50 border border-red-200 rounded text-red-800">
|
if (process.env.NODE_ENV === 'development') {
|
||||||
<h2>Something went wrong!</h2>
|
return (
|
||||||
<button
|
<div>
|
||||||
className="mt-2 px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700"
|
<div className="p-2 m-2 bg-yellow-50 border border-yellow-200 rounded text-yellow-800 text-xs">
|
||||||
onClick={() => this.setState({ hasError: false })}
|
⚠️ Error boundary triggered - rendering children anyway
|
||||||
>
|
</div>
|
||||||
Try again
|
{this.props.children}
|
||||||
</button>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
}
|
||||||
|
// In production, just render children silently
|
||||||
|
return this.props.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
|
|||||||
const stats = {
|
const stats = {
|
||||||
totalProjects: projects.length,
|
totalProjects: projects.length,
|
||||||
publishedProjects: projects.filter(p => p.published).length,
|
publishedProjects: projects.filter(p => p.published).length,
|
||||||
totalViews: (analytics?.overview?.totalViews as number) || (analytics?.totalViews as number) || projects.reduce((sum, p) => sum + (p.analytics?.views || 0), 0),
|
totalViews: ((analytics?.overview as Record<string, unknown>)?.totalViews as number) || (analytics?.totalViews as number) || projects.reduce((sum, p) => sum + (p.analytics?.views || 0), 0),
|
||||||
unreadEmails: emails.filter(e => !(e.read as boolean)).length,
|
unreadEmails: emails.filter(e => !(e.read as boolean)).length,
|
||||||
avgPerformance: (() => {
|
avgPerformance: (() => {
|
||||||
// Only show real performance data, not defaults
|
// Only show real performance data, not defaults
|
||||||
@@ -172,9 +172,9 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
|
|||||||
}, 0) / projectsWithPerf.length);
|
}, 0) / projectsWithPerf.length);
|
||||||
})(),
|
})(),
|
||||||
systemHealth: (systemStats?.status as string) || 'unknown',
|
systemHealth: (systemStats?.status as string) || 'unknown',
|
||||||
totalUsers: (analytics?.metrics?.totalUsers as number) || (analytics?.totalUsers as number) || 0,
|
totalUsers: ((analytics?.metrics as Record<string, unknown>)?.totalUsers as number) || (analytics?.totalUsers as number) || 0,
|
||||||
bounceRate: (analytics?.metrics?.bounceRate as number) || (analytics?.bounceRate as number) || 0,
|
bounceRate: ((analytics?.metrics as Record<string, unknown>)?.bounceRate as number) || (analytics?.bounceRate as number) || 0,
|
||||||
avgSessionDuration: (analytics?.metrics?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0
|
avgSessionDuration: ((analytics?.metrics as Record<string, unknown>)?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ const ToastItem = ({ toast, onRemove }: ToastProps) => {
|
|||||||
const getColors = () => {
|
const getColors = () => {
|
||||||
switch (toast.type) {
|
switch (toast.type) {
|
||||||
case 'success':
|
case 'success':
|
||||||
return 'bg-stone-50 border-green-200 text-green-800 shadow-md';
|
return 'bg-stone-50 border-green-300 text-green-900 shadow-md';
|
||||||
case 'error':
|
case 'error':
|
||||||
return 'bg-stone-50 border-red-200 text-red-800 shadow-md';
|
return 'bg-stone-50 border-red-200 text-red-800 shadow-md';
|
||||||
case 'warning':
|
case 'warning':
|
||||||
@@ -291,7 +291,7 @@ export const ToastProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
{children}
|
{children}
|
||||||
|
|
||||||
{/* Toast Container */}
|
{/* Toast Container */}
|
||||||
<div className="fixed top-4 right-4 z-50 space-y-2 max-w-xs">
|
<div className="fixed top-4 right-4 z-50 space-y-3 max-w-sm">
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{toasts.map((toast) => (
|
{toasts.map((toast) => (
|
||||||
<ToastItem
|
<ToastItem
|
||||||
|
|||||||
@@ -57,34 +57,55 @@ export const trackWebVitals = (metric: WebVitalsMetric) => {
|
|||||||
|
|
||||||
// Track page load performance
|
// Track page load performance
|
||||||
export const trackPageLoad = () => {
|
export const trackPageLoad = () => {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined' || typeof performance === 'undefined') return;
|
||||||
|
|
||||||
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;
|
try {
|
||||||
|
const navigationEntries = performance.getEntriesByType('navigation');
|
||||||
|
const navigation = navigationEntries[0] as PerformanceNavigationTiming | undefined;
|
||||||
|
|
||||||
if (navigation) {
|
if (navigation && navigation.loadEventEnd && navigation.fetchStart) {
|
||||||
trackPerformance({
|
trackPerformance({
|
||||||
name: 'page-load',
|
name: 'page-load',
|
||||||
value: navigation.loadEventEnd - navigation.fetchStart,
|
value: navigation.loadEventEnd - navigation.fetchStart,
|
||||||
url: window.location.pathname,
|
url: window.location.pathname,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
userAgent: navigator.userAgent,
|
userAgent: navigator.userAgent,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Track individual timing phases
|
// Track individual timing phases
|
||||||
trackEvent('page-timing', {
|
trackEvent('page-timing', {
|
||||||
dns: Math.round(navigation.domainLookupEnd - navigation.domainLookupStart),
|
dns: navigation.domainLookupEnd && navigation.domainLookupStart
|
||||||
tcp: Math.round(navigation.connectEnd - navigation.connectStart),
|
? Math.round(navigation.domainLookupEnd - navigation.domainLookupStart)
|
||||||
request: Math.round(navigation.responseStart - navigation.requestStart),
|
: 0,
|
||||||
response: Math.round(navigation.responseEnd - navigation.responseStart),
|
tcp: navigation.connectEnd && navigation.connectStart
|
||||||
dom: Math.round(navigation.domContentLoadedEventEnd - navigation.responseEnd),
|
? Math.round(navigation.connectEnd - navigation.connectStart)
|
||||||
load: Math.round(navigation.loadEventEnd - navigation.domContentLoadedEventEnd),
|
: 0,
|
||||||
url: window.location.pathname,
|
request: navigation.responseStart && navigation.requestStart
|
||||||
});
|
? Math.round(navigation.responseStart - navigation.requestStart)
|
||||||
|
: 0,
|
||||||
|
response: navigation.responseEnd && navigation.responseStart
|
||||||
|
? Math.round(navigation.responseEnd - navigation.responseStart)
|
||||||
|
: 0,
|
||||||
|
dom: navigation.domContentLoadedEventEnd && navigation.responseEnd
|
||||||
|
? Math.round(navigation.domContentLoadedEventEnd - navigation.responseEnd)
|
||||||
|
: 0,
|
||||||
|
load: navigation.loadEventEnd && navigation.domContentLoadedEventEnd
|
||||||
|
? Math.round(navigation.loadEventEnd - navigation.domContentLoadedEventEnd)
|
||||||
|
: 0,
|
||||||
|
url: window.location.pathname,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - performance tracking is not critical
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Error tracking page load:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track API response times
|
// Track API response times
|
||||||
export const trackApiCall = (endpoint: string, duration: number, status: number) => {
|
export const trackApiCall = (endpoint: string, duration: number, status: number) => {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
trackEvent('api-call', {
|
trackEvent('api-call', {
|
||||||
endpoint,
|
endpoint,
|
||||||
duration: Math.round(duration),
|
duration: Math.round(duration),
|
||||||
@@ -95,6 +116,7 @@ export const trackApiCall = (endpoint: string, duration: number, status: number)
|
|||||||
|
|
||||||
// Track user interactions
|
// Track user interactions
|
||||||
export const trackInteraction = (action: string, element?: string) => {
|
export const trackInteraction = (action: string, element?: string) => {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
trackEvent('interaction', {
|
trackEvent('interaction', {
|
||||||
action,
|
action,
|
||||||
element,
|
element,
|
||||||
@@ -104,6 +126,7 @@ export const trackInteraction = (action: string, element?: string) => {
|
|||||||
|
|
||||||
// Track errors
|
// Track errors
|
||||||
export const trackError = (error: string, context?: string) => {
|
export const trackError = (error: string, context?: string) => {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
trackEvent('error', {
|
trackEvent('error', {
|
||||||
error,
|
error,
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -13,104 +13,192 @@ interface Metric {
|
|||||||
|
|
||||||
// Simple Web Vitals implementation (since we don't want to add external dependencies)
|
// Simple Web Vitals implementation (since we don't want to add external dependencies)
|
||||||
const getCLS = (onPerfEntry: (metric: Metric) => void) => {
|
const getCLS = (onPerfEntry: (metric: Metric) => void) => {
|
||||||
let clsValue = 0;
|
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||||
let sessionValue = 0;
|
|
||||||
let sessionEntries: PerformanceEntry[] = [];
|
|
||||||
|
|
||||||
const observer = new PerformanceObserver((list) => {
|
try {
|
||||||
for (const entry of list.getEntries()) {
|
let clsValue = 0;
|
||||||
if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) {
|
let sessionValue = 0;
|
||||||
const firstSessionEntry = sessionEntries[0];
|
let sessionEntries: PerformanceEntry[] = [];
|
||||||
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
|
|
||||||
|
|
||||||
if (sessionValue && entry.startTime - lastSessionEntry.startTime < 1000 && entry.startTime - firstSessionEntry.startTime < 5000) {
|
const observer = new PerformanceObserver((list) => {
|
||||||
sessionValue += (entry as PerformanceEntry & { value?: number }).value || 0;
|
try {
|
||||||
sessionEntries.push(entry);
|
for (const entry of list.getEntries()) {
|
||||||
} else {
|
if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) {
|
||||||
sessionValue = (entry as PerformanceEntry & { value?: number }).value || 0;
|
const firstSessionEntry = sessionEntries[0];
|
||||||
sessionEntries = [entry];
|
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
|
||||||
|
|
||||||
|
if (sessionValue && entry.startTime - lastSessionEntry.startTime < 1000 && entry.startTime - firstSessionEntry.startTime < 5000) {
|
||||||
|
sessionValue += (entry as PerformanceEntry & { value?: number }).value || 0;
|
||||||
|
sessionEntries.push(entry);
|
||||||
|
} else {
|
||||||
|
sessionValue = (entry as PerformanceEntry & { value?: number }).value || 0;
|
||||||
|
sessionEntries = [entry];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sessionValue > clsValue) {
|
||||||
|
clsValue = sessionValue;
|
||||||
|
onPerfEntry({
|
||||||
|
name: 'CLS',
|
||||||
|
value: clsValue,
|
||||||
|
delta: clsValue,
|
||||||
|
id: `cls-${Date.now()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
if (sessionValue > clsValue) {
|
// Silently fail - CLS tracking is not critical
|
||||||
clsValue = sessionValue;
|
if (process.env.NODE_ENV === 'development') {
|
||||||
onPerfEntry({
|
console.warn('CLS tracking error:', error);
|
||||||
name: 'CLS',
|
|
||||||
value: clsValue,
|
|
||||||
delta: clsValue,
|
|
||||||
id: `cls-${Date.now()}`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe({ type: 'layout-shift', buffered: true });
|
observer.observe({ type: 'layout-shift', buffered: true });
|
||||||
|
return observer;
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('CLS observer initialization failed:', error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFID = (onPerfEntry: (metric: Metric) => void) => {
|
const getFID = (onPerfEntry: (metric: Metric) => void) => {
|
||||||
const observer = new PerformanceObserver((list) => {
|
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||||
for (const entry of list.getEntries()) {
|
|
||||||
onPerfEntry({
|
|
||||||
name: 'FID',
|
|
||||||
value: (entry as PerformanceEntry & { processingStart?: number }).processingStart! - entry.startTime,
|
|
||||||
delta: (entry as PerformanceEntry & { processingStart?: number }).processingStart! - entry.startTime,
|
|
||||||
id: `fid-${Date.now()}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe({ type: 'first-input', buffered: true });
|
try {
|
||||||
|
const observer = new PerformanceObserver((list) => {
|
||||||
|
try {
|
||||||
|
for (const entry of list.getEntries()) {
|
||||||
|
const processingStart = (entry as PerformanceEntry & { processingStart?: number }).processingStart;
|
||||||
|
if (processingStart !== undefined) {
|
||||||
|
onPerfEntry({
|
||||||
|
name: 'FID',
|
||||||
|
value: processingStart - entry.startTime,
|
||||||
|
delta: processingStart - entry.startTime,
|
||||||
|
id: `fid-${Date.now()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('FID tracking error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe({ type: 'first-input', buffered: true });
|
||||||
|
return observer;
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('FID observer initialization failed:', error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFCP = (onPerfEntry: (metric: Metric) => void) => {
|
const getFCP = (onPerfEntry: (metric: Metric) => void) => {
|
||||||
const observer = new PerformanceObserver((list) => {
|
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||||
for (const entry of list.getEntries()) {
|
|
||||||
if (entry.name === 'first-contentful-paint') {
|
|
||||||
onPerfEntry({
|
|
||||||
name: 'FCP',
|
|
||||||
value: entry.startTime,
|
|
||||||
delta: entry.startTime,
|
|
||||||
id: `fcp-${Date.now()}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe({ type: 'paint', buffered: true });
|
try {
|
||||||
|
const observer = new PerformanceObserver((list) => {
|
||||||
|
try {
|
||||||
|
for (const entry of list.getEntries()) {
|
||||||
|
if (entry.name === 'first-contentful-paint') {
|
||||||
|
onPerfEntry({
|
||||||
|
name: 'FCP',
|
||||||
|
value: entry.startTime,
|
||||||
|
delta: entry.startTime,
|
||||||
|
id: `fcp-${Date.now()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('FCP tracking error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe({ type: 'paint', buffered: true });
|
||||||
|
return observer;
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('FCP observer initialization failed:', error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLCP = (onPerfEntry: (metric: Metric) => void) => {
|
const getLCP = (onPerfEntry: (metric: Metric) => void) => {
|
||||||
const observer = new PerformanceObserver((list) => {
|
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||||
const entries = list.getEntries();
|
|
||||||
const lastEntry = entries[entries.length - 1];
|
|
||||||
|
|
||||||
onPerfEntry({
|
try {
|
||||||
name: 'LCP',
|
const observer = new PerformanceObserver((list) => {
|
||||||
value: lastEntry.startTime,
|
try {
|
||||||
delta: lastEntry.startTime,
|
const entries = list.getEntries();
|
||||||
id: `lcp-${Date.now()}`,
|
const lastEntry = entries[entries.length - 1];
|
||||||
|
|
||||||
|
if (lastEntry) {
|
||||||
|
onPerfEntry({
|
||||||
|
name: 'LCP',
|
||||||
|
value: lastEntry.startTime,
|
||||||
|
delta: lastEntry.startTime,
|
||||||
|
id: `lcp-${Date.now()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('LCP tracking error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe({ type: 'largest-contentful-paint', buffered: true });
|
observer.observe({ type: 'largest-contentful-paint', buffered: true });
|
||||||
|
return observer;
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('LCP observer initialization failed:', error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTTFB = (onPerfEntry: (metric: Metric) => void) => {
|
const getTTFB = (onPerfEntry: (metric: Metric) => void) => {
|
||||||
const observer = new PerformanceObserver((list) => {
|
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||||
for (const entry of list.getEntries()) {
|
|
||||||
if (entry.entryType === 'navigation') {
|
|
||||||
const navEntry = entry as PerformanceNavigationTiming;
|
|
||||||
onPerfEntry({
|
|
||||||
name: 'TTFB',
|
|
||||||
value: navEntry.responseStart - navEntry.fetchStart,
|
|
||||||
delta: navEntry.responseStart - navEntry.fetchStart,
|
|
||||||
id: `ttfb-${Date.now()}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe({ type: 'navigation', buffered: true });
|
try {
|
||||||
|
const observer = new PerformanceObserver((list) => {
|
||||||
|
try {
|
||||||
|
for (const entry of list.getEntries()) {
|
||||||
|
if (entry.entryType === 'navigation') {
|
||||||
|
const navEntry = entry as PerformanceNavigationTiming;
|
||||||
|
if (navEntry.responseStart && navEntry.fetchStart) {
|
||||||
|
onPerfEntry({
|
||||||
|
name: 'TTFB',
|
||||||
|
value: navEntry.responseStart - navEntry.fetchStart,
|
||||||
|
delta: navEntry.responseStart - navEntry.fetchStart,
|
||||||
|
id: `ttfb-${Date.now()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('TTFB tracking error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe({ type: 'navigation', buffered: true });
|
||||||
|
return observer;
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('TTFB observer initialization failed:', error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Custom hook for Web Vitals tracking
|
// Custom hook for Web Vitals tracking
|
||||||
@@ -118,11 +206,14 @@ export const useWebVitals = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|
||||||
// Store web vitals for batch sending
|
// Wrap everything in try-catch to prevent errors from breaking the app
|
||||||
const webVitals: Record<string, number> = {};
|
try {
|
||||||
const path = window.location.pathname;
|
// Store web vitals for batch sending
|
||||||
const projectMatch = path.match(/\/projects\/([^\/]+)/);
|
const webVitals: Record<string, number> = {};
|
||||||
const projectId = projectMatch ? projectMatch[1] : null;
|
const path = window.location.pathname;
|
||||||
|
const projectMatch = path.match(/\/projects\/([^\/]+)/);
|
||||||
|
const projectId = projectMatch ? projectMatch[1] : null;
|
||||||
|
const observers: PerformanceObserver[] = [];
|
||||||
|
|
||||||
const sendWebVitals = async () => {
|
const sendWebVitals = async () => {
|
||||||
if (Object.keys(webVitals).length >= 3) { // Wait for at least FCP, LCP, CLS
|
if (Object.keys(webVitals).length >= 3) { // Wait for at least FCP, LCP, CLS
|
||||||
@@ -156,7 +247,7 @@ export const useWebVitals = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Track Core Web Vitals
|
// Track Core Web Vitals
|
||||||
getCLS((metric) => {
|
const clsObserver = getCLS((metric) => {
|
||||||
webVitals.CLS = metric.value;
|
webVitals.CLS = metric.value;
|
||||||
trackWebVitals({
|
trackWebVitals({
|
||||||
...metric,
|
...metric,
|
||||||
@@ -165,8 +256,9 @@ export const useWebVitals = () => {
|
|||||||
});
|
});
|
||||||
sendWebVitals();
|
sendWebVitals();
|
||||||
});
|
});
|
||||||
|
if (clsObserver) observers.push(clsObserver);
|
||||||
|
|
||||||
getFID((metric) => {
|
const fidObserver = getFID((metric) => {
|
||||||
webVitals.FID = metric.value;
|
webVitals.FID = metric.value;
|
||||||
trackWebVitals({
|
trackWebVitals({
|
||||||
...metric,
|
...metric,
|
||||||
@@ -175,8 +267,9 @@ export const useWebVitals = () => {
|
|||||||
});
|
});
|
||||||
sendWebVitals();
|
sendWebVitals();
|
||||||
});
|
});
|
||||||
|
if (fidObserver) observers.push(fidObserver);
|
||||||
|
|
||||||
getFCP((metric) => {
|
const fcpObserver = getFCP((metric) => {
|
||||||
webVitals.FCP = metric.value;
|
webVitals.FCP = metric.value;
|
||||||
trackWebVitals({
|
trackWebVitals({
|
||||||
...metric,
|
...metric,
|
||||||
@@ -185,8 +278,9 @@ export const useWebVitals = () => {
|
|||||||
});
|
});
|
||||||
sendWebVitals();
|
sendWebVitals();
|
||||||
});
|
});
|
||||||
|
if (fcpObserver) observers.push(fcpObserver);
|
||||||
|
|
||||||
getLCP((metric) => {
|
const lcpObserver = getLCP((metric) => {
|
||||||
webVitals.LCP = metric.value;
|
webVitals.LCP = metric.value;
|
||||||
trackWebVitals({
|
trackWebVitals({
|
||||||
...metric,
|
...metric,
|
||||||
@@ -195,8 +289,9 @@ export const useWebVitals = () => {
|
|||||||
});
|
});
|
||||||
sendWebVitals();
|
sendWebVitals();
|
||||||
});
|
});
|
||||||
|
if (lcpObserver) observers.push(lcpObserver);
|
||||||
|
|
||||||
getTTFB((metric) => {
|
const ttfbObserver = getTTFB((metric) => {
|
||||||
webVitals.TTFB = metric.value;
|
webVitals.TTFB = metric.value;
|
||||||
trackWebVitals({
|
trackWebVitals({
|
||||||
...metric,
|
...metric,
|
||||||
@@ -205,6 +300,7 @@ export const useWebVitals = () => {
|
|||||||
});
|
});
|
||||||
sendWebVitals();
|
sendWebVitals();
|
||||||
});
|
});
|
||||||
|
if (ttfbObserver) observers.push(ttfbObserver);
|
||||||
|
|
||||||
// Track page load performance
|
// Track page load performance
|
||||||
const handleLoad = () => {
|
const handleLoad = () => {
|
||||||
@@ -225,8 +321,28 @@ export const useWebVitals = () => {
|
|||||||
window.addEventListener('load', handleLoad);
|
window.addEventListener('load', handleLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('load', handleLoad);
|
// Cleanup all observers
|
||||||
};
|
observers.forEach(observer => {
|
||||||
|
try {
|
||||||
|
observer.disconnect();
|
||||||
|
} catch {
|
||||||
|
// Silently fail
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
window.removeEventListener('load', handleLoad);
|
||||||
|
} catch {
|
||||||
|
// Silently fail
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// If Web Vitals initialization fails, don't break the app
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.warn('Web Vitals initialization failed:', error);
|
||||||
|
}
|
||||||
|
// Return empty cleanup function
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|||||||
1700
public/404-terminal.html
Normal file
1700
public/404-terminal.html
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user