diff --git a/src/components/button-filter.tsx b/src/components/button-filter.tsx new file mode 100644 index 0000000..1a5a6b0 --- /dev/null +++ b/src/components/button-filter.tsx @@ -0,0 +1,15 @@ +import classNames from "classnames"; +import { ReactNode } from "react"; + +export function FilterButton({ children, onClick, active }: { children: ReactNode, onClick?: () => Promise | void, active?: boolean }) { + return
+ {children} +
+} \ No newline at end of file diff --git a/src/pages/home.tsx b/src/pages/home.tsx index 3a0bba1..0cd6fd0 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -1,17 +1,30 @@ import { useState, useEffect } from "react"; -import { LNVpsApi, VmTemplateResponse } from "../api"; +import { LNVpsApi, VmHostRegion, VmTemplateResponse } from "../api"; import VpsCard from "../components/vps-card"; import { ApiUrl, NostrProfile } from "../const"; import { Link } from "react-router-dom"; import { VpsCustomOrder } from "../components/vps-custom"; import { LatestNews } from "../components/latest-news"; +import { FilterButton } from "../components/button-filter"; +import { dedupe } from "@snort/shared"; export default function HomePage() { const [offers, setOffers] = useState(); + const [region, setRegion] = useState>([]); + + const regions = (offers?.templates.map((t) => t.region) ?? []).reduce((acc, v) => { + if (acc[v.id] === undefined) { + acc[v.id] = v; + } + return acc; + }, {} as Record); useEffect(() => { const api = new LNVpsApi(ApiUrl, undefined); - api.listOffers().then((o) => setOffers(o)); + api.listOffers().then((o) => { + setOffers(o) + setRegion(dedupe(o.templates.map((z) => z.region.id))); + }); }, []); return ( @@ -23,8 +36,24 @@ export default function HomePage() { Virtual Private Server hosting with flexible plans, high uptime, and dedicated support, tailored to your needs. + {Object.keys(regions).length > 1 &&
+ Regions: + {Object.values(regions).map((r) => { + return setRegion(x => { + if (x.includes(r.id)) { + return x.filter(y => y != r.id); + } else { + return [...x, r.id]; + } + })}> + {r.name} + ; + })} +
}
- {offers?.templates.map((a) => )} + {offers?.templates.filter((t) => region.includes(t.region.id)).sort((a, b) => a.cost_plan.amount - b.cost_plan.amount).map((a) => )} {offers?.templates !== undefined && offers.templates.length === 0 && (
No offers available