hook up query parameters form with rest query
This commit is contained in:
parent
3574df8ae0
commit
7c70da4bed
3 changed files with 19 additions and 17 deletions
|
|
@ -5,7 +5,7 @@ import { AppSidebar } from './AppSidebar';
|
||||||
import { getUser, handleCallback, logout } from './auth/authService';
|
import { getUser, handleCallback, logout } from './auth/authService';
|
||||||
import LoginModal from './components/LoginModal';
|
import LoginModal from './components/LoginModal';
|
||||||
import { Map } from './components/Map';
|
import { Map } from './components/Map';
|
||||||
import { Parameters } from './components/Parameters';
|
import { Parameters, type ParameterValues } from './components/Parameters';
|
||||||
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from './components/ui/breadcrumb';
|
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from './components/ui/breadcrumb';
|
||||||
import { Button } from './components/ui/button';
|
import { Button } from './components/ui/button';
|
||||||
import { Separator } from './components/ui/separator';
|
import { Separator } from './components/ui/separator';
|
||||||
|
|
@ -30,6 +30,7 @@ function App() {
|
||||||
|
|
||||||
const [isParametersModalOpen, setIsParametersModalOpen] = useState(true)
|
const [isParametersModalOpen, setIsParametersModalOpen] = useState(true)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
const [queryParameters, setQueryParameters] = useState<ParameterValues | null>(null)
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -52,8 +53,9 @@ function App() {
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onSubmit = async () => {
|
const onSubmit = async (parameters: ParameterValues) => {
|
||||||
// Fetch listing data
|
// Fetch listing data
|
||||||
|
setQueryParameters(parameters)
|
||||||
const data = await fetchData();
|
const data = await fetchData();
|
||||||
if (data) {
|
if (data) {
|
||||||
setListingData(data);
|
setListingData(data);
|
||||||
|
|
@ -98,7 +100,7 @@ function App() {
|
||||||
</div>
|
</div>
|
||||||
{Object.keys(listingData).length > 0 &&
|
{Object.keys(listingData).length > 0 &&
|
||||||
<div className="flex-1 w-full relative" style={{ minHeight: 0, marginBottom: '8rem' }}>
|
<div className="flex-1 w-full relative" style={{ minHeight: 0, marginBottom: '8rem' }}>
|
||||||
<Map listingData={listingData} />
|
<Map listingData={listingData} queryParameters={queryParameters} />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// @ts-nocheck
|
// // @ts-nocheck
|
||||||
import crossfilter from "crossfilter2";
|
import crossfilter from "crossfilter2";
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
import mapboxgl from "mapbox-gl";
|
import mapboxgl from "mapbox-gl";
|
||||||
|
|
@ -6,6 +6,7 @@ import 'mapbox-gl/dist/mapbox-gl.css'; // this hides the map for some reason
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { renderToString } from 'react-dom/server';
|
import { renderToString } from 'react-dom/server';
|
||||||
import "../assets/Map.css";
|
import "../assets/Map.css";
|
||||||
|
import { Metric, type ParameterValues } from "./Parameters";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
import { ScrollArea } from "./ui/scroll-area";
|
import { ScrollArea } from "./ui/scroll-area";
|
||||||
import { Separator } from "./ui/separator";
|
import { Separator } from "./ui/separator";
|
||||||
|
|
@ -13,6 +14,7 @@ import { Separator } from "./ui/separator";
|
||||||
export function Map(
|
export function Map(
|
||||||
props: {
|
props: {
|
||||||
listingData: any;
|
listingData: any;
|
||||||
|
queryParameters: ParameterValues | null;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const data = props.listingData;
|
const data = props.listingData;
|
||||||
|
|
@ -33,8 +35,11 @@ export function Map(
|
||||||
let heatmap = null;
|
let heatmap = null;
|
||||||
|
|
||||||
// rivet
|
// rivet
|
||||||
var filter = { city: 'London', country: null, mode: 'qmprice' };
|
var filter = { city: 'London', country: null, mode: Metric.qmprice };
|
||||||
// filter['countries'] = Array.from(new Set(data.features.map(function (d) { return d['properties']['country'] })));
|
// filter['countries'] = Array.from(new Set(data.features.map(function (d) { return d['properties']['country'] })));
|
||||||
|
if (props.queryParameters) {
|
||||||
|
filter['mode'] = props.queryParameters.metric;
|
||||||
|
}
|
||||||
// rivets.bind(document.getElementById('overlay'), { filter: filter });
|
// rivets.bind(document.getElementById('overlay'), { filter: filter });
|
||||||
const mapRef = useRef(mapboxgl.Map)
|
const mapRef = useRef(mapboxgl.Map)
|
||||||
const mapContainerRef = useRef('map-container')
|
const mapContainerRef = useRef('map-container')
|
||||||
|
|
@ -85,7 +90,7 @@ export function Map(
|
||||||
heatmap.setCellDensity(0.5); // small value == bigger hexagons
|
heatmap.setCellDensity(0.5); // small value == bigger hexagons
|
||||||
heatmap.setPropertyName(filter.mode);
|
heatmap.setPropertyName(filter.mode);
|
||||||
|
|
||||||
if (filter.mode === 'qmprice') {
|
if (filter.mode === Metric.qmprice) {
|
||||||
// if we visualize sqm based data, remove properties where we have no data
|
// if we visualize sqm based data, remove properties where we have no data
|
||||||
qmDim.filter(function (d) { return d > 0; });
|
qmDim.filter(function (d) { return d > 0; });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,15 @@ import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, For
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
||||||
|
|
||||||
|
|
||||||
enum Metric {
|
export enum Metric {
|
||||||
qmprice = 'Price per square meter',
|
qmprice = 'qmprice',
|
||||||
rooms = 'Number of rooms',
|
rooms = 'rooms',
|
||||||
qm = 'Area',
|
qm = 'qm',
|
||||||
price = 'Price',
|
price = 'total_price',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface ParameterValues {
|
export interface ParameterValues {
|
||||||
metric: Metric
|
metric: Metric
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,12 +28,8 @@ export function Parameters(
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
watch,
|
|
||||||
formState: { errors },
|
|
||||||
} = useForm<ParameterValues>()
|
} = useForm<ParameterValues>()
|
||||||
// const onSubmit: SubmitHandler<ParameterValues> = (data) => console.log(data)
|
// const onSubmit: SubmitHandler<ParameterValues> = (data) => console.log(data)
|
||||||
console.log(watch("metric"))
|
|
||||||
console.log(errors)
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
metric: z.nativeEnum(Metric, { required_error: "Metric is required" }),
|
metric: z.nativeEnum(Metric, { required_error: "Metric is required" }),
|
||||||
|
|
@ -48,7 +44,6 @@ export function Parameters(
|
||||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||||
// Do something with the form values.
|
// Do something with the form values.
|
||||||
// ✅ This will be type-safe and validated.
|
// ✅ This will be type-safe and validated.
|
||||||
console.log(values)
|
|
||||||
props.onSubmit(values)
|
props.onSubmit(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue