Add services layer, tests, streaming UI, and cleanup legacy code

This commit is contained in:
Viktor Barzin 2026-02-06 20:55:10 +00:00
parent 5514fa6381
commit d205d15c74
62 changed files with 3729 additions and 1024 deletions

View file

@ -1,8 +1,6 @@
import { getUser } from "@/auth/authService";
import { zodResolver } from "@hookform/resolvers/zod";
import { DialogTitle } from "@radix-ui/react-dialog";
import type { User } from "oidc-client-ts";
import { useEffect, useState } from "react";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { Button } from "./ui/button";
@ -24,6 +22,12 @@ export enum ListingType {
BUY = 'BUY'
}
export enum FurnishType {
FURNISHED = 'furnished',
PART_FURNISHED = 'partFurnished',
UNFURNISHED = 'unfurnished',
}
export interface ParameterValues {
metric: Metric
@ -33,30 +37,15 @@ export interface ParameterValues {
min_price?: number
max_price?: number
min_sqm?: number
max_sqm?: number
min_price_per_sqm?: number
max_price_per_sqm?: number
last_seen_days?: number
available_from?: Date
district: string
furnish_types?: FurnishType[]
}
const fetchDistricts = async (user: User | null) => {
const accessToken = user?.access_token;
const response = await fetch('/api/get_districts',
{
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`, // Pass the token
'Content-Type': 'application/json',
},
}
);
if (!response.ok) {
throw new Error('Error: ' + response.status);
}
const data: Response = await response.json();
return data;
};
export function Parameters(
props: {
isOpen: boolean,
@ -69,15 +58,6 @@ export function Parameters(
} = useForm<ParameterValues>()
const [action, setAction] = useState<'fetch-data' | 'visualize' | null>(null)
const [availableFromRawInput, setAvailableFromRawInput] = useState("now");
const [_districts, setDistricts] = useState<string[]>([]);
useEffect(() => {
getUser().then(user => {
fetchDistricts(user).then(data => {
setDistricts(Object.keys(data));
})
})
}, []);
const formSchema = z.object({
metric: z.nativeEnum(Metric, { required_error: "Metric is required" }),
@ -177,29 +157,6 @@ export function Parameters(
</FormItem>
)}
/>
{/* <FormField # listings don't have district stored as metadata; so only useful in rightmove querying
control={form.control}
name="district"
render={({ field }) => (
<FormItem className="flex flex-row items-center gap-4">
<FormLabel>District</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="District" />
</SelectTrigger>
</FormControl>
<SelectContent {...register('district')} >
{districts.map((district, index) => (
<SelectItem key={index} value={district}>{district}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/> */}
<FormField
control={form.control}
name="min_sqm"