Compare commits
7 Commits
d5445c2282
...
backup5
| Author | SHA1 | Date | |
|---|---|---|---|
| 15655e3987 | |||
|
|
5263fa6834 | ||
|
|
923c86a3b3 | ||
| d8b3864411 | |||
|
|
4aaffe99c7 | ||
| 194cbd6ca8 | |||
|
|
a11da5a977 |
@@ -19,7 +19,7 @@ GOOGLE_CLIENT_ID=
|
|||||||
# Server Configuration
|
# Server Configuration
|
||||||
PORT=3001
|
PORT=3001
|
||||||
API_URL=http://localhost:3001
|
API_URL=http://localhost:3001
|
||||||
FRONTEND_URL=http://localhost:3002
|
FRONTEND_URL=http://localhost:3019
|
||||||
|
|
||||||
# Revalidation secret (shared with frontend for on-demand cache revalidation)
|
# Revalidation secret (shared with frontend for on-demand cache revalidation)
|
||||||
# Must match the REVALIDATE_SECRET in frontend/.env
|
# Must match the REVALIDATE_SECRET in frontend/.env
|
||||||
|
|||||||
22
backend/src/lib/revalidate.ts
Normal file
22
backend/src/lib/revalidate.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Trigger frontend cache revalidation (fire-and-forget)
|
||||||
|
// Revalidates both the sitemap and the next-event data (homepage, llms.txt)
|
||||||
|
export function revalidateFrontendCache() {
|
||||||
|
const frontendUrl = process.env.FRONTEND_URL || 'http://localhost:3002';
|
||||||
|
const secret = process.env.REVALIDATE_SECRET;
|
||||||
|
if (!secret) {
|
||||||
|
console.warn('REVALIDATE_SECRET not set, skipping frontend revalidation');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch(`${frontendUrl}/api/revalidate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ secret, tag: ['events-sitemap', 'next-event'] }),
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (!res.ok) console.error('Frontend revalidation failed:', res.status);
|
||||||
|
else console.log('Frontend revalidation triggered (sitemap + next-event)');
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Frontend revalidation error:', err.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { db, dbGet, dbAll, events, tickets, payments, eventPaymentOverrides, ema
|
|||||||
import { eq, desc, and, gte, sql } from 'drizzle-orm';
|
import { eq, desc, and, gte, sql } from 'drizzle-orm';
|
||||||
import { requireAuth, getAuthUser } from '../lib/auth.js';
|
import { requireAuth, getAuthUser } from '../lib/auth.js';
|
||||||
import { generateId, getNow, convertBooleansForDb, toDbDate, calculateAvailableSeats } from '../lib/utils.js';
|
import { generateId, getNow, convertBooleansForDb, toDbDate, calculateAvailableSeats } from '../lib/utils.js';
|
||||||
|
import { revalidateFrontendCache } from '../lib/revalidate.js';
|
||||||
|
|
||||||
interface UserContext {
|
interface UserContext {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -15,29 +16,6 @@ interface UserContext {
|
|||||||
|
|
||||||
const eventsRouter = new Hono<{ Variables: { user: UserContext } }>();
|
const eventsRouter = new Hono<{ Variables: { user: UserContext } }>();
|
||||||
|
|
||||||
// Trigger frontend cache revalidation (fire-and-forget)
|
|
||||||
// Revalidates both the sitemap and the next-event data (homepage, llms.txt)
|
|
||||||
function revalidateFrontendCache() {
|
|
||||||
const frontendUrl = process.env.FRONTEND_URL || 'http://localhost:3002';
|
|
||||||
const secret = process.env.REVALIDATE_SECRET;
|
|
||||||
if (!secret) {
|
|
||||||
console.warn('REVALIDATE_SECRET not set, skipping frontend revalidation');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fetch(`${frontendUrl}/api/revalidate`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ secret, tag: ['events-sitemap', 'next-event'] }),
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
if (!res.ok) console.error('Frontend revalidation failed:', res.status);
|
|
||||||
else console.log('Frontend revalidation triggered (sitemap + next-event)');
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error('Frontend revalidation error:', err.message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to normalize event data for API response
|
// Helper to normalize event data for API response
|
||||||
// PostgreSQL decimal returns strings, booleans are stored as integers
|
// PostgreSQL decimal returns strings, booleans are stored as integers
|
||||||
function normalizeEvent(event: any) {
|
function normalizeEvent(event: any) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { db, dbGet, siteSettings, events } from '../db/index.js';
|
|||||||
import { eq, and, gte } from 'drizzle-orm';
|
import { eq, and, gte } from 'drizzle-orm';
|
||||||
import { requireAuth } from '../lib/auth.js';
|
import { requireAuth } from '../lib/auth.js';
|
||||||
import { generateId, getNow, toDbBool } from '../lib/utils.js';
|
import { generateId, getNow, toDbBool } from '../lib/utils.js';
|
||||||
|
import { revalidateFrontendCache } from '../lib/revalidate.js';
|
||||||
|
|
||||||
interface UserContext {
|
interface UserContext {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -172,6 +173,11 @@ siteSettingsRouter.put('/', requireAuth(['admin']), zValidator('json', updateSit
|
|||||||
(db as any).select().from(siteSettings).where(eq((siteSettings as any).id, existing.id))
|
(db as any).select().from(siteSettings).where(eq((siteSettings as any).id, existing.id))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Revalidate frontend cache if featured event changed
|
||||||
|
if (data.featuredEventId !== undefined) {
|
||||||
|
revalidateFrontendCache();
|
||||||
|
}
|
||||||
|
|
||||||
return c.json({ settings: updated, message: 'Settings updated successfully' });
|
return c.json({ settings: updated, message: 'Settings updated successfully' });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -216,6 +222,9 @@ siteSettingsRouter.put('/featured-event', requireAuth(['admin']), zValidator('js
|
|||||||
|
|
||||||
await (db as any).insert(siteSettings).values(newSettings);
|
await (db as any).insert(siteSettings).values(newSettings);
|
||||||
|
|
||||||
|
// Revalidate frontend cache so homepage shows the updated featured event
|
||||||
|
revalidateFrontendCache();
|
||||||
|
|
||||||
return c.json({ featuredEventId: eventId, message: eventId ? 'Event set as featured' : 'Featured event removed' });
|
return c.json({ featuredEventId: eventId, message: eventId ? 'Event set as featured' : 'Featured event removed' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +238,9 @@ siteSettingsRouter.put('/featured-event', requireAuth(['admin']), zValidator('js
|
|||||||
})
|
})
|
||||||
.where(eq((siteSettings as any).id, existing.id));
|
.where(eq((siteSettings as any).id, existing.id));
|
||||||
|
|
||||||
|
// Revalidate frontend cache so homepage shows the updated featured event
|
||||||
|
revalidateFrontendCache();
|
||||||
|
|
||||||
return c.json({ featuredEventId: eventId, message: eventId ? 'Event set as featured' : 'Featured event removed' });
|
return c.json({ featuredEventId: eventId, message: eventId ? 'Event set as featured' : 'Featured event removed' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ Type=simple
|
|||||||
User=spanglish
|
User=spanglish
|
||||||
Group=spanglish
|
Group=spanglish
|
||||||
WorkingDirectory=/home/spanglish/Spanglish/backend
|
WorkingDirectory=/home/spanglish/Spanglish/backend
|
||||||
|
EnvironmentFile=/home/spanglish/Spanglish/backend/.env
|
||||||
Environment=NODE_ENV=production
|
Environment=NODE_ENV=production
|
||||||
Environment=PORT=3018
|
Environment=PORT=3018
|
||||||
EnvironmentFile=/home/spanglish/Spanglish/backend/.env
|
|
||||||
ExecStart=/usr/bin/node dist/index.js
|
ExecStart=/usr/bin/node dist/index.js
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
QrCodeIcon,
|
QrCodeIcon,
|
||||||
CheckCircleIcon,
|
CheckCircleIcon,
|
||||||
XCircleIcon,
|
XCircleIcon,
|
||||||
|
XMarkIcon,
|
||||||
MagnifyingGlassIcon,
|
MagnifyingGlassIcon,
|
||||||
ArrowPathIcon,
|
ArrowPathIcon,
|
||||||
ClockIcon,
|
ClockIcon,
|
||||||
@@ -76,86 +77,135 @@ function vibrate(pattern: number | number[]) {
|
|||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Stop all tracks on a media stream ───────────────────────
|
||||||
|
function stopAllTracks() {
|
||||||
|
try {
|
||||||
|
// Find all video elements and stop their streams
|
||||||
|
document.querySelectorAll('video').forEach((video) => {
|
||||||
|
const stream = video.srcObject as MediaStream | null;
|
||||||
|
if (stream) {
|
||||||
|
stream.getTracks().forEach((track) => track.stop());
|
||||||
|
video.srcObject = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
// ─── QR Scanner Component ────────────────────────────────────
|
// ─── QR Scanner Component ────────────────────────────────────
|
||||||
|
// This component fully mounts/unmounts — use a key prop externally
|
||||||
|
// to force a fresh instance when the scan tab becomes active.
|
||||||
function QRScanner({
|
function QRScanner({
|
||||||
onScan,
|
onScan,
|
||||||
isActive,
|
onError,
|
||||||
onActiveChange,
|
|
||||||
}: {
|
}: {
|
||||||
onScan: (code: string) => void;
|
onScan: (code: string) => void;
|
||||||
isActive: boolean;
|
onError: () => void;
|
||||||
onActiveChange: (active: boolean) => void;
|
|
||||||
}) {
|
}) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const scannerRef = useRef<any>(null);
|
const scannerRef = useRef<any>(null);
|
||||||
const scannerElementId = useRef(`qr-scanner-${Math.random().toString(36).substr(2, 9)}`);
|
const mountedRef = useRef(true);
|
||||||
|
const elementId = useRef(`qr-scanner-${Date.now()}`);
|
||||||
const [facingMode, setFacingMode] = useState<'environment' | 'user'>('environment');
|
const [facingMode, setFacingMode] = useState<'environment' | 'user'>('environment');
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
// Full cleanup helper
|
||||||
if (containerRef.current && !document.getElementById(scannerElementId.current)) {
|
const destroyScanner = useCallback(async () => {
|
||||||
const scannerDiv = document.createElement('div');
|
if (scannerRef.current) {
|
||||||
scannerDiv.id = scannerElementId.current;
|
try { await scannerRef.current.stop(); } catch {}
|
||||||
scannerDiv.style.width = '100%';
|
try { scannerRef.current.clear(); } catch {}
|
||||||
containerRef.current.appendChild(scannerDiv);
|
scannerRef.current = null;
|
||||||
}
|
}
|
||||||
return () => {
|
stopAllTracks();
|
||||||
if (scannerRef.current) {
|
|
||||||
try { scannerRef.current.stop().catch(() => {}); } catch {}
|
|
||||||
scannerRef.current = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Start scanner on mount, destroy on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
mountedRef.current = true;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
const startScanner = async () => {
|
const init = async () => {
|
||||||
const elementId = scannerElementId.current;
|
const container = containerRef.current;
|
||||||
const element = document.getElementById(elementId);
|
if (!container) return;
|
||||||
if (!element) return;
|
|
||||||
|
// Create a fresh div for the scanner
|
||||||
|
const id = elementId.current;
|
||||||
|
container.innerHTML = '';
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.id = id;
|
||||||
|
div.style.width = '100%';
|
||||||
|
div.style.height = '100%';
|
||||||
|
container.appendChild(div);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { Html5Qrcode } = await import('html5-qrcode');
|
const { Html5Qrcode } = await import('html5-qrcode');
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (scannerRef.current) {
|
|
||||||
try { await scannerRef.current.stop(); } catch {}
|
|
||||||
scannerRef.current = null;
|
|
||||||
}
|
|
||||||
if (cancelled) return;
|
|
||||||
|
|
||||||
const scanner = new Html5Qrcode(elementId);
|
const scanner = new Html5Qrcode(id);
|
||||||
scannerRef.current = scanner;
|
scannerRef.current = scanner;
|
||||||
|
|
||||||
await scanner.start(
|
await scanner.start(
|
||||||
{ facingMode },
|
{ facingMode },
|
||||||
{ fps: 10, qrbox: { width: 250, height: 250 }, aspectRatio: 1 },
|
{ fps: 10, qrbox: { width: 250, height: 250 }, aspectRatio: 1 },
|
||||||
(decodedText: string) => onScan(decodedText),
|
(decodedText: string) => {
|
||||||
|
if (mountedRef.current) onScan(decodedText);
|
||||||
|
},
|
||||||
() => {}
|
() => {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (cancelled) {
|
||||||
|
await destroyScanner();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force layout recalculation after camera starts
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (container) {
|
||||||
|
container.style.display = 'none';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||||
|
container.offsetHeight; // force reflow
|
||||||
|
container.style.display = '';
|
||||||
|
}
|
||||||
|
if (mountedRef.current) setReady(true);
|
||||||
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Scanner error:', error);
|
console.error('Scanner error:', error);
|
||||||
if (!cancelled) {
|
if (!cancelled && mountedRef.current) {
|
||||||
toast.error('Failed to start camera. Check permissions.');
|
toast.error('Failed to start camera. Check permissions.');
|
||||||
onActiveChange(false);
|
onError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopScanner = async () => {
|
init();
|
||||||
if (scannerRef.current) {
|
|
||||||
try { await scannerRef.current.stop(); } catch {}
|
return () => {
|
||||||
scannerRef.current = null;
|
cancelled = true;
|
||||||
|
mountedRef.current = false;
|
||||||
|
destroyScanner();
|
||||||
|
};
|
||||||
|
}, [facingMode]); // restart when camera flips
|
||||||
|
|
||||||
|
// Handle browser visibility change (suspend/resume)
|
||||||
|
useEffect(() => {
|
||||||
|
const handleVisibility = () => {
|
||||||
|
if (document.visibilityState === 'hidden') {
|
||||||
|
destroyScanner();
|
||||||
|
} else if (document.visibilityState === 'visible' && mountedRef.current) {
|
||||||
|
// Re-trigger by flipping facingMode back-and-forth (forces useEffect re-run)
|
||||||
|
setFacingMode((prev) => {
|
||||||
|
// Toggle and toggle back to trigger the effect
|
||||||
|
const temp = prev === 'environment' ? 'user' : 'environment';
|
||||||
|
setTimeout(() => {
|
||||||
|
if (mountedRef.current) setFacingMode(prev);
|
||||||
|
}, 100);
|
||||||
|
return temp;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isActive) {
|
document.addEventListener('visibilitychange', handleVisibility);
|
||||||
startScanner();
|
return () => document.removeEventListener('visibilitychange', handleVisibility);
|
||||||
} else {
|
}, [destroyScanner]);
|
||||||
stopScanner();
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => { cancelled = true; };
|
|
||||||
}, [isActive, facingMode, onScan, onActiveChange]);
|
|
||||||
|
|
||||||
const switchCamera = () => {
|
const switchCamera = () => {
|
||||||
setFacingMode((prev) => (prev === 'environment' ? 'user' : 'environment'));
|
setFacingMode((prev) => (prev === 'environment' ? 'user' : 'environment'));
|
||||||
@@ -163,8 +213,11 @@ function QRScanner({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full bg-black flex-1 min-h-0 overflow-hidden">
|
<div className="relative w-full bg-black flex-1 min-h-0 overflow-hidden">
|
||||||
<div ref={containerRef} className="w-full h-full [&_video]:!object-cover [&_video]:!h-full" />
|
<div
|
||||||
{isActive && (
|
ref={containerRef}
|
||||||
|
className="w-full h-full [&_video]:!object-cover [&_video]:!h-full [&_video]:!w-full"
|
||||||
|
/>
|
||||||
|
{ready && (
|
||||||
<button
|
<button
|
||||||
onClick={switchCamera}
|
onClick={switchCamera}
|
||||||
className="absolute top-3 right-3 z-10 bg-black/50 backdrop-blur-sm text-white p-2.5 rounded-full active:scale-95 transition-transform"
|
className="absolute top-3 right-3 z-10 bg-black/50 backdrop-blur-sm text-white p-2.5 rounded-full active:scale-95 transition-transform"
|
||||||
@@ -173,7 +226,7 @@ function QRScanner({
|
|||||||
<VideoCameraIcon className="w-5 h-5" />
|
<VideoCameraIcon className="w-5 h-5" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{!isActive && (
|
{!ready && (
|
||||||
<div className="absolute inset-0 flex items-center justify-center text-gray-400">
|
<div className="absolute inset-0 flex items-center justify-center text-gray-400">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<QrCodeIcon className="w-16 h-16 mx-auto mb-2 opacity-30" />
|
<QrCodeIcon className="w-16 h-16 mx-auto mb-2 opacity-30" />
|
||||||
@@ -189,15 +242,27 @@ function QRScanner({
|
|||||||
function ValidTicketScreen({
|
function ValidTicketScreen({
|
||||||
validation,
|
validation,
|
||||||
onConfirmCheckin,
|
onConfirmCheckin,
|
||||||
|
onClose,
|
||||||
checkingIn,
|
checkingIn,
|
||||||
}: {
|
}: {
|
||||||
validation: TicketValidationResult;
|
validation: TicketValidationResult;
|
||||||
onConfirmCheckin: () => void;
|
onConfirmCheckin: () => void;
|
||||||
|
onClose: () => void;
|
||||||
checkingIn: boolean;
|
checkingIn: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 bg-emerald-600 flex flex-col animate-in fade-in duration-200">
|
<div className="fixed inset-0 z-50 bg-emerald-600 flex flex-col animate-in fade-in duration-200">
|
||||||
<div className="flex-1 flex flex-col items-center justify-center px-6 text-white">
|
{/* Close button (dismiss without check-in) */}
|
||||||
|
<div className="flex justify-end p-4">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="p-2 rounded-full bg-white/20 text-white active:scale-95 transition-transform"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<XMarkIcon className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 flex flex-col items-center justify-center px-6 -mt-14 text-white">
|
||||||
<div className="w-24 h-24 rounded-full bg-white/20 flex items-center justify-center mb-6">
|
<div className="w-24 h-24 rounded-full bg-white/20 flex items-center justify-center mb-6">
|
||||||
<CheckCircleIcon className="w-16 h-16 text-white" />
|
<CheckCircleIcon className="w-16 h-16 text-white" />
|
||||||
</div>
|
</div>
|
||||||
@@ -581,7 +646,7 @@ export default function AdminScannerPage() {
|
|||||||
const [activeTab, setActiveTab] = useState<ActiveTab>('scan');
|
const [activeTab, setActiveTab] = useState<ActiveTab>('scan');
|
||||||
|
|
||||||
// Scanner state
|
// Scanner state
|
||||||
const [cameraActive, setCameraActive] = useState(false);
|
const [scannerKey, setScannerKey] = useState(0); // increment to force remount
|
||||||
const [scanResult, setScanResult] = useState<ScanResultData>({ state: 'idle' });
|
const [scanResult, setScanResult] = useState<ScanResultData>({ state: 'idle' });
|
||||||
const [lastScannedCode, setLastScannedCode] = useState('');
|
const [lastScannedCode, setLastScannedCode] = useState('');
|
||||||
const [checkingIn, setCheckingIn] = useState(false);
|
const [checkingIn, setCheckingIn] = useState(false);
|
||||||
@@ -638,21 +703,8 @@ export default function AdminScannerPage() {
|
|||||||
loadStats();
|
loadStats();
|
||||||
}, [selectedEventId]);
|
}, [selectedEventId]);
|
||||||
|
|
||||||
// Auto-start camera on page load (Scan tab)
|
// When scan tab becomes active again or scan result is dismissed, bump key to remount scanner
|
||||||
useEffect(() => {
|
const scannerActive = activeTab === 'scan' && scanResult.state === 'idle' && !loading;
|
||||||
if (!loading && activeTab === 'scan') {
|
|
||||||
setCameraActive(true);
|
|
||||||
}
|
|
||||||
}, [loading, activeTab]);
|
|
||||||
|
|
||||||
// Pause camera when switching away from scan tab
|
|
||||||
useEffect(() => {
|
|
||||||
if (activeTab !== 'scan') {
|
|
||||||
setCameraActive(false);
|
|
||||||
} else if (scanResult.state === 'idle') {
|
|
||||||
setCameraActive(true);
|
|
||||||
}
|
|
||||||
}, [activeTab, scanResult.state]);
|
|
||||||
|
|
||||||
// Validate ticket
|
// Validate ticket
|
||||||
const validateTicket = useCallback(async (code: string) => {
|
const validateTicket = useCallback(async (code: string) => {
|
||||||
@@ -690,7 +742,6 @@ export default function AdminScannerPage() {
|
|||||||
if (decodedText === lastScannedCodeRef.current) return;
|
if (decodedText === lastScannedCodeRef.current) return;
|
||||||
lastScannedCodeRef.current = decodedText;
|
lastScannedCodeRef.current = decodedText;
|
||||||
setLastScannedCode(decodedText);
|
setLastScannedCode(decodedText);
|
||||||
setCameraActive(false);
|
|
||||||
|
|
||||||
let code = decodedText;
|
let code = decodedText;
|
||||||
const urlMatch = decodedText.match(/\/ticket\/([a-zA-Z0-9-_]+)/);
|
const urlMatch = decodedText.match(/\/ticket\/([a-zA-Z0-9-_]+)/);
|
||||||
@@ -768,12 +819,12 @@ export default function AdminScannerPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset scan state
|
// Reset scan state — bump key so scanner fully remounts
|
||||||
const resetScan = () => {
|
const resetScan = () => {
|
||||||
setScanResult({ state: 'idle' });
|
setScanResult({ state: 'idle' });
|
||||||
setLastScannedCode('');
|
setLastScannedCode('');
|
||||||
lastScannedCodeRef.current = '';
|
lastScannedCodeRef.current = '';
|
||||||
if (activeTab === 'scan') setCameraActive(true);
|
setScannerKey((k) => k + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get selected event name
|
// Get selected event name
|
||||||
@@ -788,7 +839,7 @@ export default function AdminScannerPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-950 flex flex-col h-screen max-h-screen overflow-hidden">
|
<div className="bg-gray-950 flex flex-col overflow-hidden" style={{ height: '100dvh' }}>
|
||||||
{/* ── Sticky Header ── */}
|
{/* ── Sticky Header ── */}
|
||||||
<header className="flex-shrink-0 bg-gray-900 border-b border-gray-800 px-4 py-3 safe-area-top">
|
<header className="flex-shrink-0 bg-gray-900 border-b border-gray-800 px-4 py-3 safe-area-top">
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex items-center justify-between gap-3">
|
||||||
@@ -864,14 +915,17 @@ export default function AdminScannerPage() {
|
|||||||
|
|
||||||
{/* ── Tab Content ── */}
|
{/* ── Tab Content ── */}
|
||||||
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||||
{/* SCAN TAB */}
|
{/* SCAN TAB — scanner fully unmounts when not active */}
|
||||||
{activeTab === 'scan' && (
|
{scannerActive && (
|
||||||
<QRScanner
|
<QRScanner
|
||||||
isActive={cameraActive && scanResult.state === 'idle'}
|
key={scannerKey}
|
||||||
onScan={handleScan}
|
onScan={handleScan}
|
||||||
onActiveChange={setCameraActive}
|
onError={() => {}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{activeTab === 'scan' && !scannerActive && scanResult.state !== 'idle' && (
|
||||||
|
<div className="flex-1 bg-black" />
|
||||||
|
)}
|
||||||
|
|
||||||
{/* SEARCH TAB */}
|
{/* SEARCH TAB */}
|
||||||
{activeTab === 'search' && (
|
{activeTab === 'search' && (
|
||||||
@@ -889,6 +943,7 @@ export default function AdminScannerPage() {
|
|||||||
<ValidTicketScreen
|
<ValidTicketScreen
|
||||||
validation={scanResult.validation}
|
validation={scanResult.validation}
|
||||||
onConfirmCheckin={handleCheckin}
|
onConfirmCheckin={handleCheckin}
|
||||||
|
onClose={resetScan}
|
||||||
checkingIn={checkingIn}
|
checkingIn={checkingIn}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ interface LlmsEvent {
|
|||||||
async function getNextUpcomingEvent(): Promise<LlmsEvent | null> {
|
async function getNextUpcomingEvent(): Promise<LlmsEvent | null> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${apiUrl}/api/events/next/upcoming`, {
|
const response = await fetch(`${apiUrl}/api/events/next/upcoming`, {
|
||||||
next: { tags: ['next-event'] },
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (!response.ok) return null;
|
if (!response.ok) return null;
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -41,7 +41,7 @@ async function getNextUpcomingEvent(): Promise<LlmsEvent | null> {
|
|||||||
async function getUpcomingEvents(): Promise<LlmsEvent[]> {
|
async function getUpcomingEvents(): Promise<LlmsEvent[]> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${apiUrl}/api/events?status=published&upcoming=true`, {
|
const response = await fetch(`${apiUrl}/api/events?status=published&upcoming=true`, {
|
||||||
next: { tags: ['next-event'] },
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (!response.ok) return [];
|
if (!response.ok) return [];
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -115,7 +115,7 @@ function getEventStatus(event: LlmsEvent): string {
|
|||||||
async function getHomepageFaqs(): Promise<LlmsFaq[]> {
|
async function getHomepageFaqs(): Promise<LlmsFaq[]> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${apiUrl}/api/faq?homepage=true`, {
|
const response = await fetch(`${apiUrl}/api/faq?homepage=true`, {
|
||||||
next: { revalidate: 3600 },
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (!response.ok) return [];
|
if (!response.ok) return [];
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -128,6 +128,8 @@ async function getHomepageFaqs(): Promise<LlmsFaq[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const [nextEvent, upcomingEvents, faqs] = await Promise.all([
|
const [nextEvent, upcomingEvents, faqs] = await Promise.all([
|
||||||
getNextUpcomingEvent(),
|
getNextUpcomingEvent(),
|
||||||
|
|||||||
Reference in New Issue
Block a user