@realadvisor-sites/kit-react 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/bin/sites-kit-react.mjs +26 -0
- package/client/index.ts +21 -0
- package/client/islands.ts +33 -0
- package/components/ConsentBanner.tsx +25 -0
- package/components/Document.tsx +170 -0
- package/components/EnquiryForm.tsx +107 -0
- package/components/Island.tsx +39 -0
- package/components/LanguageSwitch.tsx +24 -0
- package/components/LegalContent.tsx +30 -0
- package/components/ListingsMap.tsx +76 -0
- package/components/ListingsPager.tsx +25 -0
- package/components/ListingsSearch.tsx +294 -0
- package/components/RaImage.tsx +107 -0
- package/components/SafeHtml.tsx +30 -0
- package/components/form/Button.tsx +22 -0
- package/components/form/Combobox.tsx +34 -0
- package/components/form/Input.tsx +24 -0
- package/components/form/Select.tsx +30 -0
- package/components/index.ts +15 -0
- package/env.d.ts +36 -0
- package/lib/image.ts +36 -0
- package/lib/records.ts +17 -0
- package/lib/search.ts +37 -0
- package/package.json +63 -4
- package/server/data.ts +82 -0
- package/server/enquiry.ts +9 -0
- package/server/entry.server.tsx +54 -0
- package/server/fixture-client.ts +2 -0
- package/server/kit.ts +52 -0
- package/server/security.ts +32 -0
- package/server/seo.ts +39 -0
- package/server/worker.ts +146 -0
- package/styles/consent.css +6 -0
- package/styles/kit.css +21 -0
- package/styles/map.css +58 -0
- package/styles/pager.css +14 -0
- package/styles/search.css +162 -0
- package/tools/check-deploy.mjs +280 -0
- package/tools/preview.mjs +77 -0
- package/vite.d.mts +2 -0
- package/vite.mjs +180 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React island: the component renders on the server (its own useId prefix)
|
|
3
|
+
* and hydrates alone in the browser, when visible (default), idle or at load,
|
|
4
|
+
* through `islands()` in app/client.ts. The rest of the page stays static
|
|
5
|
+
* HTML: no React Router runtime, no inline script (props go in data-props).
|
|
6
|
+
*
|
|
7
|
+
* <Island name="OfferTabs" component={OfferTabs} props={{ title, panels }} />
|
|
8
|
+
* // app/client.ts
|
|
9
|
+
* islands({ OfferTabs: () => import('./components/OfferTabs') });
|
|
10
|
+
*
|
|
11
|
+
* Props must be JSON (no functions, no Dates); the island must not import
|
|
12
|
+
* server code (data clients, secrets).
|
|
13
|
+
*/
|
|
14
|
+
import { createElement, useId, type ComponentType } from 'react';
|
|
15
|
+
import { renderToString } from 'react-dom/server';
|
|
16
|
+
|
|
17
|
+
export type IslandProps<P extends object> = {
|
|
18
|
+
/** Key in the islands() loader map. */
|
|
19
|
+
name: string;
|
|
20
|
+
component: ComponentType<P>;
|
|
21
|
+
props: P;
|
|
22
|
+
when?: 'visible' | 'idle' | 'load';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function Island<P extends object>({ name, component, props, when = 'visible' }: IslandProps<P>) {
|
|
26
|
+
// A stable, unique prefix per island on the page (React's own id of this element).
|
|
27
|
+
const prefix = `${name}-${useId().replace(/[^a-zA-Z0-9]/g, '')}-`;
|
|
28
|
+
const html = renderToString(createElement(component, props), { identifierPrefix: prefix });
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
data-island={name}
|
|
32
|
+
data-when={when}
|
|
33
|
+
data-prefix={prefix}
|
|
34
|
+
data-props={JSON.stringify(props)}
|
|
35
|
+
style={{ display: 'contents' }}
|
|
36
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language links of a multi-language site: one <a hreflang> per version of
|
|
3
|
+
* this page (the same `alternates` the page gives <Seo>), the current one
|
|
4
|
+
* aria-current. Single-language sites render nothing.
|
|
5
|
+
*/
|
|
6
|
+
import { lang } from '@realadvisor/sites-kit/i18n';
|
|
7
|
+
|
|
8
|
+
export function LanguageSwitch({ alternates, locale, className }: { alternates: { lang: string; href: string }[]; locale: string; className?: string }) {
|
|
9
|
+
if (alternates.length < 2) return null;
|
|
10
|
+
return (
|
|
11
|
+
<nav className={['lang-switch', className].filter(Boolean).join(' ')} aria-label="Language">
|
|
12
|
+
<ul>
|
|
13
|
+
{alternates.map((a) => (
|
|
14
|
+
<li key={a.lang}>
|
|
15
|
+
<a href={a.href} hrefLang={a.lang} lang={a.lang} aria-current={a.lang === locale ? 'true' : undefined}>{lang(a.lang).toUpperCase()}</a>
|
|
16
|
+
</li>
|
|
17
|
+
))}
|
|
18
|
+
</ul>
|
|
19
|
+
</nav>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Alternates of one page in every locale: `localePath(path, locale)` per language. */
|
|
24
|
+
export { localePath } from '@realadvisor/sites-kit/i18n';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legal sections from the kit's lib/legal.ts (port of LegalContent.astro).
|
|
3
|
+
* Never edit the words: they come from the agency data only.
|
|
4
|
+
*
|
|
5
|
+
* <LegalContent sections={legalNotice(agencyOf(org, team))} />
|
|
6
|
+
*/
|
|
7
|
+
import type { LegalSection } from '@realadvisor/sites-kit/legal';
|
|
8
|
+
|
|
9
|
+
export function LegalContent({ sections, className }: { sections: LegalSection[]; className?: string }) {
|
|
10
|
+
return (
|
|
11
|
+
<div className={['legal', className].filter(Boolean).join(' ')}>
|
|
12
|
+
{sections.map((s, i) => (
|
|
13
|
+
<section key={i}>
|
|
14
|
+
<h2>{s.heading}</h2>
|
|
15
|
+
{s.rows && (
|
|
16
|
+
<dl>
|
|
17
|
+
{s.rows.map((r, j) => (
|
|
18
|
+
<div key={j}>
|
|
19
|
+
<dt>{r.label}</dt>
|
|
20
|
+
<dd>{r.href ? <a href={r.href}>{r.value}</a> : r.value}</dd>
|
|
21
|
+
</div>
|
|
22
|
+
))}
|
|
23
|
+
</dl>
|
|
24
|
+
)}
|
|
25
|
+
{s.paragraphs?.map((p, j) => <p key={j}>{p}</p>)}
|
|
26
|
+
</section>
|
|
27
|
+
))}
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listings map (port of ListingsMap.astro: same markup and data-* contract;
|
|
3
|
+
* the browser side is @realadvisor/sites-kit/client/listings-map, no map
|
|
4
|
+
* library, OSM tiles only). Height: `--map-h` on a parent. Keep the attribution.
|
|
5
|
+
*
|
|
6
|
+
* <ListingsMap listings={located} href={listingUrl} price={price} />
|
|
7
|
+
*/
|
|
8
|
+
import type { Listing } from '@realadvisor/sites-sdk/types';
|
|
9
|
+
import { formatPrice, listingUrl } from '@realadvisor/sites-kit/format';
|
|
10
|
+
import { img } from '@realadvisor/sites-kit/image';
|
|
11
|
+
import { lang, localePath, pluralForms, propertyTypeLabel, t } from '@realadvisor/sites-kit/i18n';
|
|
12
|
+
import { usePageLocale } from './Document';
|
|
13
|
+
|
|
14
|
+
type MapProps<L> = {
|
|
15
|
+
listings: L[];
|
|
16
|
+
/** id of the list whose cards (`data-listing-id`) follow the map. */
|
|
17
|
+
list?: string;
|
|
18
|
+
locale?: string;
|
|
19
|
+
/** First view (zoom, centre) instead of fitting the listings. */
|
|
20
|
+
view?: { z: number; lat: number; lng: number };
|
|
21
|
+
/** Keep the visitor's view in the URL as `?map=z/lat/lng`. */
|
|
22
|
+
sync?: boolean;
|
|
23
|
+
listMode?: 'client' | 'server';
|
|
24
|
+
href?: (l: L) => string;
|
|
25
|
+
price?: (l: L) => string;
|
|
26
|
+
className?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The map over SDK listings (also ListingsSearch's). */
|
|
30
|
+
export function ListingsMap({ listings, list, locale: localeProp, view, sync, listMode, href, price, className }: MapProps<Listing>) {
|
|
31
|
+
const pathLocale = usePageLocale();
|
|
32
|
+
const locale = localeProp ?? pathLocale;
|
|
33
|
+
const l = lang(locale);
|
|
34
|
+
const points = listings
|
|
35
|
+
.filter((x) => x.address.lat != null && x.address.lng != null)
|
|
36
|
+
.map((x) => ({
|
|
37
|
+
id: x.id,
|
|
38
|
+
lat: x.address.lat,
|
|
39
|
+
lng: x.address.lng,
|
|
40
|
+
url: href ? href(x) : localePath(listingUrl(x), locale),
|
|
41
|
+
title: x.title,
|
|
42
|
+
type: propertyTypeLabel(x.property_type, locale),
|
|
43
|
+
price: price ? price(x) : formatPrice(x, { locale }),
|
|
44
|
+
photo: x.photos[0]?.url ? img(x.photos[0].url, { w: 320, h: 213 }) : undefined,
|
|
45
|
+
}));
|
|
46
|
+
const labels = { lang: l, inArea: pluralForms('inArea', l), listings: pluralForms('listings', l), showAll: t('showAll', {}, l), close: t('close', {}, l) };
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
className={['ra-map', className].filter(Boolean).join(' ')}
|
|
50
|
+
data-ra-map=""
|
|
51
|
+
data-points={JSON.stringify(points)}
|
|
52
|
+
data-labels={JSON.stringify(labels)}
|
|
53
|
+
data-list={list}
|
|
54
|
+
data-view={view ? JSON.stringify(view) : undefined}
|
|
55
|
+
data-sync={sync ? 'true' : undefined}
|
|
56
|
+
data-list-mode={listMode === 'server' ? 'server' : undefined}
|
|
57
|
+
>
|
|
58
|
+
<div className="ra-map-viewport" data-map-viewport="" tabIndex={0} role="application" aria-label={t('mapLabel', {}, l)} aria-roledescription="map">
|
|
59
|
+
<div className="ra-map-tiles" data-map-tiles="" aria-hidden="true"></div>
|
|
60
|
+
<div className="ra-map-markers" data-map-markers=""></div>
|
|
61
|
+
<div className="ra-map-popup" data-map-popup=""></div>
|
|
62
|
+
</div>
|
|
63
|
+
<div className="ra-map-status" data-map-status="" role="status">
|
|
64
|
+
<span data-map-count=""></span>
|
|
65
|
+
<button type="button">{t('showAll', {}, l)}</button>
|
|
66
|
+
</div>
|
|
67
|
+
<div className="ra-map-zoom">
|
|
68
|
+
<button type="button" data-map-zoom="1" aria-label={t('zoomIn', {}, l)}>+</button>
|
|
69
|
+
<button type="button" data-map-zoom="-1" aria-label={t('zoomOut', {}, l)}>−</button>
|
|
70
|
+
</div>
|
|
71
|
+
<p className="ra-map-attr">© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">{t('osmContributors', {}, l)}</a></p>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default ListingsMap;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Numbered pages of ListingsSearch (port of ListingsPager.astro). */
|
|
2
|
+
import { pageList, type SearchResult } from '@realadvisor/sites-kit/search';
|
|
3
|
+
import { usePageLocale } from './Document';
|
|
4
|
+
import { lang, t } from '@realadvisor/sites-kit/i18n';
|
|
5
|
+
|
|
6
|
+
export function ListingsPager({ result, href, locale }: { result: SearchResult; href: (over: { page?: number }) => string; locale?: string }) {
|
|
7
|
+
const l = lang(locale ?? usePageLocale());
|
|
8
|
+
if (!(result.pages > 1 && result.total > 0)) return null;
|
|
9
|
+
const pages = pageList(result.page, result.pages);
|
|
10
|
+
return (
|
|
11
|
+
<nav className="rs-pager" data-rs-pager="" aria-label={t('pagination', {}, l)}>
|
|
12
|
+
{result.page > 1 ? (
|
|
13
|
+
<a className="rs-step" href={href({ page: result.page - 1 > 1 ? result.page - 1 : undefined })} rel="prev" data-rs-nav="">‹ <span>{t('prevPage', {}, l)}</span></a>
|
|
14
|
+
) : <span className="rs-step" aria-hidden="true"></span>}
|
|
15
|
+
<ol>
|
|
16
|
+
{pages.map((n, i) => n == null ? <li key={`g${i}`} className="rs-gap" aria-hidden="true">…</li> : (
|
|
17
|
+
<li key={n}><a href={href({ page: n > 1 ? n : undefined })} data-rs-nav="" aria-current={n === result.page ? 'page' : undefined} aria-label={`${t('page', {}, l)} ${n}`}>{n}</a></li>
|
|
18
|
+
))}
|
|
19
|
+
</ol>
|
|
20
|
+
{result.page < result.pages ? (
|
|
21
|
+
<a className="rs-step" href={href({ page: result.page + 1 })} rel="next" data-rs-nav=""><span>{t('nextPage', {}, l)}</span> ›</a>
|
|
22
|
+
) : <span className="rs-step" aria-hidden="true"></span>}
|
|
23
|
+
</nav>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE listing search (port of ListingsSearch.astro: same markup, class and
|
|
3
|
+
* data-rs-* hooks, same GET URLs; the browser side is the Astro kit's
|
|
4
|
+
* client/listings-search, which swaps the server's HTML in). Filters, chips,
|
|
5
|
+
* count, sort, list / map views, pagination, empty states, phone pill.
|
|
6
|
+
*
|
|
7
|
+
* const result = searchListings(pool, parseSearch(url.searchParams));
|
|
8
|
+
* <h1 data-rs-sync="h1">{heading}</h1>
|
|
9
|
+
* <ListingsSearch result={result} base="/kaufen" contactHref="/kontakt">
|
|
10
|
+
* {(l, i) => <ListingCard listing={l} priority={i === 0} />}
|
|
11
|
+
* </ListingsSearch>
|
|
12
|
+
*
|
|
13
|
+
* The page must stay static (no `hydrate` handle): the script replaces parts
|
|
14
|
+
* of it. Theme with the tokens of the Astro version (--accent, --rs-*, …).
|
|
15
|
+
*/
|
|
16
|
+
import type { ReactNode } from 'react';
|
|
17
|
+
import type { Listing } from '@realadvisor/sites-sdk/types';
|
|
18
|
+
import { mapView, searchHref, type FilterKey } from '@realadvisor/sites-kit/search';
|
|
19
|
+
import { formatAmount, formatPrice, formatSurface, listingUrl } from '@realadvisor/sites-kit/format';
|
|
20
|
+
import { count, lang, localePath, offerTypeLabel, propertyTypeLabel, t } from '@realadvisor/sites-kit/i18n';
|
|
21
|
+
import type { ListingsResult } from '../lib/search';
|
|
22
|
+
import { ListingsMap } from './ListingsMap';
|
|
23
|
+
import { ListingsPager } from './ListingsPager';
|
|
24
|
+
import { RaImage } from './RaImage';
|
|
25
|
+
import { usePageLocale } from './Document';
|
|
26
|
+
import { Select } from './form/Select';
|
|
27
|
+
import { Combobox } from './form/Combobox';
|
|
28
|
+
import { Button } from './form/Button';
|
|
29
|
+
|
|
30
|
+
type FilterName = 'offerType' | 'propertyType' | 'city' | 'price' | 'rooms';
|
|
31
|
+
export type ListingsSearchProps = {
|
|
32
|
+
result: ListingsResult;
|
|
33
|
+
base?: string;
|
|
34
|
+
locale?: string;
|
|
35
|
+
contactHref?: string;
|
|
36
|
+
valuationHref?: string;
|
|
37
|
+
tellUsHref?: string;
|
|
38
|
+
listingHref?: (l: Listing) => string;
|
|
39
|
+
/** Map popup price (default formatPrice). */
|
|
40
|
+
price?: (l: Listing) => string;
|
|
41
|
+
filters?: FilterName[];
|
|
42
|
+
sold?: boolean;
|
|
43
|
+
className?: string;
|
|
44
|
+
/** The design's card; a plain card when absent. */
|
|
45
|
+
children?: (l: Listing, i: number) => ReactNode;
|
|
46
|
+
/** Replaces the "no listings at all" block. */
|
|
47
|
+
empty?: ReactNode;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const GridIcon = () => (
|
|
51
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75"><rect x="4" y="4" width="7" height="7" /><rect x="13" y="4" width="7" height="7" /><rect x="4" y="13" width="7" height="7" /><rect x="13" y="13" width="7" height="7" /></svg>
|
|
52
|
+
);
|
|
53
|
+
const MapIcon = () => (
|
|
54
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinejoin="round"><path d="M9 4 3 6v14l6-2 6 2 6-2V4l-6 2-6-2zM9 4v14M15 6v14" /></svg>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export function ListingsSearch(props: ListingsSearchProps) {
|
|
58
|
+
const pathLocale = usePageLocale();
|
|
59
|
+
const {
|
|
60
|
+
result,
|
|
61
|
+
locale = pathLocale,
|
|
62
|
+
base = localePath('/listings', locale),
|
|
63
|
+
contactHref,
|
|
64
|
+
valuationHref,
|
|
65
|
+
tellUsHref = contactHref,
|
|
66
|
+
price,
|
|
67
|
+
filters = ['offerType', 'propertyType', 'city', 'price', 'rooms'],
|
|
68
|
+
sold = true,
|
|
69
|
+
className,
|
|
70
|
+
children,
|
|
71
|
+
empty,
|
|
72
|
+
} = props;
|
|
73
|
+
const listingHref = (x: Listing) => (props.listingHref ? props.listingHref(x) : localePath(listingUrl(x), locale));
|
|
74
|
+
const l = lang(locale);
|
|
75
|
+
const { params: p, facets, counts, total } = result;
|
|
76
|
+
const href = (over: Parameters<typeof searchHref>[2] = {}) => searchHref(base, p, over);
|
|
77
|
+
const show = (f: FilterName) => filters.includes(f);
|
|
78
|
+
const isMap = p.view === 'map';
|
|
79
|
+
const nothingAtAll = counts.available + counts.sold === 0;
|
|
80
|
+
const withCurrent = <T extends { value: string }>(opts: T[], value: string | undefined, make: (v: string) => T) =>
|
|
81
|
+
value && !opts.some((o) => o.value === value) ? [make(value), ...opts] : opts;
|
|
82
|
+
const amount = (n: number) => formatAmount(n, { currency: result.currency, locale });
|
|
83
|
+
const typeOptions = withCurrent(
|
|
84
|
+
facets.propertyTypes.map((f) => ({ value: f.value, label: propertyTypeLabel(f.value, locale) })),
|
|
85
|
+
p.propertyType,
|
|
86
|
+
(v) => ({ value: v, label: propertyTypeLabel(v, locale) }),
|
|
87
|
+
);
|
|
88
|
+
const cityOptions = withCurrent(facets.cities.map((f) => ({ value: f.value, label: f.value })), p.city, (v) => ({ value: v, label: v }));
|
|
89
|
+
const priceOptions = withCurrent(
|
|
90
|
+
facets.prices.map((n) => ({ value: String(n), label: t('priceMax', { price: amount(n) }, l) })),
|
|
91
|
+
p.maxPrice ? String(p.maxPrice) : undefined,
|
|
92
|
+
(v) => ({ value: v, label: t('priceMax', { price: amount(Number(v)) }, l) }),
|
|
93
|
+
);
|
|
94
|
+
const roomOptions = withCurrent(
|
|
95
|
+
facets.rooms.map((n) => ({ value: String(n), label: t('roomsMin', { n: String(n) }, l) })),
|
|
96
|
+
p.minRooms ? String(p.minRooms) : undefined,
|
|
97
|
+
(v) => ({ value: v, label: t('roomsMin', { n: v }, l) }),
|
|
98
|
+
);
|
|
99
|
+
const sortOptions = (['newest', 'price-asc', 'price-desc', 'surface-desc'] as const).map((s) => ({ value: s, label: t(`sort_${s}`, {}, l) }));
|
|
100
|
+
const showOffer = show('offerType') && (facets.offerTypes.length > 1 || !!p.offerType);
|
|
101
|
+
const nFilters = result.chips.length;
|
|
102
|
+
const chipLabel = (k: FilterKey): string =>
|
|
103
|
+
k === 'offerType' ? offerTypeLabel(p.offerType!, locale)
|
|
104
|
+
: k === 'propertyType' ? propertyTypeLabel(p.propertyType, locale)
|
|
105
|
+
: k === 'city' ? p.city!
|
|
106
|
+
: k === 'minPrice' ? t('priceMin', { price: amount(p.minPrice!) }, l)
|
|
107
|
+
: k === 'maxPrice' ? t('priceMax', { price: amount(p.maxPrice!) }, l)
|
|
108
|
+
: k === 'bbox' ? t('mapArea', {}, l)
|
|
109
|
+
: t('roomsMin', { n: String(p.minRooms) }, l);
|
|
110
|
+
const resetHref = searchHref(base, { ...p, offerType: undefined, propertyType: undefined, city: undefined, minPrice: undefined, maxPrice: undefined, minRooms: undefined, bbox: undefined }, { page: undefined, map: undefined });
|
|
111
|
+
const mapMode = isMap && result.mapItems.length > 0;
|
|
112
|
+
const facts = (x: Listing) =>
|
|
113
|
+
[x.rooms ? `${x.rooms} ${t('rooms', {}, l).toLowerCase()}` : '', x.living_surface ? formatSurface(x.living_surface) : ''].filter(Boolean).join(' · ');
|
|
114
|
+
const cardSizes = isMap ? '(min-width: 1280px) 300px, (min-width: 960px) 40vw, 100vw' : '(min-width: 1024px) 400px, (min-width: 640px) 50vw, 100vw';
|
|
115
|
+
const card = (x: Listing, i: number) =>
|
|
116
|
+
children ? children(x, i) : (
|
|
117
|
+
<a className="rs-card" href={listingHref(x)}>
|
|
118
|
+
{x.photos[0] ? (
|
|
119
|
+
<RaImage src={x.photos[0]} alt={x.photos[0].alt || `${propertyTypeLabel(x.property_type, locale)}, ${x.address.city ?? ''}`} width={600} height={400} sizes={cardSizes} />
|
|
120
|
+
) : (
|
|
121
|
+
<span className="rs-card-nophoto" aria-hidden="true">{propertyTypeLabel(x.property_type, locale)}</span>
|
|
122
|
+
)}
|
|
123
|
+
<span className="rs-card-type">{propertyTypeLabel(x.property_type, locale)}{x.address.city && ` · ${x.address.city}`}</span>
|
|
124
|
+
<span className="rs-card-title">{x.title}</span>
|
|
125
|
+
<span className="rs-card-price">{x.status === 'sold' ? t('sold', {}, l) : formatPrice(x, { locale })}</span>
|
|
126
|
+
{facts(x) && <span className="rs-card-facts">{facts(x)}</span>}
|
|
127
|
+
</a>
|
|
128
|
+
);
|
|
129
|
+
const relax = result.relax.length > 0 && (
|
|
130
|
+
<ul className="rs-relax">
|
|
131
|
+
{result.relax.map((r) => (
|
|
132
|
+
<li key={r.key}><a href={href({ [r.key]: undefined })} data-rs-nav="">{t('removeFilter', { filter: chipLabel(r.key) }, l)}</a> <span className="rs-n">{count('listings', r.count, l)}</span></li>
|
|
133
|
+
))}
|
|
134
|
+
</ul>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div className={['rs', isMap && 'is-map', className].filter(Boolean).join(' ')} data-rs-root="" data-rs-view={p.view}>
|
|
139
|
+
{!nothingAtAll && (
|
|
140
|
+
<form method="get" action={base} className="rs-form" data-rs-form="" role="search" aria-label={t('filters', {}, l)}>
|
|
141
|
+
{isMap && <input type="hidden" name="view" value="map" />}
|
|
142
|
+
{p.status === 'sold' && <input type="hidden" name="status" value="sold" />}
|
|
143
|
+
<div className="rs-top">
|
|
144
|
+
<button type="button" className="rs-filters-btn" popoverTarget="rs-sheet">
|
|
145
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round"><path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0" /><circle cx="16" cy="6" r="2" /><circle cx="10" cy="12" r="2" /><circle cx="18" cy="18" r="2" /></svg>
|
|
146
|
+
<span>{t('filters', {}, l)}</span>
|
|
147
|
+
<span className="rs-badge" data-rs-swap="badge" hidden={!nFilters}>{nFilters}</span>
|
|
148
|
+
</button>
|
|
149
|
+
<div id="rs-sheet" className="rs-sheet" popover="auto">
|
|
150
|
+
<div className="rs-sheet-head">
|
|
151
|
+
<p className="rs-sheet-title">{t('filters', {}, l)}</p>
|
|
152
|
+
<button type="button" className="rs-sheet-close" popoverTarget="rs-sheet" popoverTargetAction="hide" aria-label={t('close', {}, l)}>
|
|
153
|
+
<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
154
|
+
</button>
|
|
155
|
+
</div>
|
|
156
|
+
{showOffer && (
|
|
157
|
+
<fieldset className="rs-offer field">
|
|
158
|
+
<legend className="field-label">{t('offer', {}, l)}</legend>
|
|
159
|
+
<div className="rs-seg">
|
|
160
|
+
<label><input type="radio" name="offerType" value="" defaultChecked={!p.offerType} /><span>{t('all', {}, l)}</span></label>
|
|
161
|
+
<label><input type="radio" name="offerType" value="buy" defaultChecked={p.offerType === 'buy'} /><span>{t('offerBuy', {}, l)}</span></label>
|
|
162
|
+
<label><input type="radio" name="offerType" value="rent" defaultChecked={p.offerType === 'rent'} /><span>{t('offerRent', {}, l)}</span></label>
|
|
163
|
+
</div>
|
|
164
|
+
</fieldset>
|
|
165
|
+
)}
|
|
166
|
+
{!showOffer && p.offerType && <input type="hidden" name="offerType" value={p.offerType} />}
|
|
167
|
+
{show('city') && cityOptions.length > 1 && (
|
|
168
|
+
<Combobox label={t('city', {}, l)} name="city" value={p.city} placeholder={t('allCities', {}, l)} options={cityOptions} className="rs-city" />
|
|
169
|
+
)}
|
|
170
|
+
{show('propertyType') && typeOptions.length > 1 && (
|
|
171
|
+
<Select label={t('propertyType', {}, l)} name="propertyType" value={p.propertyType} placeholder={t('all', {}, l)} options={typeOptions} className="rs-type" />
|
|
172
|
+
)}
|
|
173
|
+
{show('price') && priceOptions.length > 0 && (
|
|
174
|
+
<Select label={t('price', {}, l)} name="maxPrice" value={p.maxPrice ? String(p.maxPrice) : undefined} placeholder={t('any', {}, l)} options={priceOptions} className="rs-price" />
|
|
175
|
+
)}
|
|
176
|
+
{p.minPrice && <input type="hidden" name="minPrice" value={String(p.minPrice)} />}
|
|
177
|
+
{show('rooms') && roomOptions.length > 1 && (
|
|
178
|
+
<Select label={t('rooms', {}, l)} name="minRooms" value={p.minRooms ? String(p.minRooms) : undefined} placeholder={t('any', {}, l)} options={roomOptions} className="rs-rooms" />
|
|
179
|
+
)}
|
|
180
|
+
<Button type="submit" className="rs-apply"><span data-rs-swap="apply">{count('showListings', total, l)}</span></Button>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div className="rs-bar">
|
|
185
|
+
<p className="rs-count" data-rs-count="" data-rs-swap="count" aria-live="polite" tabIndex={-1}>{count('listingsFound', total, l)}</p>
|
|
186
|
+
<div className="rs-tools">
|
|
187
|
+
{sold && counts.sold > 0 && (
|
|
188
|
+
<nav className="rs-status" aria-label={t('status', {}, l)} data-rs-swap="status">
|
|
189
|
+
<a href={href({ status: undefined })} aria-current={p.status === 'available' ? 'page' : undefined}>{t('currentListings', {}, l)}</a>
|
|
190
|
+
<a href={href({ status: 'sold' })} aria-current={p.status === 'sold' ? 'page' : undefined}>{t('soldListings', {}, l)} <span className="rs-n">{counts.sold}</span></a>
|
|
191
|
+
</nav>
|
|
192
|
+
)}
|
|
193
|
+
<Select label={t('sort', {}, l)} hideLabel name="sort" value={p.sort} options={sortOptions} className="rs-sort" />
|
|
194
|
+
<nav className="rs-views" aria-label={`${t('viewList', {}, l)} / ${t('viewMap', {}, l)}`} data-rs-swap="views">
|
|
195
|
+
<a href={href({ view: undefined })} data-rs-nav="" data-rs-view="list" aria-current={!isMap ? 'page' : undefined}><GridIcon />{t('viewList', {}, l)}</a>
|
|
196
|
+
<a href={href({ view: 'map' })} data-rs-nav="" data-rs-view="map" aria-current={isMap ? 'page' : undefined}><MapIcon />{t('viewMap', {}, l)}</a>
|
|
197
|
+
</nav>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
</form>
|
|
201
|
+
)}
|
|
202
|
+
|
|
203
|
+
<div className="rs-chips" data-rs-chips="" data-rs-swap="chips" hidden={!nFilters} aria-label={t('activeFilters', {}, l)} role="group">
|
|
204
|
+
{result.chips.map((k) => (
|
|
205
|
+
<a key={k} className="rs-chip" href={href({ [k]: undefined })} data-rs-nav="" aria-label={t('removeFilter', { filter: chipLabel(k) }, l)}>
|
|
206
|
+
{chipLabel(k)}<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path d="M7 7l10 10M17 7L7 17" /></svg>
|
|
207
|
+
</a>
|
|
208
|
+
))}
|
|
209
|
+
{nFilters > 1 && <a className="rs-reset" href={resetHref} data-rs-nav="">{t('resetFilters', {}, l)}</a>}
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<div className="rs-region" data-rs-swap="results">
|
|
213
|
+
{nothingAtAll ? (
|
|
214
|
+
empty ? <div data-rs-empty="none">{empty}</div> : (
|
|
215
|
+
<div className="rs-empty" data-rs-empty="none">
|
|
216
|
+
<h2 className="rs-empty-title">{t('noListings', {}, l)}</h2>
|
|
217
|
+
<p className="rs-empty-text">{t('noListingsText', {}, l)}</p>
|
|
218
|
+
<p className="rs-empty-actions">
|
|
219
|
+
{valuationHref && <Button href={valuationHref}>{t('valuation', {}, l)}</Button>}
|
|
220
|
+
{contactHref && <Button href={contactHref} variant="secondary">{t('contactUs', {}, l)}</Button>}
|
|
221
|
+
</p>
|
|
222
|
+
</div>
|
|
223
|
+
)
|
|
224
|
+
) : mapMode ? (
|
|
225
|
+
<>
|
|
226
|
+
{result.truncated && <p className="rs-note">{t('mapTruncated', { n: String(result.mapItems.length) }, l)}</p>}
|
|
227
|
+
<div className="rs-results rs-split">
|
|
228
|
+
<div className="rs-col">
|
|
229
|
+
{total > 0 ? (
|
|
230
|
+
<ul id="rs-results" className="rs-grid rs-list" data-rs-results="">
|
|
231
|
+
{result.items.map((x, i) => <li key={x.id} data-listing-id={x.id}>{card(x, i)}</li>)}
|
|
232
|
+
</ul>
|
|
233
|
+
) : (
|
|
234
|
+
<div className="rs-empty rs-empty-area" data-rs-empty="area">
|
|
235
|
+
<h2 className="rs-empty-title">{t('noneInArea', {}, l)}</h2>
|
|
236
|
+
<p className="rs-empty-text">{t('noneInAreaText', {}, l)}</p>
|
|
237
|
+
{relax}
|
|
238
|
+
<p className="rs-empty-actions"><Button href={resetHref} data-rs-reset data-rs-nav>{t('resetFilters', {}, l)}</Button></p>
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
241
|
+
<ListingsPager result={result} href={href} locale={locale} />
|
|
242
|
+
</div>
|
|
243
|
+
<div className="rs-map" data-rs-map="">
|
|
244
|
+
<div className="rs-follow" data-rs-follow-bar="">
|
|
245
|
+
<label className="rs-follow-toggle"><input type="checkbox" data-rs-follow="" defaultChecked /> <span>{t('searchAsMove', {}, l)}</span></label>
|
|
246
|
+
<button type="button" className="rs-search-area" data-rs-search-area="" hidden>{t('searchThisArea', {}, l)}</button>
|
|
247
|
+
</div>
|
|
248
|
+
<ListingsMap
|
|
249
|
+
listings={result.mapItems}
|
|
250
|
+
list="rs-results"
|
|
251
|
+
locale={locale}
|
|
252
|
+
view={mapView(p.map)}
|
|
253
|
+
sync
|
|
254
|
+
listMode="server"
|
|
255
|
+
href={listingHref}
|
|
256
|
+
price={price}
|
|
257
|
+
/>
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
</>
|
|
261
|
+
) : total === 0 ? (
|
|
262
|
+
<div className="rs-empty" data-rs-empty="nomatch">
|
|
263
|
+
<h2 className="rs-empty-title">{t('noMatch', {}, l)}</h2>
|
|
264
|
+
<p className="rs-empty-text">{t('noMatchText', {}, l)}</p>
|
|
265
|
+
{relax}
|
|
266
|
+
<p className="rs-empty-actions">
|
|
267
|
+
<Button href={resetHref} data-rs-reset data-rs-nav>{t('resetFilters', {}, l)}</Button>
|
|
268
|
+
{tellUsHref && <Button href={tellUsHref} variant="secondary">{t('tellUs', {}, l)}</Button>}
|
|
269
|
+
</p>
|
|
270
|
+
</div>
|
|
271
|
+
) : (
|
|
272
|
+
<>
|
|
273
|
+
{isMap && <p className="rs-note">{t('noCoords', {}, l)}</p>}
|
|
274
|
+
<div className="rs-results">
|
|
275
|
+
<ul id="rs-results" className="rs-grid" data-rs-results="">
|
|
276
|
+
{result.items.map((x, i) => <li key={x.id} data-listing-id={x.id}>{card(x, i)}</li>)}
|
|
277
|
+
</ul>
|
|
278
|
+
</div>
|
|
279
|
+
<ListingsPager result={result} href={href} locale={locale} />
|
|
280
|
+
</>
|
|
281
|
+
)}
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
{!nothingAtAll && total > 0 && (
|
|
285
|
+
<a className="rs-pill" data-rs-pill="" data-rs-nav="" data-rs-swap="pill" href={href({ view: isMap ? undefined : 'map' })}>
|
|
286
|
+
{isMap ? <GridIcon /> : <MapIcon />}
|
|
287
|
+
{isMap ? t('viewList', {}, l) : t('viewMap', {}, l)}
|
|
288
|
+
</a>
|
|
289
|
+
)}
|
|
290
|
+
</div>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export default ListingsSearch;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE way to show a listing, agent, agency or place photo (port of the Astro
|
|
3
|
+
* kit's RaImage.astro, same URLs and srcsets). imgproxy at the size you
|
|
4
|
+
* render, srcset, sizes, width/height, lazy by default; `priority` for the
|
|
5
|
+
* page's one LCP image (eager, fetchpriority high, a preload React hoists
|
|
6
|
+
* into <head>, at most 1600w, quality 70).
|
|
7
|
+
*
|
|
8
|
+
* Added over the Astro version (what the Astro sites built themselves):
|
|
9
|
+
* - `avif`: an AVIF <source> (default: on the priority image only, as on
|
|
10
|
+
* Astro; a lazy photo stays a plain <img>, so CSS that sizes `> img` holds);
|
|
11
|
+
* - `position`: object-position / focal point for boxes that crop further;
|
|
12
|
+
* - `crop`: a part of the original (fractions), e.g. a square out of a
|
|
13
|
+
* portrait photo, before the resize.
|
|
14
|
+
*
|
|
15
|
+
* <RaImage src={l.photos[0]} alt="…" width={800} height={600} sizes="(min-width: 1024px) 33vw, 100vw" />
|
|
16
|
+
* <RaImage src={hero} alt="" width={1600} height={1200} priority mobile={{ width: 800, height: 640 }} data-hero />
|
|
17
|
+
*
|
|
18
|
+
* `data-*` attributes go on the <img> (as Astro's `...rest`).
|
|
19
|
+
*/
|
|
20
|
+
import type { CSSProperties } from 'react';
|
|
21
|
+
import { preload } from 'react-dom';
|
|
22
|
+
import { imgUrl, srcsetUrl, type Crop } from '../lib/image';
|
|
23
|
+
|
|
24
|
+
export type RaImageProps = {
|
|
25
|
+
/** A photo of the data (`{ url, alt }`) or a URL. */
|
|
26
|
+
src: { url: string; alt?: string } | string | null | undefined;
|
|
27
|
+
alt: string;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
/** Browser layout width per breakpoint. Default 100vw. */
|
|
31
|
+
sizes?: string;
|
|
32
|
+
priority?: boolean;
|
|
33
|
+
fit?: 'fill' | 'fit';
|
|
34
|
+
widths?: number[];
|
|
35
|
+
quality?: number;
|
|
36
|
+
/** Crop for screens under 768px: box ratio width/height and sizes. */
|
|
37
|
+
mobile?: { width: number; height: number; sizes?: string };
|
|
38
|
+
/** AVIF source first (default: `priority`, as the Astro kit). */
|
|
39
|
+
avif?: boolean;
|
|
40
|
+
/** object-position of the rendered photo, e.g. "50% 30%". */
|
|
41
|
+
position?: string;
|
|
42
|
+
/** Part of the original to use, in fractions of its size. */
|
|
43
|
+
crop?: Crop;
|
|
44
|
+
className?: string;
|
|
45
|
+
style?: CSSProperties;
|
|
46
|
+
/** `data-*` attributes, on the <img> (e.g. `data-hero`). */
|
|
47
|
+
[data: `data-${string}`]: string | number | boolean | undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const MOBILE = '(max-width: 767px)';
|
|
51
|
+
const DESKTOP = '(min-width: 768px)';
|
|
52
|
+
const MOBILE_W = [480, 600, 800, 1200];
|
|
53
|
+
|
|
54
|
+
export function RaImage(props: RaImageProps) {
|
|
55
|
+
const { src, alt, width, height, priority = false, fit = 'fill', mobile, avif = priority, position, crop, className } = props;
|
|
56
|
+
const data = Object.fromEntries(Object.entries(props).filter(([k]) => k.startsWith('data-')));
|
|
57
|
+
const url = typeof src === 'string' ? src : src?.url;
|
|
58
|
+
if (!url) return null;
|
|
59
|
+
const widths = props.widths ?? (priority ? [640, 960, 1280, 1600] : [480, 768, 1200, 1920]);
|
|
60
|
+
const quality = props.quality ?? (priority ? 70 : undefined);
|
|
61
|
+
const sizes = props.sizes ?? (priority ? '(min-width: 1440px) 1440px, 100vw' : '100vw');
|
|
62
|
+
const ratio = fit === 'fill' ? width / height : undefined;
|
|
63
|
+
const set = srcsetUrl(url, widths, ratio, { quality, crop });
|
|
64
|
+
const avifSet = set && avif ? srcsetUrl(url, widths, ratio, { quality, crop, format: 'avif' }) : '';
|
|
65
|
+
const fallbackW = Math.min(1200, Math.max(...widths.filter((w) => w <= 1200), widths[0] ?? 768));
|
|
66
|
+
const fallback = imgUrl(url, { w: fallbackW, h: ratio ? Math.round(fallbackW / ratio) : 0, fit, quality, crop });
|
|
67
|
+
const mRatio = mobile ? mobile.width / mobile.height : 0;
|
|
68
|
+
const mobileSet = mobile ? srcsetUrl(url, MOBILE_W, mRatio, { quality, crop }) : '';
|
|
69
|
+
const mobileAvif = mobileSet && avif ? srcsetUrl(url, MOBILE_W, mRatio, { quality, crop, format: 'avif' }) : '';
|
|
70
|
+
const mobileSizes = mobile?.sizes ?? '100vw';
|
|
71
|
+
const style = position ? { objectPosition: position, ...props.style } : props.style;
|
|
72
|
+
const image = (
|
|
73
|
+
<img
|
|
74
|
+
src={fallback}
|
|
75
|
+
srcSet={set || undefined}
|
|
76
|
+
sizes={set ? sizes : undefined}
|
|
77
|
+
width={width}
|
|
78
|
+
height={height}
|
|
79
|
+
alt={alt}
|
|
80
|
+
loading={priority ? 'eager' : 'lazy'}
|
|
81
|
+
fetchPriority={priority ? 'high' : undefined}
|
|
82
|
+
decoding="async"
|
|
83
|
+
className={className}
|
|
84
|
+
style={style}
|
|
85
|
+
{...data}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
const usePicture = !!(mobileSet || avifSet);
|
|
89
|
+
// Preloads (React puts them in <head>): the format the browser will pick first (AVIF when there is one).
|
|
90
|
+
if (priority) {
|
|
91
|
+
if (mobileSet) preload(fallback, { as: 'image', type: mobileAvif ? 'image/avif' : undefined, media: MOBILE, imageSrcSet: mobileAvif || mobileSet, imageSizes: mobileSizes, fetchPriority: 'high' });
|
|
92
|
+
if (set) preload(fallback, { as: 'image', type: avifSet ? 'image/avif' : undefined, media: mobileSet ? DESKTOP : undefined, imageSrcSet: avifSet || set, imageSizes: sizes, fetchPriority: 'high' });
|
|
93
|
+
}
|
|
94
|
+
if (!usePicture) return image;
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
<picture>
|
|
98
|
+
{mobileAvif && <source media={MOBILE} type="image/avif" srcSet={mobileAvif} sizes={mobileSizes} width={mobile!.width} height={mobile!.height} />}
|
|
99
|
+
{mobileSet && <source media={MOBILE} srcSet={mobileSet} sizes={mobileSizes} width={mobile!.width} height={mobile!.height} />}
|
|
100
|
+
{avifSet && <source type="image/avif" srcSet={avifSet} sizes={sizes} />}
|
|
101
|
+
{image}
|
|
102
|
+
</picture>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default RaImage;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich text (listing, team, development descriptions) sanitized where the
|
|
3
|
+
* data is read, typically in the loader, and rendered with a type that says so:
|
|
4
|
+
*
|
|
5
|
+
* // loader (server): the client chunk gets the clean HTML, not the raw field
|
|
6
|
+
* return { description: sanitized(listing.description) };
|
|
7
|
+
* // page
|
|
8
|
+
* <SafeHtml html={loaderData.description} className="prose" />
|
|
9
|
+
*
|
|
10
|
+
* `SanitizedHtml` comes out of `sanitized()` (the kit's sanitizeHtml), so
|
|
11
|
+
* tsc rejects a raw string (never build one by hand), and check:deploy needs no sanitizeHtml(...) call
|
|
12
|
+
* written inside `dangerouslySetInnerHTML` (it still flags any other
|
|
13
|
+
* `dangerouslySetInnerHTML` in app/). It is a plain object, so it passes
|
|
14
|
+
* through loader data (JSON) unchanged.
|
|
15
|
+
*/
|
|
16
|
+
import { sanitizeHtml } from '@realadvisor/sites-kit';
|
|
17
|
+
|
|
18
|
+
/** HTML that went through sanitizeHtml: make it with `sanitized()` only (a string brand: it survives loader serialization). */
|
|
19
|
+
export type SanitizedHtml = { readonly kind: 'sanitized-html'; readonly sanitizedHtml: string };
|
|
20
|
+
|
|
21
|
+
export const sanitized = (html: string | null | undefined): SanitizedHtml => ({ kind: 'sanitized-html', sanitizedHtml: html ? sanitizeHtml(html) : '' });
|
|
22
|
+
|
|
23
|
+
type Tag = 'div' | 'section' | 'article' | 'span' | 'p' | 'blockquote';
|
|
24
|
+
|
|
25
|
+
export function SafeHtml({ html, as: As = 'div', className, id }: { html: SanitizedHtml | null | undefined; as?: Tag; className?: string; id?: string }) {
|
|
26
|
+
if (!html?.sanitizedHtml) return null;
|
|
27
|
+
return <As className={className} id={id} dangerouslySetInnerHTML={{ __html: html.sanitizedHtml }} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default SafeHtml;
|