Многоагентный аудит + имплементация: один воркер на файл, точечные правки. Верификация: py_compile (47/47 .py) + tsc --noEmit (0 ошибок). Unit-тесты не прогонялись (окружение не поднято: rollup native dep / нет pytest-venv). Полностью исправлено (169): #1336, #1337, #1339, #1340, #1341, #1342, #1343, #1345, #1346, #1348, #1349, #1350, #1351, #1354, #1356, #1358, #1359, #1360, #1362, #1364, #1365, #1366, #1367, #1368, #1369, #1370, #1371, #1372, #1373, #1374, #1375, #1376, #1377, #1378, #1379, #1380, #1381, #1382, #1384, #1385, #1386, #1387, #1388, #1389, #1390, #1391, #1392, #1394, #1395, #1396, #1397, #1399, #1400, #1401, #1402, #1403, #1404, #1408, #1409, #1410, #1411, #1412, #1413, #1414, #1415, #1416, #1417, #1418, #1420, #1423, #1425, #1426, #1427, #1428, #1429, #1430, #1431, #1432, #1433, #1434, #1435, #1437, #1438, #1439, #1440, #1441, #1442, #1443, #1444, #1445, #1446, #1447, #1448, #1449, #1450, #1451, #1452, #1453, #1454, #1455, #1456, #1457, #1458, #1459, #1460, #1461, #1462, #1463, #1464, #1465, #1466, #1467, #1468, #1469, #1471, #1472, #1473, #1474, #1476, #1478, #1479, #1481, #1482, #1483, #1484, #1485, #1487, #1488, #1489, #1490, #1491, #1492, #1493, #1494, #1495, #1496, #1497, #1499, #1500, #1501, #1502, #1504, #1505, #1506, #1507, #1510, #1514, #1515, #1516, #1517, #1518, #1519, #1521, #1522, #1523, #1524, #1525, #1526, #1527, #1528, #1529, #1531, #1532, #1533, #1534, #1535, #1536, #1537, #1538 Частично (9, in-file часть, остаток cross-file): #1361, #1419, #1422, #1424, #1470, #1475, #1477, #1480, #1498 Требуют cross-file (3, не тронуты): #1338, #1363, #1421 Пропущено (1): #1539 Не входило в партию: 22 needs-Leha issue (нужны решения владельца). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
284 lines
8.1 KiB
TypeScript
284 lines
8.1 KiB
TypeScript
"use client";
|
||
|
||
import { useState } from "react";
|
||
|
||
import type { AnalogLot } from "@/types/trade-in";
|
||
|
||
/** XSS prevention: only allow http/https/relative src */
|
||
function safeImgSrc(url: string | null): string | null {
|
||
if (!url) return null;
|
||
if (
|
||
url.startsWith("https://") ||
|
||
url.startsWith("http://") ||
|
||
url.startsWith("/")
|
||
) {
|
||
return url;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
function fmtRub(value: number): string {
|
||
return value.toLocaleString("ru-RU", {
|
||
style: "currency",
|
||
currency: "RUB",
|
||
maximumFractionDigits: 0,
|
||
});
|
||
}
|
||
|
||
function fmtDate(iso: string | null): string {
|
||
if (!iso) return "—";
|
||
return new Date(iso).toLocaleDateString("ru-RU", {
|
||
day: "2-digit",
|
||
month: "2-digit",
|
||
year: "2-digit",
|
||
});
|
||
}
|
||
|
||
type SortKey = "price_rub" | "price_per_m2" | "days_on_market";
|
||
|
||
interface Props {
|
||
rows: AnalogLot[];
|
||
emptyLabel?: string;
|
||
}
|
||
|
||
export function AnalogsTable({
|
||
rows,
|
||
emptyLabel = "Нет аналогов в радиусе 1 км",
|
||
}: Props) {
|
||
const [sortKey, setSortKey] = useState<SortKey>("price_rub");
|
||
const [sortAsc, setSortAsc] = useState(true);
|
||
|
||
if (rows.length === 0) {
|
||
return (
|
||
<div
|
||
style={{
|
||
padding: "20px 0",
|
||
color: "#9ca3af",
|
||
fontSize: 14,
|
||
textAlign: "center",
|
||
}}
|
||
>
|
||
{emptyLabel}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const sorted = [...rows].sort((a, b) => {
|
||
const av = a[sortKey];
|
||
const bv = b[sortKey];
|
||
// null ('неизвестно') всегда в конце, независимо от направления
|
||
if (av === null) return bv === null ? 0 : 1;
|
||
if (bv === null) return -1;
|
||
return sortAsc ? av - bv : bv - av;
|
||
});
|
||
|
||
function handleSort(key: SortKey) {
|
||
if (sortKey === key) {
|
||
setSortAsc((prev) => !prev);
|
||
} else {
|
||
setSortKey(key);
|
||
setSortAsc(true);
|
||
}
|
||
}
|
||
|
||
function SortIcon({ col }: { col: SortKey }) {
|
||
if (sortKey !== col) return null;
|
||
return sortAsc ? (
|
||
<svg
|
||
width="11"
|
||
height="11"
|
||
viewBox="0 0 24 24"
|
||
fill="none"
|
||
stroke="currentColor"
|
||
strokeWidth="2.5"
|
||
strokeLinecap="round"
|
||
strokeLinejoin="round"
|
||
style={{ display: "inline", marginLeft: 2, verticalAlign: "middle" }}
|
||
aria-hidden="true"
|
||
>
|
||
<polyline points="18 15 12 9 6 15" />
|
||
</svg>
|
||
) : (
|
||
<svg
|
||
width="11"
|
||
height="11"
|
||
viewBox="0 0 24 24"
|
||
fill="none"
|
||
stroke="currentColor"
|
||
strokeWidth="2.5"
|
||
strokeLinecap="round"
|
||
strokeLinejoin="round"
|
||
style={{ display: "inline", marginLeft: 2, verticalAlign: "middle" }}
|
||
aria-hidden="true"
|
||
>
|
||
<polyline points="6 9 12 15 18 9" />
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
const thStyle: React.CSSProperties = {
|
||
padding: "7px 8px",
|
||
fontSize: 11,
|
||
color: "#5b6066",
|
||
textTransform: "uppercase",
|
||
letterSpacing: "0.04em",
|
||
fontWeight: 600,
|
||
borderBottom: "1px solid #e6e8ec",
|
||
textAlign: "left",
|
||
whiteSpace: "nowrap",
|
||
background: "#f9fafb",
|
||
};
|
||
const tdStyle: React.CSSProperties = {
|
||
padding: "8px 8px",
|
||
fontSize: 13,
|
||
color: "#1a1d23",
|
||
borderBottom: "1px solid #f3f4f6",
|
||
verticalAlign: "middle",
|
||
};
|
||
const numTd: React.CSSProperties = {
|
||
...tdStyle,
|
||
fontVariantNumeric: "tabular-nums",
|
||
textAlign: "right",
|
||
};
|
||
const sortableTh = (col: SortKey): React.CSSProperties => ({
|
||
...thStyle,
|
||
cursor: "pointer",
|
||
userSelect: "none",
|
||
color: sortKey === col ? "#1d4ed8" : "#5b6066",
|
||
});
|
||
|
||
return (
|
||
<div style={{ overflowX: "auto" }}>
|
||
<table
|
||
style={{
|
||
width: "100%",
|
||
borderCollapse: "collapse",
|
||
fontSize: 13,
|
||
}}
|
||
>
|
||
<thead>
|
||
<tr>
|
||
<th style={thStyle}>Фото</th>
|
||
<th style={thStyle}>Адрес</th>
|
||
<th style={{ ...thStyle, textAlign: "right" }}>м²</th>
|
||
<th style={{ ...thStyle, textAlign: "right" }}>Комн.</th>
|
||
<th style={{ ...thStyle, textAlign: "right" }}>Этаж</th>
|
||
<th
|
||
style={sortableTh("price_rub")}
|
||
onClick={() => handleSort("price_rub")}
|
||
>
|
||
Цена ₽ <SortIcon col="price_rub" />
|
||
</th>
|
||
<th
|
||
style={sortableTh("price_per_m2")}
|
||
onClick={() => handleSort("price_per_m2")}
|
||
>
|
||
₽/м² <SortIcon col="price_per_m2" />
|
||
</th>
|
||
<th
|
||
style={sortableTh("days_on_market")}
|
||
onClick={() => handleSort("days_on_market")}
|
||
>
|
||
Дней <SortIcon col="days_on_market" />
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{sorted.map((row, i) => {
|
||
const imgSrc = safeImgSrc(row.photo_url);
|
||
return (
|
||
<tr
|
||
key={i}
|
||
style={{ background: i % 2 === 0 ? "#fff" : "#fafafa" }}
|
||
>
|
||
<td style={tdStyle}>
|
||
{imgSrc ? (
|
||
// eslint-disable-next-line @next/next/no-img-element
|
||
<img
|
||
src={imgSrc}
|
||
alt="фото"
|
||
width={48}
|
||
height={36}
|
||
style={{
|
||
objectFit: "cover",
|
||
borderRadius: 4,
|
||
display: "block",
|
||
}}
|
||
/>
|
||
) : (
|
||
<div
|
||
style={{
|
||
width: 48,
|
||
height: 36,
|
||
background: "#f3f4f6",
|
||
borderRadius: 4,
|
||
display: "flex",
|
||
alignItems: "center",
|
||
justifyContent: "center",
|
||
}}
|
||
>
|
||
<svg
|
||
width="16"
|
||
height="16"
|
||
viewBox="0 0 24 24"
|
||
fill="none"
|
||
stroke="#9ca3af"
|
||
strokeWidth="1.5"
|
||
strokeLinecap="round"
|
||
strokeLinejoin="round"
|
||
aria-hidden="true"
|
||
>
|
||
<rect
|
||
x="3"
|
||
y="3"
|
||
width="18"
|
||
height="18"
|
||
rx="2"
|
||
ry="2"
|
||
/>
|
||
<circle cx="8.5" cy="8.5" r="1.5" />
|
||
<polyline points="21 15 16 10 5 21" />
|
||
</svg>
|
||
</div>
|
||
)}
|
||
</td>
|
||
<td style={{ ...tdStyle, maxWidth: 200 }}>
|
||
<span
|
||
title={row.address}
|
||
style={{
|
||
display: "block",
|
||
overflow: "hidden",
|
||
textOverflow: "ellipsis",
|
||
whiteSpace: "nowrap",
|
||
}}
|
||
>
|
||
{row.address}
|
||
</span>
|
||
{row.listing_date && (
|
||
<span style={{ fontSize: 11, color: "#9ca3af" }}>
|
||
{fmtDate(row.listing_date)}
|
||
</span>
|
||
)}
|
||
</td>
|
||
<td style={{ ...numTd }}>{row.area_m2.toFixed(1)}</td>
|
||
<td style={{ ...numTd }}>
|
||
{row.rooms === 0 ? "ст." : row.rooms}
|
||
</td>
|
||
<td style={{ ...numTd }}>
|
||
{row.floor !== null && row.total_floors !== null
|
||
? `${row.floor}/${row.total_floors}`
|
||
: (row.floor ?? "—")}
|
||
</td>
|
||
<td style={{ ...numTd }}>{fmtRub(row.price_rub)}</td>
|
||
<td style={{ ...numTd }}>{fmtRub(row.price_per_m2)}</td>
|
||
<td style={{ ...numTd }}>
|
||
{row.days_on_market !== null ? row.days_on_market : "—"}
|
||
</td>
|
||
</tr>
|
||
);
|
||
})}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
);
|
||
}
|