SPB Git

Repository Public

page.tsx 15.3 KB 363 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/ventes/page.tsx9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-10-2012 * Last Modified    : 2026-10-2013 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * /ventes — registre des ventes récentes au Québec.44 * Source : transactions publiées (flux « Transactions immobilières » du Journal45 * de Québec / Journal de Montréal, api.qub.ca), ingérées chaque jour par le46 * connecteur scripts/ingest-jdm.mjs et appariées à leur unité d'évaluation.47 * Filtres en formulaire GET (fonctionne sans JavaScript), pagination par liens.48 */49import type { Metadata } from "next";50import Link from "next/link";51import {52  PERIODE_LABELS,53  VENTE_PERIODES,54  VENTE_TYPES,55  VENTE_TYPE_LABELS,56  dateFrLong,57  parseVenteFilters,58  ventesOverview,59  ventesRecentes,60  vsRolePct,61} from "@/lib/ventes";62import { munBySlug } from "@/lib/municipalites";63import { SITE_URL, moneyFr, numFr, slugify } from "@/lib/seo";6465export const dynamic = "force-dynamic";6667export const metadata: Metadata = {68  title: "Ventes récentes au Québec — registre des transactions immobilières",69  description:70    "Les dernières ventes immobilières publiées au Québec, mises à jour chaque jour : prix de vente, adresse, type, écart avec l'évaluation municipale. Filtrez par municipalité, type et prix ; chaque vente mène à l'estimation Vrai-Prix de la propriété.",71  alternates: { canonical: "/ventes" },72  openGraph: {73    type: "website",74    title: "Ventes récentes au Québec — registre des transactions immobilières",75    description:76      "Les dernières ventes immobilières publiées au Québec, mises à jour chaque jour, appariées au rôle d'évaluation.",77    url: "/ventes",78  },79};8081type SP = Record<string, string | string[] | undefined>;8283function hrefWith(sp: SP, patch: Record<string, string | number | undefined>): string {84  const u = new URLSearchParams();85  for (const [k, v] of Object.entries(sp)) {86    const s = Array.isArray(v) ? v[0] : v;87    if (s) u.set(k, s);88  }89  for (const [k, v] of Object.entries(patch)) {90    if (v === undefined || v === "" || v === null) u.delete(k);91    else u.set(k, String(v));92  }93  const qs = u.toString();94  return qs ? `/ventes?${qs}` : "/ventes";95}9697function pct(p: number | null): string {98  if (p == null) return "—";99  return `${p >= 0 ? "+" : "−"}${Math.abs(p).toFixed(0)} %`;100}101102export default async function VentesPage({ searchParams }: { searchParams: Promise<SP> }) {103  const sp = await searchParams;104  const f = parseVenteFilters(sp);105  const page = ventesRecentes(f);106  const ov = ventesOverview();107  const url = `${SITE_URL}/ventes`;108109  const jsonLd = {110    "@context": "https://schema.org",111    "@graph": [112      {113        "@type": "Dataset",114        "@id": `${url}#dataset`,115        name: "Ventes immobilières récentes au Québec",116        description:117          "Transactions immobilières publiées au Québec, appariées aux unités d'évaluation du rôle foncier (MAMH).",118        url,119        isAccessibleForFree: true,120        creator: { "@type": "Organization", name: "Vrai-Prix", url: SITE_URL },121        temporalCoverage: ov.maxDate ? `2021-01-01/${ov.maxDate}` : undefined,122        spatialCoverage: { "@type": "Place", name: "Québec, Canada" },123      },124      {125        "@type": "BreadcrumbList",126        itemListElement: [127          { "@type": "ListItem", position: 1, name: "Accueil", item: SITE_URL },128          { "@type": "ListItem", position: 2, name: "Ventes récentes", item: url },129        ],130      },131    ],132  };133134  const tiles: [string, string][] = [135    ["Ventes · 30 jours", numFr(ov.n30)],136    ["Ventes · 90 jours", numFr(ov.n90)],137    ["Prix médian · 30 jours", moneyFr(ov.median30)],138    ["Dernière vente captée", ov.maxDate ? dateFrLong(ov.maxDate) : "—"],139  ];140141  const first = page.total ? (page.page - 1) * page.limit + 1 : 0;142  const last = Math.min(page.total, page.page * page.limit);143  const filtered = !!(f.q || f.type || f.min != null || f.max != null);144145  return (146    <div className="pb-6 pt-10 sm:pt-14">147      <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />148      <nav className="vp-mono text-[11px] uppercase tracking-[0.08em] text-ink-2">149        <Link href="/" className="hover:underline">150          Accueil151        </Link>{" "}152        / <span className="text-ink">Ventes récentes</span>153      </nav>154155      <section className="mt-6">156        <span className="kicker">Registre · ventes réelles</span>157        <h1 className="vp-display mt-3 max-w-4xl text-[clamp(28px,5.4vw,56px)] font-bold uppercase leading-[1.0] tracking-[-0.03em]">158          Les dernières ventes <span className="hl">au Québec</span>159        </h1>160        <p className="mt-4 max-w-2xl text-[15.5px] text-ink-2">161          Transactions immobilières publiées, captées chaque jour et appariées162          automatiquement à leur unité d&apos;évaluation. Chaque vente mène à163          l&apos;estimation complète de la propriété — et à l&apos;écart entre164          le prix payé et la valeur au rôle. Il s&apos;écoule plusieurs semaines165          entre la signature et la publication d&apos;une vente.166        </p>167      </section>168169      {/* ---- Tuiles ---- */}170      <section className="mt-8 grid grid-cols-2 gap-3 lg:grid-cols-4">171        {tiles.map(([label, val]) => (172          <div key={label} className="vp-card p-4">173            <p className="klabel">{label}</p>174            <p className="vp-display mt-1 break-words text-[clamp(17px,2.2vw,26px)] font-bold tracking-[-0.02em]">175              {val}176            </p>177          </div>178        ))}179      </section>180181      {ov.byType30.length > 0 && (182        <ul className="mt-4 flex flex-wrap gap-x-5 gap-y-2">183          {ov.byType30.map((t) => (184            <li key={t.type} className="stat-chip">185              <b>{moneyFr(t.median)}</b> {VENTE_TYPE_LABELS[t.type] ?? t.type} · {numFr(t.n)} / 30 j186            </li>187          ))}188        </ul>189      )}190191      {/* ---- Filtres (GET, sans JS) ---- */}192      <section className="mt-10">193        <span className="kicker">Filtrer</span>194        <form method="get" action="/ventes" className="mt-4 grid gap-x-6 gap-y-4 sm:grid-cols-2 lg:grid-cols-[1.4fr_1fr_1fr_1fr_1.2fr_auto]">195          <label className="block">196            <span className="klabel">Municipalité</span>197            <input198              type="search"199              name="q"200              defaultValue={f.q}201              placeholder="ex. Québec, Lévis, Gatineau"202              className="vp-input mt-1"203              autoComplete="off"204            />205          </label>206          <label className="block">207            <span className="klabel">Type</span>208            <select name="type" defaultValue={f.type} className="vp-input mt-1 cursor-pointer">209              <option value="">Tous les types</option>210              {VENTE_TYPES.map((t) => (211                <option key={t} value={t}>212                  {VENTE_TYPE_LABELS[t]}213                </option>214              ))}215            </select>216          </label>217          <label className="block">218            <span className="klabel">Prix min ($)</span>219            <input name="min" defaultValue={f.min ?? ""} inputMode="numeric" placeholder="0" className="vp-input mt-1" />220          </label>221          <label className="block">222            <span className="klabel">Prix max ($)</span>223            <input name="max" defaultValue={f.max ?? ""} inputMode="numeric" placeholder="∞" className="vp-input mt-1" />224          </label>225          <label className="block">226            <span className="klabel">Période</span>227            <select name="periode" defaultValue={f.periode} className="vp-input mt-1 cursor-pointer">228              {Object.keys(VENTE_PERIODES).map((k) => (229                <option key={k} value={k}>230                  {PERIODE_LABELS[k]}231                </option>232              ))}233            </select>234          </label>235          <div className="flex items-end gap-3">236            <button type="submit" className="btn btn-primary">237              Filtrer238            </button>239            {filtered && (240              <Link href="/ventes" className="vp-mono text-[11px] uppercase tracking-[0.08em] text-ink-2 underline underline-offset-2">241                Effacer242              </Link>243            )}244          </div>245        </form>246      </section>247248      {/* ---- Résultats ---- */}249      <section className="mt-8">250        <p className="vp-mono text-[11px] uppercase tracking-[0.08em] text-ink-2">251          {page.total === 0252            ? "Aucune vente ne correspond à ces critères."253            : `${numFr(page.total)} ventes${page.since ? ` depuis le ${dateFrLong(page.since)}` : ""} · ${numFr(first)}–${numFr(last)} · page ${page.page} / ${page.pages}`}254        </p>255256        {page.rows.length > 0 && (257          <div className="mt-4 overflow-x-auto">258            <table className="w-full min-w-[760px] border-collapse text-[14px]">259              <thead>260                <tr className="border-b-2 border-ink text-left">261                  <th className="klabel py-2 pr-4">Date</th>262                  <th className="klabel py-2 pr-4">Adresse</th>263                  <th className="klabel py-2 pr-4">Municipalité</th>264                  <th className="klabel py-2 pr-4">Type</th>265                  <th className="klabel py-2 pr-4 text-right">Prix de vente</th>266                  <th className="klabel py-2 pr-4 text-right">Rôle</th>267                  <th className="klabel py-2 text-right">vs rôle</th>268                </tr>269              </thead>270              <tbody>271                {page.rows.map((r) => {272                  const p = vsRolePct(r.amount, r.valeur_role);273                  const slug = r.city ? slugify(r.city) : "";274                  const munOk = slug ? !!munBySlug(slug) : false;275                  return (276                    <tr key={r.id} className="border-b border-[rgba(20,24,20,0.12)]">277                      <td className="vp-mono whitespace-nowrap py-2.5 pr-4 text-[12px] text-ink-2">{dateFrLong(r.date)}</td>278                      <td className="py-2.5 pr-4">279                        {r.id_provinc ? (280                          <Link281                            href={`/estimation/${encodeURIComponent(r.id_provinc)}`}282                            className="font-medium underline decoration-[rgba(20,24,20,0.3)] underline-offset-2 hover:decoration-ink"283                          >284                            {r.street ?? "Adresse non publiée"}285                          </Link>286                        ) : (287                          <span className="font-medium">{r.street ?? "Adresse non publiée"}</span>288                        )}289                        {(r.year_built || r.floor_area) && (290                          <span className="vp-mono ml-2 text-[10.5px] uppercase tracking-[0.05em] text-ink-3">291                            {r.year_built ? `${r.year_built}` : ""}292                            {r.year_built && r.floor_area ? " · " : ""}293                            {r.floor_area ? `${Math.round(r.floor_area)} m²` : ""}294                          </span>295                        )}296                      </td>297                      <td className="py-2.5 pr-4">298                        {munOk ? (299                          <Link href={`/municipalite/${slug}`} className="hover:underline">300                            {r.city}301                          </Link>302                        ) : (303                          r.city ?? "—"304                        )}305                      </td>306                      <td className="py-2.5 pr-4 text-ink-2">{VENTE_TYPE_LABELS[r.property_type ?? ""] ?? r.property_type ?? "—"}</td>307                      <td className="vp-display py-2.5 pr-4 text-right text-[15px] font-bold tracking-[-0.01em]">{moneyFr(r.amount)}</td>308                      <td className="vp-mono py-2.5 pr-4 text-right text-ink-2">{moneyFr(r.valeur_role)}</td>309                      <td className={`vp-mono py-2.5 text-right ${p != null && p < 0 ? "text-[var(--danger)]" : "text-ink-2"}`}>{pct(p)}</td>310                    </tr>311                  );312                })}313              </tbody>314            </table>315          </div>316        )}317318        {page.pages > 1 && (319          <nav className="mt-6 flex flex-wrap items-center justify-between gap-3" aria-label="Pagination">320            {page.page > 1 ? (321              <Link href={hrefWith(sp, { page: page.page - 1 })} className="btn btn-ghost" rel="prev">322                ← Plus récentes323              </Link>324            ) : (325              <span />326            )}327            <span className="vp-mono text-[11px] uppercase tracking-[0.08em] text-ink-2">328              page {page.page} / {page.pages}329            </span>330            {page.page < page.pages ? (331              <Link href={hrefWith(sp, { page: page.page + 1 })} className="btn btn-ghost" rel="next">332                Plus anciennes →333              </Link>334            ) : (335              <span />336            )}337          </nav>338        )}339      </section>340341      <section className="mt-12 max-w-3xl text-[13.5px] text-ink-2">342        <span className="kicker">À propos de ces données</span>343        <p className="mt-3">344          Les ventes proviennent des transactions publiées au registre foncier et345          reprises par le flux « Transactions immobilières » du Journal de Québec346          et du Journal de Montréal (Québecor). Chaque vente est captée347          quotidiennement, puis appariée à l&apos;unité d&apos;évaluation la plus348          proche du rôle foncier (MAMH) : l&apos;écart « vs rôle » compare le prix349          payé à la valeur inscrite au rôle en vigueur. Les regroupements de types350          suivent ceux de la source : détaché, jumelé et en rangée forment351          « Unifamiliale » ; « Autre » englobe les terrains, les condos neufs et352          les ventes non classées. Données indicatives : consultez un353          professionnel avant toute décision, et la{" "}354          <Link href="/methodologie" className="underline">355            méthodologie356          </Link>{" "}357          pour les limites connues.358        </p>359      </section>360    </div>361  );362}363
Files main
Menu

Theme