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
|
||||
}));
|
||||
|
||||
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)
|
||||
: 0;
|
||||
|
||||
|
||||
@@ -126,29 +126,30 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
await prisma.project.update({
|
||||
where: { id: projectIdNum },
|
||||
data: {
|
||||
performance: {
|
||||
...perf,
|
||||
lighthouse: lighthouseScore,
|
||||
loadTime: performance.loadTime || perf.loadTime || 0,
|
||||
firstContentfulPaint: fcp || perf.firstContentfulPaint || 0,
|
||||
largestContentfulPaint: lcp || perf.largestContentfulPaint || 0,
|
||||
cumulativeLayoutShift: cls || perf.cumulativeLayoutShift || 0,
|
||||
totalBlockingTime: performance.tbt || perf.totalBlockingTime || 0,
|
||||
speedIndex: performance.si || perf.speedIndex || 0,
|
||||
coreWebVitals: {
|
||||
lcp: lcp || (perf.coreWebVitals as Record<string, unknown>)?.lcp || 0,
|
||||
fid: fid || (perf.coreWebVitals as Record<string, unknown>)?.fid || 0,
|
||||
cls: cls || (perf.coreWebVitals as Record<string, unknown>)?.cls || 0
|
||||
data: {
|
||||
performance: {
|
||||
...perf,
|
||||
lighthouse: lighthouseScore,
|
||||
loadTime: performance.loadTime || perf.loadTime || 0,
|
||||
firstContentfulPaint: fcp || perf.firstContentfulPaint || 0,
|
||||
largestContentfulPaint: lcp || perf.largestContentfulPaint || 0,
|
||||
cumulativeLayoutShift: cls || perf.cumulativeLayoutShift || 0,
|
||||
totalBlockingTime: performance.tbt || perf.totalBlockingTime || 0,
|
||||
speedIndex: performance.si || perf.speedIndex || 0,
|
||||
coreWebVitals: {
|
||||
lcp: lcp || (perf.coreWebVitals as Record<string, unknown>)?.lcp || 0,
|
||||
fid: fid || (perf.coreWebVitals as Record<string, unknown>)?.fid || 0,
|
||||
cls: cls || (perf.coreWebVitals as Record<string, unknown>)?.cls || 0
|
||||
},
|
||||
lastUpdated: new Date().toISOString()
|
||||
},
|
||||
lastUpdated: new Date().toISOString()
|
||||
},
|
||||
analytics: {
|
||||
...analytics,
|
||||
lastUpdated: new Date().toISOString()
|
||||
analytics: {
|
||||
...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';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
// In a real app, you would check for admin session here
|
||||
// For now, we trust the 'x-admin-request' header if it's set by the server-side component or middleware
|
||||
// but typically you'd verify the session cookie/token
|
||||
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');
|
||||
|
||||
const contacts = await prisma.contact.findMany({
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
take: 100,
|
||||
});
|
||||
let whereClause = {};
|
||||
|
||||
switch (filter) {
|
||||
case 'unread':
|
||||
whereClause = { responded: false };
|
||||
break;
|
||||
case 'responded':
|
||||
whereClause = { responded: true };
|
||||
break;
|
||||
default:
|
||||
whereClause = {};
|
||||
}
|
||||
|
||||
return NextResponse.json({ contacts });
|
||||
} catch (error) {
|
||||
console.error('Error fetching contacts:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch contacts' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
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() {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [data, setData] = useState<StatusData | null>(null);
|
||||
const [isExpanded, setIsExpanded] = useState(true);
|
||||
const [isMinimized, setIsMinimized] = useState(false);
|
||||
const [hasActivity, setHasActivity] = useState(false);
|
||||
const [isTrackingEnabled, setIsTrackingEnabled] = useState(() => {
|
||||
// Check localStorage for tracking preference
|
||||
if (typeof window !== "undefined") {
|
||||
const stored = localStorage.getItem("activityTrackingEnabled");
|
||||
return stored !== "false"; // Default to true if not set
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// Initialize with default value to prevent hydration mismatch
|
||||
const [isTrackingEnabled, setIsTrackingEnabled] = useState(true);
|
||||
const [quote, setQuote] = useState<{
|
||||
content: string;
|
||||
author: string;
|
||||
} | 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)
|
||||
useEffect(() => {
|
||||
// Don't fetch if tracking is disabled
|
||||
if (!isTrackingEnabled) {
|
||||
// Don't fetch if tracking is disabled or during SSR
|
||||
if (!isTrackingEnabled || typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchData = async () => {
|
||||
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
|
||||
const res = await fetch("/api/n8n/status", {
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
console.log("ActivityFeed data (raw):", json);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log("ActivityFeed data (raw):", json);
|
||||
}
|
||||
|
||||
// Handle array response if API returns it wrapped
|
||||
if (Array.isArray(json)) {
|
||||
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
|
||||
const hasActiveActivity =
|
||||
json.coding?.isActive ||
|
||||
json.gaming?.isPlaying ||
|
||||
json.music?.isPlaying;
|
||||
const coding = activityData.coding;
|
||||
const gaming = activityData.gaming;
|
||||
const music = activityData.music;
|
||||
|
||||
const hasActiveActivity = Boolean(
|
||||
coding?.isActive ||
|
||||
gaming?.isPlaying ||
|
||||
music?.isPlaying
|
||||
);
|
||||
|
||||
console.log("Has activity:", hasActiveActivity, {
|
||||
coding: json.coding?.isActive,
|
||||
gaming: json.gaming?.isPlaying,
|
||||
music: json.music?.isPlaying,
|
||||
});
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log("Has activity:", hasActiveActivity, {
|
||||
coding: coding?.isActive,
|
||||
gaming: gaming?.isPlaying,
|
||||
music: music?.isPlaying,
|
||||
});
|
||||
}
|
||||
|
||||
setHasActivity(hasActiveActivity);
|
||||
|
||||
@@ -112,8 +167,12 @@ export default function ActivityFeed() {
|
||||
if (hasActiveActivity && !isMinimized) {
|
||||
setIsExpanded(true);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch activity", e);
|
||||
} catch (error) {
|
||||
// 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;
|
||||
setIsTrackingEnabled(newValue);
|
||||
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
|
||||
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
|
||||
if (!isTrackingEnabled && !data) return null;
|
||||
|
||||
|
||||
@@ -20,21 +20,47 @@ interface Message {
|
||||
}
|
||||
|
||||
export default function ChatWidget() {
|
||||
// Prevent hydration mismatch by only rendering after mount
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [inputValue, setInputValue] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [conversationId, setConversationId] = useState(() => {
|
||||
// Generate or retrieve conversation ID
|
||||
if (typeof window !== "undefined") {
|
||||
const [conversationId, setConversationId] = useState<string>("default");
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
// Generate or retrieve conversation ID only on client
|
||||
try {
|
||||
const stored = localStorage.getItem("chatSessionId");
|
||||
if (stored) return stored;
|
||||
const newId = crypto.randomUUID();
|
||||
if (stored) {
|
||||
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);
|
||||
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 inputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -62,22 +88,55 @@ export default function ChatWidget() {
|
||||
// Load messages from localStorage
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
const stored = localStorage.getItem("chatMessages");
|
||||
if (stored) {
|
||||
try {
|
||||
const parsed = JSON.parse(stored);
|
||||
setMessages(
|
||||
parsed.map((m: Message) => ({
|
||||
...m,
|
||||
text: decodeHtmlEntities(m.text), // Decode HTML entities when loading
|
||||
timestamp: new Date(m.timestamp),
|
||||
})),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error("Failed to load chat history", e);
|
||||
try {
|
||||
const stored = localStorage.getItem("chatMessages");
|
||||
if (stored) {
|
||||
try {
|
||||
const parsed = JSON.parse(stored);
|
||||
setMessages(
|
||||
parsed.map((m: Message) => ({
|
||||
...m,
|
||||
text: decodeHtmlEntities(m.text), // Decode HTML entities when loading
|
||||
timestamp: new Date(m.timestamp),
|
||||
})),
|
||||
);
|
||||
} 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 {
|
||||
// Add welcome message
|
||||
} catch (error) {
|
||||
// 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([
|
||||
{
|
||||
id: "welcome",
|
||||
@@ -93,7 +152,14 @@ export default function ChatWidget() {
|
||||
// Save messages to localStorage
|
||||
useEffect(() => {
|
||||
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]);
|
||||
|
||||
@@ -204,6 +270,11 @@ export default function ChatWidget() {
|
||||
]);
|
||||
};
|
||||
|
||||
// Don't render until mounted to prevent hydration mismatch
|
||||
if (!mounted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Chat Button */}
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState, Suspense, lazy } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import dynamic from "next/dynamic";
|
||||
import { ToastProvider } from "@/components/Toast";
|
||||
import ErrorBoundary from "@/components/ErrorBoundary";
|
||||
import { AnalyticsProvider } from "@/components/AnalyticsProvider";
|
||||
|
||||
// Lazy load heavy components to avoid webpack issues
|
||||
const BackgroundBlobs = lazy(() => import("@/components/BackgroundBlobs"));
|
||||
const ChatWidget = lazy(() => import("./ChatWidget"));
|
||||
// Dynamic import with SSR disabled to avoid framer-motion issues
|
||||
const BackgroundBlobs = dynamic(() => import("@/components/BackgroundBlobs").catch(() => ({ default: () => null })), {
|
||||
ssr: false,
|
||||
loading: () => null,
|
||||
});
|
||||
|
||||
const ChatWidget = dynamic(() => import("./ChatWidget").catch(() => ({ default: () => null })), {
|
||||
ssr: false,
|
||||
loading: () => null,
|
||||
});
|
||||
|
||||
export default function ClientProviders({
|
||||
children,
|
||||
@@ -16,37 +25,61 @@ export default function ClientProviders({
|
||||
}) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [is404Page, setIs404Page] = useState(false);
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
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 = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
const has404Component = document.querySelector('[data-404-page]');
|
||||
setIs404Page(!!has404Component);
|
||||
try {
|
||||
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
||||
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
|
||||
check404();
|
||||
const timeout = setTimeout(check404, 100);
|
||||
return () => clearTimeout(timeout);
|
||||
}, []);
|
||||
try {
|
||||
check404();
|
||||
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 (
|
||||
<AnalyticsProvider>
|
||||
<ToastProvider>
|
||||
{mounted && (
|
||||
<Suspense fallback={null}>
|
||||
<BackgroundBlobs />
|
||||
</Suspense>
|
||||
)}
|
||||
<div className="relative z-10">{children}</div>
|
||||
{mounted && !is404Page && (
|
||||
<Suspense fallback={null}>
|
||||
<ChatWidget />
|
||||
</Suspense>
|
||||
)}
|
||||
</ToastProvider>
|
||||
</AnalyticsProvider>
|
||||
<ErrorBoundary>
|
||||
<ErrorBoundary>
|
||||
<AnalyticsProvider>
|
||||
<ErrorBoundary>
|
||||
<ToastProvider>
|
||||
{mounted && <BackgroundBlobs />}
|
||||
<div className="relative z-10">{children}</div>
|
||||
{mounted && !is404Page && <ChatWidget />}
|
||||
</ToastProvider>
|
||||
</ErrorBoundary>
|
||||
</AnalyticsProvider>
|
||||
</ErrorBoundary>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export default function KernelPanic404() {
|
||||
const inputContainerRef = 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 bootStartedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
/* --- SYSTEM CORE --- */
|
||||
@@ -20,21 +21,25 @@ export default function KernelPanic404() {
|
||||
const body = document.body;
|
||||
|
||||
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 systemFrozen = false;
|
||||
let currentMusic: any = null;
|
||||
let currentMusic: { stop: () => void } | null = null;
|
||||
let hawkinsActive = false;
|
||||
let fsocietyActive = false;
|
||||
|
||||
// Timers storage to clear on unmount
|
||||
const timers: (NodeJS.Timeout | number)[] = [];
|
||||
const interval = (fn: Function, ms: number) => {
|
||||
const interval = (fn: () => void, ms: number) => {
|
||||
const id = setInterval(fn, ms);
|
||||
timers.push(id);
|
||||
return id;
|
||||
};
|
||||
const timeout = (fn: Function, ms: number) => {
|
||||
const timeout = (fn: () => void, ms: number) => {
|
||||
const id = setTimeout(fn, ms);
|
||||
timers.push(id);
|
||||
return id;
|
||||
@@ -44,7 +49,7 @@ export default function KernelPanic404() {
|
||||
function initAudio() {
|
||||
if (!audioCtx) {
|
||||
const AudioContextClass =
|
||||
window.AudioContext || (window as any).webkitAudioContext;
|
||||
window.AudioContext || (window as typeof window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
|
||||
if (AudioContextClass) {
|
||||
audioCtx = new AudioContextClass();
|
||||
}
|
||||
@@ -439,6 +444,7 @@ export default function KernelPanic404() {
|
||||
}
|
||||
|
||||
/* --- FILE SYSTEM --- */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const fileSystem: any = {
|
||||
home: {
|
||||
type: "dir",
|
||||
@@ -546,7 +552,7 @@ export default function KernelPanic404() {
|
||||
|
||||
let currentPath = fileSystem.home.children.guest;
|
||||
let pathStr = "~";
|
||||
let commandHistory: string[] = [];
|
||||
const commandHistory: string[] = [];
|
||||
let historyIndex = -1;
|
||||
|
||||
/* --- UTILS --- */
|
||||
@@ -554,12 +560,19 @@ export default function KernelPanic404() {
|
||||
if (!output) return;
|
||||
const d = document.createElement("div");
|
||||
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")
|
||||
d.style.color = "var(--alert)";
|
||||
if (type === "log-dim") d.style.opacity = "0.6";
|
||||
if (type === "log-sys") d.style.color = "cyan";
|
||||
if (type === "log-k") d.style.color = "#fff";
|
||||
d.style.setProperty("color", "var(--alert)", "important");
|
||||
if (type === "log-dim") {
|
||||
d.style.opacity = "0.6";
|
||||
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 === "fsociety-mask") d.classList.add("fsociety-mask");
|
||||
if (type === "memory-error") d.classList.add("memory-error");
|
||||
@@ -659,7 +672,7 @@ export default function KernelPanic404() {
|
||||
// Clear initial output
|
||||
output!.innerHTML = "";
|
||||
|
||||
for (let msg of bootMessages) {
|
||||
for (const msg of bootMessages) {
|
||||
printLine(msg.t, msg.type);
|
||||
await sleep(msg.d);
|
||||
}
|
||||
@@ -782,7 +795,7 @@ export default function KernelPanic404() {
|
||||
if (suggestions.length === 0) {
|
||||
try {
|
||||
playSynth("beep");
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -805,13 +818,13 @@ export default function KernelPanic404() {
|
||||
input.setSelectionRange(input.value.length, input.value.length);
|
||||
try {
|
||||
playSynth("beep");
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
} else {
|
||||
// Multiple matches
|
||||
printLine(`Possible completions: ${suggestions.join(" ")}`, "log-dim");
|
||||
try {
|
||||
playSynth("beep");
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -820,7 +833,7 @@ export default function KernelPanic404() {
|
||||
if (systemFrozen || !input) {
|
||||
try {
|
||||
playSynth("beep");
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -859,7 +872,7 @@ export default function KernelPanic404() {
|
||||
args.includes("-a") || args.includes("-la") || args.includes("-l");
|
||||
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,
|
||||
);
|
||||
|
||||
@@ -1165,7 +1178,7 @@ export default function KernelPanic404() {
|
||||
overlay.style.display = "none";
|
||||
overlay.innerHTML = "";
|
||||
|
||||
const sporeInterval = interval(() => {
|
||||
const _sporeInterval = interval(() => {
|
||||
const spore = document.createElement("div");
|
||||
spore.className = "spore";
|
||||
spore.style.left = Math.random() * 100 + "%";
|
||||
@@ -1175,7 +1188,7 @@ export default function KernelPanic404() {
|
||||
setTimeout(() => spore.remove(), 3000);
|
||||
}, 300);
|
||||
|
||||
const glitchInterval = interval(() => {
|
||||
const _glitchInterval = interval(() => {
|
||||
if (!hawkinsActive) return;
|
||||
body.style.filter = "hue-rotate(180deg) contrast(1.3) brightness(0.9)";
|
||||
setTimeout(
|
||||
@@ -1400,7 +1413,7 @@ export default function KernelPanic404() {
|
||||
|
||||
try {
|
||||
playSynth("key");
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
|
||||
if (e.key === "ArrowUp" && historyIndex > 0) {
|
||||
historyIndex--;
|
||||
@@ -1442,18 +1455,40 @@ export default function KernelPanic404() {
|
||||
--phosphor: #33ff00;
|
||||
--phosphor-sec: #008f11;
|
||||
--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-wrap {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
box-sizing: border-box;
|
||||
background: radial-gradient(circle at center, #111 0%, #000 100%);
|
||||
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 {
|
||||
@@ -1463,25 +1498,22 @@ export default function KernelPanic404() {
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background:
|
||||
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)
|
||||
);
|
||||
background-size:
|
||||
100% 4px,
|
||||
3px 100%;
|
||||
background: 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));
|
||||
background-size: 100% 4px, 3px 100%;
|
||||
pointer-events: none;
|
||||
z-index: 90;
|
||||
}
|
||||
|
||||
.glow {
|
||||
text-shadow:
|
||||
0 0 2px var(--phosphor-sec),
|
||||
0 0 8px var(--phosphor);
|
||||
text-shadow: 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 --- */
|
||||
@@ -1502,7 +1534,6 @@ export default function KernelPanic404() {
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.1rem;
|
||||
line-height: 1.4;
|
||||
color: var(--phosphor);
|
||||
}
|
||||
|
||||
#output::-webkit-scrollbar {
|
||||
@@ -1522,7 +1553,6 @@ export default function KernelPanic404() {
|
||||
margin-right: 10px;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
color: var(--phosphor);
|
||||
}
|
||||
|
||||
#cmd-input {
|
||||
@@ -1847,7 +1877,7 @@ export default function KernelPanic404() {
|
||||
|
||||
<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="output" ref={outputRef}></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 { 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 Image from "next/image";
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ function EditorPageContent() {
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [isCreating, setIsCreating] = useState(!projectId);
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
const [isTyping, setIsTyping] = useState(false);
|
||||
const [_isTyping, setIsTyping] = useState(false);
|
||||
const [history, setHistory] = useState<typeof formData[]>([]);
|
||||
const [historyIndex, setHistoryIndex] = useState(-1);
|
||||
const [originalFormData, setOriginalFormData] = useState<typeof formData | null>(null);
|
||||
|
||||
@@ -57,25 +57,42 @@ const AdminPage = () => {
|
||||
|
||||
// Check if user is locked out
|
||||
const checkLockout = useCallback(() => {
|
||||
const lockoutData = localStorage.getItem('admin_lockout');
|
||||
if (lockoutData) {
|
||||
try {
|
||||
const { timestamp, attempts } = JSON.parse(lockoutData);
|
||||
const now = Date.now();
|
||||
if (typeof window === 'undefined') return false;
|
||||
|
||||
try {
|
||||
const lockoutData = localStorage.getItem('admin_lockout');
|
||||
if (lockoutData) {
|
||||
try {
|
||||
const { timestamp, attempts } = JSON.parse(lockoutData);
|
||||
const now = Date.now();
|
||||
|
||||
if (now - timestamp < LOCKOUT_DURATION) {
|
||||
setAuthState(prev => ({
|
||||
...prev,
|
||||
isLocked: true,
|
||||
attempts,
|
||||
isLoading: false
|
||||
}));
|
||||
return true;
|
||||
} else {
|
||||
localStorage.removeItem('admin_lockout');
|
||||
if (now - timestamp < LOCKOUT_DURATION) {
|
||||
setAuthState(prev => ({
|
||||
...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;
|
||||
@@ -197,7 +214,11 @@ const AdminPage = () => {
|
||||
attempts: 0,
|
||||
isLoading: false
|
||||
}));
|
||||
localStorage.removeItem('admin_lockout');
|
||||
try {
|
||||
localStorage.removeItem('admin_lockout');
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
} else {
|
||||
const newAttempts = authState.attempts + 1;
|
||||
setAuthState(prev => ({
|
||||
@@ -208,10 +229,17 @@ const AdminPage = () => {
|
||||
}));
|
||||
|
||||
if (newAttempts >= 5) {
|
||||
localStorage.setItem('admin_lockout', JSON.stringify({
|
||||
timestamp: Date.now(),
|
||||
attempts: newAttempts
|
||||
}));
|
||||
try {
|
||||
localStorage.setItem('admin_lockout', JSON.stringify({
|
||||
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 => ({
|
||||
...prev,
|
||||
isLocked: true,
|
||||
@@ -252,7 +280,11 @@ const AdminPage = () => {
|
||||
<p className="text-stone-500">Too many failed attempts. Please try again in 15 minutes.</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
localStorage.removeItem('admin_lockout');
|
||||
try {
|
||||
localStorage.removeItem('admin_lockout');
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
window.location.reload();
|
||||
}}
|
||||
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";
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
// Dynamically import KernelPanic404 to avoid SSR issues
|
||||
const KernelPanic404 = dynamic(() => import("./components/KernelPanic404"), {
|
||||
// Dynamically import KernelPanic404Wrapper to avoid SSR issues
|
||||
const KernelPanic404 = dynamic(() => import("./components/KernelPanic404Wrapper"), {
|
||||
ssr: false,
|
||||
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>
|
||||
),
|
||||
});
|
||||
|
||||
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 (
|
||||
<main className="min-h-screen w-full bg-black overflow-hidden relative">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex items-center justify-center min-h-screen bg-black text-[#33ff00] font-mono">
|
||||
<div>Loading terminal...</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<KernelPanic404 />
|
||||
</Suspense>
|
||||
</main>
|
||||
<div style={{
|
||||
position: "fixed",
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
overflow: "hidden",
|
||||
backgroundColor: "#020202",
|
||||
zIndex: 9998
|
||||
}}>
|
||||
<KernelPanic404 />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import Projects from "./components/Projects";
|
||||
import Contact from "./components/Contact";
|
||||
import Footer from "./components/Footer";
|
||||
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";
|
||||
|
||||
export default function Home() {
|
||||
@@ -35,7 +36,9 @@ export default function Home() {
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
<ActivityFeed />
|
||||
<ErrorBoundary>
|
||||
<ActivityFeed />
|
||||
</ErrorBoundary>
|
||||
<Header />
|
||||
{/* Spacer to prevent navbar overlap */}
|
||||
<div className="h-24 md:h-32" aria-hidden="true"></div>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
"use client";
|
||||
|
||||
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 { useParams } from 'next/navigation';
|
||||
import { useState, useEffect } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import Image from 'next/image';
|
||||
|
||||
interface Project {
|
||||
id: number;
|
||||
|
||||
@@ -4,9 +4,7 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import {
|
||||
BarChart3,
|
||||
TrendingUp,
|
||||
Eye,
|
||||
Heart,
|
||||
Zap,
|
||||
Globe,
|
||||
Activity,
|
||||
|
||||
@@ -9,12 +9,16 @@ interface AnalyticsProviderProps {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
// Wrap entire effect in try-catch to prevent any errors from breaking the app
|
||||
try {
|
||||
|
||||
// Track page view
|
||||
const trackPageView = async () => {
|
||||
const path = window.location.pathname;
|
||||
@@ -49,8 +53,15 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
||||
}
|
||||
};
|
||||
|
||||
// Track page load performance
|
||||
trackPageLoad();
|
||||
// Track page load performance - wrapped in try-catch
|
||||
try {
|
||||
trackPageLoad();
|
||||
} catch (error) {
|
||||
// Silently fail
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.warn('Error tracking page load:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Track initial page view
|
||||
trackPageView();
|
||||
@@ -65,36 +76,43 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
||||
|
||||
// Wait for page to fully load
|
||||
setTimeout(async () => {
|
||||
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;
|
||||
const paintEntries = performance.getEntriesByType('paint');
|
||||
const lcpEntries = performance.getEntriesByType('largest-contentful-paint');
|
||||
|
||||
const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint');
|
||||
const lcp = lcpEntries[lcpEntries.length - 1];
|
||||
|
||||
const performanceData = {
|
||||
loadTime: navigation ? navigation.loadEventEnd - navigation.fetchStart : 0,
|
||||
fcp: fcp ? fcp.startTime : 0,
|
||||
lcp: lcp ? lcp.startTime : 0,
|
||||
ttfb: navigation ? navigation.responseStart - navigation.fetchStart : 0,
|
||||
cls: 0, // Will be updated by CLS observer
|
||||
fid: 0, // Will be updated by FID observer
|
||||
si: 0 // Speed Index - would need to calculate
|
||||
};
|
||||
try {
|
||||
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming | undefined;
|
||||
const paintEntries = performance.getEntriesByType('paint');
|
||||
const lcpEntries = performance.getEntriesByType('largest-contentful-paint');
|
||||
|
||||
const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint');
|
||||
const lcp = lcpEntries.length > 0 ? lcpEntries[lcpEntries.length - 1] : undefined;
|
||||
|
||||
const performanceData = {
|
||||
loadTime: navigation && navigation.loadEventEnd && navigation.fetchStart ? navigation.loadEventEnd - navigation.fetchStart : 0,
|
||||
fcp: fcp ? fcp.startTime : 0,
|
||||
lcp: lcp ? lcp.startTime : 0,
|
||||
ttfb: navigation && navigation.responseStart && navigation.fetchStart ? navigation.responseStart - navigation.fetchStart : 0,
|
||||
cls: 0, // Will be updated by CLS observer
|
||||
fid: 0, // Will be updated by FID observer
|
||||
si: 0 // Speed Index - would need to calculate
|
||||
};
|
||||
|
||||
// Send performance data
|
||||
await fetch('/api/analytics/track', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'performance',
|
||||
projectId: projectId,
|
||||
page: path,
|
||||
performance: performanceData
|
||||
})
|
||||
});
|
||||
// Send performance data
|
||||
await fetch('/api/analytics/track', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'performance',
|
||||
projectId: projectId,
|
||||
page: path,
|
||||
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
|
||||
} catch (error) {
|
||||
// Silently fail
|
||||
@@ -124,48 +142,84 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
|
||||
|
||||
// Track user interactions
|
||||
const handleClick = (event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement;
|
||||
const element = target.tagName.toLowerCase();
|
||||
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,
|
||||
});
|
||||
try {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (!target) return;
|
||||
|
||||
const element = target.tagName ? target.tagName.toLowerCase() : 'unknown';
|
||||
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
|
||||
const handleSubmit = (event: SubmitEvent) => {
|
||||
const form = event.target as HTMLFormElement;
|
||||
trackEvent('form-submit', {
|
||||
formId: form.id || undefined,
|
||||
formClass: form.className || undefined,
|
||||
url: window.location.pathname,
|
||||
});
|
||||
try {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const form = event.target as HTMLFormElement | null;
|
||||
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
|
||||
let maxScrollDepth = 0;
|
||||
const handleScroll = () => {
|
||||
const scrollDepth = Math.round(
|
||||
(window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100
|
||||
);
|
||||
|
||||
if (scrollDepth > maxScrollDepth) {
|
||||
maxScrollDepth = scrollDepth;
|
||||
try {
|
||||
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
||||
|
||||
// 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 });
|
||||
const scrollHeight = document.documentElement.scrollHeight;
|
||||
const innerHeight = window.innerHeight;
|
||||
|
||||
if (scrollHeight <= innerHeight) return; // No scrollable content
|
||||
|
||||
const scrollDepth = Math.round(
|
||||
(window.scrollY / (scrollHeight - innerHeight)) * 100
|
||||
);
|
||||
|
||||
if (scrollDepth > maxScrollDepth) {
|
||||
maxScrollDepth = scrollDepth;
|
||||
|
||||
// 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
|
||||
const handleError = (event: ErrorEvent) => {
|
||||
trackEvent('error', {
|
||||
message: event.message,
|
||||
filename: event.filename,
|
||||
lineno: event.lineno,
|
||||
colno: event.colno,
|
||||
url: window.location.pathname,
|
||||
});
|
||||
try {
|
||||
if (typeof window === 'undefined') return;
|
||||
trackEvent('error', {
|
||||
message: event.message || 'Unknown error',
|
||||
filename: event.filename || undefined,
|
||||
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) => {
|
||||
trackEvent('unhandled-rejection', {
|
||||
reason: event.reason?.toString(),
|
||||
url: window.location.pathname,
|
||||
});
|
||||
try {
|
||||
if (typeof window === 'undefined') return;
|
||||
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('unhandledrejection', handleUnhandledRejection);
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
window.removeEventListener('popstate', handleRouteChange);
|
||||
document.removeEventListener('click', handleClick);
|
||||
document.removeEventListener('submit', handleSubmit);
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
window.removeEventListener('error', handleError);
|
||||
window.removeEventListener('unhandledrejection', handleUnhandledRejection);
|
||||
};
|
||||
// Cleanup
|
||||
return () => {
|
||||
try {
|
||||
window.removeEventListener('popstate', handleRouteChange);
|
||||
document.removeEventListener('click', handleClick);
|
||||
document.removeEventListener('submit', handleSubmit);
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
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}</>;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,16 @@ const BackgroundBlobs = () => {
|
||||
const x5 = useTransform(springX, (value) => value / 15);
|
||||
const y5 = useTransform(springY, (value) => value / 15);
|
||||
|
||||
// Prevent hydration mismatch
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted) return;
|
||||
|
||||
const handleMouseMove = (e: MouseEvent) => {
|
||||
const x = e.clientX - window.innerWidth / 2;
|
||||
const y = e.clientY - window.innerHeight / 2;
|
||||
@@ -37,14 +46,7 @@ const BackgroundBlobs = () => {
|
||||
|
||||
window.addEventListener("mousemove", handleMouseMove);
|
||||
return () => window.removeEventListener("mousemove", handleMouseMove);
|
||||
}, [mouseX, mouseY]);
|
||||
|
||||
// Prevent hydration mismatch
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
}, [mouseX, mouseY, mounted]);
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
|
||||
@@ -22,17 +22,19 @@ export default class ErrorBoundary extends React.Component<
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div className="p-4 m-4 bg-red-50 border border-red-200 rounded text-red-800">
|
||||
<h2>Something went wrong!</h2>
|
||||
<button
|
||||
className="mt-2 px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700"
|
||||
onClick={() => this.setState({ hasError: false })}
|
||||
>
|
||||
Try again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
// Still render children to prevent white screen - just log the error
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return (
|
||||
<div>
|
||||
<div className="p-2 m-2 bg-yellow-50 border border-yellow-200 rounded text-yellow-800 text-xs">
|
||||
⚠️ Error boundary triggered - rendering children anyway
|
||||
</div>
|
||||
{this.props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
// In production, just render children silently
|
||||
return this.props.children;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
|
||||
@@ -157,7 +157,7 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
|
||||
const stats = {
|
||||
totalProjects: projects.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,
|
||||
avgPerformance: (() => {
|
||||
// Only show real performance data, not defaults
|
||||
@@ -172,9 +172,9 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
|
||||
}, 0) / projectsWithPerf.length);
|
||||
})(),
|
||||
systemHealth: (systemStats?.status as string) || 'unknown',
|
||||
totalUsers: (analytics?.metrics?.totalUsers as number) || (analytics?.totalUsers as number) || 0,
|
||||
bounceRate: (analytics?.metrics?.bounceRate as number) || (analytics?.bounceRate as number) || 0,
|
||||
avgSessionDuration: (analytics?.metrics?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0
|
||||
totalUsers: ((analytics?.metrics as Record<string, unknown>)?.totalUsers as number) || (analytics?.totalUsers as number) || 0,
|
||||
bounceRate: ((analytics?.metrics as Record<string, unknown>)?.bounceRate as number) || (analytics?.bounceRate as number) || 0,
|
||||
avgSessionDuration: ((analytics?.metrics as Record<string, unknown>)?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -59,7 +59,7 @@ const ToastItem = ({ toast, onRemove }: ToastProps) => {
|
||||
const getColors = () => {
|
||||
switch (toast.type) {
|
||||
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':
|
||||
return 'bg-stone-50 border-red-200 text-red-800 shadow-md';
|
||||
case 'warning':
|
||||
@@ -291,7 +291,7 @@ export const ToastProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
{children}
|
||||
|
||||
{/* 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>
|
||||
{toasts.map((toast) => (
|
||||
<ToastItem
|
||||
|
||||
@@ -57,34 +57,55 @@ export const trackWebVitals = (metric: WebVitalsMetric) => {
|
||||
|
||||
// Track page load performance
|
||||
export const trackPageLoad = () => {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (typeof window === 'undefined' || typeof performance === 'undefined') return;
|
||||
|
||||
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;
|
||||
|
||||
if (navigation) {
|
||||
trackPerformance({
|
||||
name: 'page-load',
|
||||
value: navigation.loadEventEnd - navigation.fetchStart,
|
||||
url: window.location.pathname,
|
||||
timestamp: Date.now(),
|
||||
userAgent: navigator.userAgent,
|
||||
});
|
||||
try {
|
||||
const navigationEntries = performance.getEntriesByType('navigation');
|
||||
const navigation = navigationEntries[0] as PerformanceNavigationTiming | undefined;
|
||||
|
||||
if (navigation && navigation.loadEventEnd && navigation.fetchStart) {
|
||||
trackPerformance({
|
||||
name: 'page-load',
|
||||
value: navigation.loadEventEnd - navigation.fetchStart,
|
||||
url: window.location.pathname,
|
||||
timestamp: Date.now(),
|
||||
userAgent: navigator.userAgent,
|
||||
});
|
||||
|
||||
// Track individual timing phases
|
||||
trackEvent('page-timing', {
|
||||
dns: Math.round(navigation.domainLookupEnd - navigation.domainLookupStart),
|
||||
tcp: Math.round(navigation.connectEnd - navigation.connectStart),
|
||||
request: Math.round(navigation.responseStart - navigation.requestStart),
|
||||
response: Math.round(navigation.responseEnd - navigation.responseStart),
|
||||
dom: Math.round(navigation.domContentLoadedEventEnd - navigation.responseEnd),
|
||||
load: Math.round(navigation.loadEventEnd - navigation.domContentLoadedEventEnd),
|
||||
url: window.location.pathname,
|
||||
});
|
||||
// Track individual timing phases
|
||||
trackEvent('page-timing', {
|
||||
dns: navigation.domainLookupEnd && navigation.domainLookupStart
|
||||
? Math.round(navigation.domainLookupEnd - navigation.domainLookupStart)
|
||||
: 0,
|
||||
tcp: navigation.connectEnd && navigation.connectStart
|
||||
? Math.round(navigation.connectEnd - navigation.connectStart)
|
||||
: 0,
|
||||
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
|
||||
export const trackApiCall = (endpoint: string, duration: number, status: number) => {
|
||||
if (typeof window === 'undefined') return;
|
||||
trackEvent('api-call', {
|
||||
endpoint,
|
||||
duration: Math.round(duration),
|
||||
@@ -95,6 +116,7 @@ export const trackApiCall = (endpoint: string, duration: number, status: number)
|
||||
|
||||
// Track user interactions
|
||||
export const trackInteraction = (action: string, element?: string) => {
|
||||
if (typeof window === 'undefined') return;
|
||||
trackEvent('interaction', {
|
||||
action,
|
||||
element,
|
||||
@@ -104,6 +126,7 @@ export const trackInteraction = (action: string, element?: string) => {
|
||||
|
||||
// Track errors
|
||||
export const trackError = (error: string, context?: string) => {
|
||||
if (typeof window === 'undefined') return;
|
||||
trackEvent('error', {
|
||||
error,
|
||||
context,
|
||||
|
||||
@@ -13,104 +13,192 @@ interface Metric {
|
||||
|
||||
// Simple Web Vitals implementation (since we don't want to add external dependencies)
|
||||
const getCLS = (onPerfEntry: (metric: Metric) => void) => {
|
||||
let clsValue = 0;
|
||||
let sessionValue = 0;
|
||||
let sessionEntries: PerformanceEntry[] = [];
|
||||
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||
|
||||
try {
|
||||
let clsValue = 0;
|
||||
let sessionValue = 0;
|
||||
let sessionEntries: PerformanceEntry[] = [];
|
||||
|
||||
const observer = new PerformanceObserver((list) => {
|
||||
for (const entry of list.getEntries()) {
|
||||
if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) {
|
||||
const firstSessionEntry = sessionEntries[0];
|
||||
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
|
||||
const observer = new PerformanceObserver((list) => {
|
||||
try {
|
||||
for (const entry of list.getEntries()) {
|
||||
if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) {
|
||||
const firstSessionEntry = sessionEntries[0];
|
||||
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 && 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()}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionValue > clsValue) {
|
||||
clsValue = sessionValue;
|
||||
onPerfEntry({
|
||||
name: 'CLS',
|
||||
value: clsValue,
|
||||
delta: clsValue,
|
||||
id: `cls-${Date.now()}`,
|
||||
});
|
||||
} catch (error) {
|
||||
// Silently fail - CLS tracking is not critical
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.warn('CLS tracking error:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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 observer = new PerformanceObserver((list) => {
|
||||
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()}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||
|
||||
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 });
|
||||
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 observer = new PerformanceObserver((list) => {
|
||||
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()}`,
|
||||
});
|
||||
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||
|
||||
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 });
|
||||
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 observer = new PerformanceObserver((list) => {
|
||||
const entries = list.getEntries();
|
||||
const lastEntry = entries[entries.length - 1];
|
||||
|
||||
onPerfEntry({
|
||||
name: 'LCP',
|
||||
value: lastEntry.startTime,
|
||||
delta: lastEntry.startTime,
|
||||
id: `lcp-${Date.now()}`,
|
||||
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||
|
||||
try {
|
||||
const observer = new PerformanceObserver((list) => {
|
||||
try {
|
||||
const entries = list.getEntries();
|
||||
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 observer = new PerformanceObserver((list) => {
|
||||
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()}`,
|
||||
});
|
||||
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
|
||||
|
||||
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 });
|
||||
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
|
||||
@@ -118,11 +206,14 @@ export const useWebVitals = () => {
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
// Store web vitals for batch sending
|
||||
const webVitals: Record<string, number> = {};
|
||||
const path = window.location.pathname;
|
||||
const projectMatch = path.match(/\/projects\/([^\/]+)/);
|
||||
const projectId = projectMatch ? projectMatch[1] : null;
|
||||
// Wrap everything in try-catch to prevent errors from breaking the app
|
||||
try {
|
||||
// Store web vitals for batch sending
|
||||
const webVitals: Record<string, number> = {};
|
||||
const path = window.location.pathname;
|
||||
const projectMatch = path.match(/\/projects\/([^\/]+)/);
|
||||
const projectId = projectMatch ? projectMatch[1] : null;
|
||||
const observers: PerformanceObserver[] = [];
|
||||
|
||||
const sendWebVitals = async () => {
|
||||
if (Object.keys(webVitals).length >= 3) { // Wait for at least FCP, LCP, CLS
|
||||
@@ -156,7 +247,7 @@ export const useWebVitals = () => {
|
||||
};
|
||||
|
||||
// Track Core Web Vitals
|
||||
getCLS((metric) => {
|
||||
const clsObserver = getCLS((metric) => {
|
||||
webVitals.CLS = metric.value;
|
||||
trackWebVitals({
|
||||
...metric,
|
||||
@@ -165,8 +256,9 @@ export const useWebVitals = () => {
|
||||
});
|
||||
sendWebVitals();
|
||||
});
|
||||
if (clsObserver) observers.push(clsObserver);
|
||||
|
||||
getFID((metric) => {
|
||||
const fidObserver = getFID((metric) => {
|
||||
webVitals.FID = metric.value;
|
||||
trackWebVitals({
|
||||
...metric,
|
||||
@@ -175,8 +267,9 @@ export const useWebVitals = () => {
|
||||
});
|
||||
sendWebVitals();
|
||||
});
|
||||
if (fidObserver) observers.push(fidObserver);
|
||||
|
||||
getFCP((metric) => {
|
||||
const fcpObserver = getFCP((metric) => {
|
||||
webVitals.FCP = metric.value;
|
||||
trackWebVitals({
|
||||
...metric,
|
||||
@@ -185,8 +278,9 @@ export const useWebVitals = () => {
|
||||
});
|
||||
sendWebVitals();
|
||||
});
|
||||
if (fcpObserver) observers.push(fcpObserver);
|
||||
|
||||
getLCP((metric) => {
|
||||
const lcpObserver = getLCP((metric) => {
|
||||
webVitals.LCP = metric.value;
|
||||
trackWebVitals({
|
||||
...metric,
|
||||
@@ -195,8 +289,9 @@ export const useWebVitals = () => {
|
||||
});
|
||||
sendWebVitals();
|
||||
});
|
||||
if (lcpObserver) observers.push(lcpObserver);
|
||||
|
||||
getTTFB((metric) => {
|
||||
const ttfbObserver = getTTFB((metric) => {
|
||||
webVitals.TTFB = metric.value;
|
||||
trackWebVitals({
|
||||
...metric,
|
||||
@@ -205,6 +300,7 @@ export const useWebVitals = () => {
|
||||
});
|
||||
sendWebVitals();
|
||||
});
|
||||
if (ttfbObserver) observers.push(ttfbObserver);
|
||||
|
||||
// Track page load performance
|
||||
const handleLoad = () => {
|
||||
@@ -225,8 +321,28 @@ export const useWebVitals = () => {
|
||||
window.addEventListener('load', handleLoad);
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('load', handleLoad);
|
||||
};
|
||||
return () => {
|
||||
// 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