feat: add custom date range picker, fix country click highlight on map
- Analytics default interval changed to 1h - Add 'Custom' toggle option with datetime-local pickers (pre-filled to last 24h) - Refactor analytics-db: buildWhere now takes from/to unix timestamps instead of Interval - Export INTERVAL_SECONDS from analytics-db for route reuse - All 6 API routes accept from/to params (fallback to interval if absent) - Timeline bucket size computed from duration rather than hardcoded per interval - Fix map country click highlight: bake isSelected into GeoJSON features (data-driven) instead of relying on Layer filter prop updates (unreliable in react-map-gl v8) - Split highlight into countries-selected (data-driven) and countries-hover (filter-driven) - Show tooltip at country centroid when selected via table, hover takes precedence Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { requireUser } from '@/src/lib/auth';
|
||||
import { getAnalyticsUserAgents, type Interval } from '@/src/lib/analytics-db';
|
||||
import { getAnalyticsUserAgents, INTERVAL_SECONDS } from '@/src/lib/analytics-db';
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
await requireUser();
|
||||
const { searchParams } = req.nextUrl;
|
||||
const interval = (searchParams.get('interval') ?? '24h') as Interval;
|
||||
const host = searchParams.get('host') ?? 'all';
|
||||
const data = await getAnalyticsUserAgents(interval, host);
|
||||
const { from, to } = resolveRange(searchParams);
|
||||
const data = await getAnalyticsUserAgents(from, to, host);
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
function resolveRange(params: URLSearchParams): { from: number; to: number } {
|
||||
const fromParam = params.get('from');
|
||||
const toParam = params.get('to');
|
||||
if (fromParam && toParam) {
|
||||
return { from: parseInt(fromParam, 10), to: parseInt(toParam, 10) };
|
||||
}
|
||||
const interval = params.get('interval') ?? '1h';
|
||||
const to = Math.floor(Date.now() / 1000);
|
||||
const from = to - (INTERVAL_SECONDS[interval as keyof typeof INTERVAL_SECONDS] ?? INTERVAL_SECONDS['1h']);
|
||||
return { from, to };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user