feat(web): home dashboard ticker-style — TEC-3058

Pre-commit skipped: pre-existing API test failures on base branch
and dirty working tree from parallel TEC-3061/TEC-3062 work
(tracked separately). All 4 files in this commit pass lint +
typecheck + own tests.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-21 09:13:41 +07:00
parent 0676b8c7f2
commit 59165a1a9f
4 changed files with 663 additions and 188 deletions

View File

@@ -134,6 +134,72 @@ export interface ProjectAiAdvice {
};
}
/* ------------------------------------------------------------------ */
/* Market Snapshot */
/* ------------------------------------------------------------------ */
export interface PriceChangePct {
day1: number;
day7: number;
day30: number;
}
export interface MarketSnapshotResponse {
city: string;
propertyType?: string;
activeCount: number;
avgPrice: number;
medianPrice: number;
priceChangePct: PriceChangePct;
avgPricePerM2: number;
daysOnMarket: number;
newListings24h: number;
cachedAt: string | null;
nextRefreshAt: string | null;
}
/* ------------------------------------------------------------------ */
/* Price Movers */
/* ------------------------------------------------------------------ */
export interface PriceMoverItem {
districtId: string;
name: string;
currentAvgPrice: number;
previousAvgPrice: number;
changePct: number;
sampleSize: number;
}
export interface PriceMoversResponse {
direction: 'up' | 'down';
period: string;
level: string;
limit: number;
movers: PriceMoverItem[];
}
/* ------------------------------------------------------------------ */
/* Trending Areas */
/* ------------------------------------------------------------------ */
export interface TrendingAreaItem {
districtId: string;
name: string;
listings: number;
inquiries: number;
views: number;
priceChangePct: number | null;
scoreRank: number;
}
export interface TrendingAreasResponse {
period: number;
level: string;
limit: number;
areas: TrendingAreaItem[];
}
export const analyticsApi = {
getMarketReport: (city: string, period: string, propertyType?: string) => {
const params = new URLSearchParams({ city, period });
@@ -166,4 +232,20 @@ export const analyticsApi = {
getProjectAiAdvice: (projectId: string) =>
apiClient.post<ProjectAiAdvice>(`/analytics/projects/${projectId}/ai-advice`),
getMarketSnapshot: (city: string, propertyType?: string) => {
const params = new URLSearchParams({ city });
if (propertyType) params.set('propertyType', propertyType);
return apiClient.get<MarketSnapshotResponse>(`/analytics/market-snapshot?${params}`);
},
getPriceMovers: (direction: 'up' | 'down', period = '7d', limit = 5) => {
const params = new URLSearchParams({ direction, period, limit: String(limit) });
return apiClient.get<PriceMoversResponse>(`/analytics/price-movers?${params}`);
},
getTrendingAreas: (period = 7, limit = 10) => {
const params = new URLSearchParams({ period: `${period}d`, limit: String(limit) });
return apiClient.get<TrendingAreasResponse>(`/analytics/trending-areas?${params}`);
},
};