Content-Length: 342828 | pFad | http://github.com/PHS-TSA/webmaster-23-24/pull/59/commits/e98097aa5e2a579a21dc086e4474dad2d42f7037

0C Effect.TS by lishaduck · Pull Request #59 · PHS-TSA/webmaster-23-24 · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effect.TS #59

Merged
merged 12 commits into from
Nov 7, 2024
Prev Previous commit
Next Next commit
refactor: use @effect/schema for geothermal
  • Loading branch information
lishaduck committed Nov 6, 2024
commit e98097aa5e2a579a21dc086e4474dad2d42f7037
12 changes: 6 additions & 6 deletions src/routes/calculator/results.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Head } from "$fresh/runtime.ts";
import type { Handlers, PageProps, RouteConfig } from "$fresh/server.ts";
import { Schema } from "@effect/schema";
import { IconCheck } from "@tabler/icons-preact";
import { Either } from "effect";
import type { ComponentChildren, JSX } from "preact";
import CalculatorScaffold from "../../components/CalculatorScaffold.tsx";
import { Cover } from "../../components/Cover.tsx";
import { Meta } from "../../components/Meta.tsx";
import {
type GeoCostBreakdown,
geothermalLoopType,
} from "../../utils/calc/geo.ts";
import {
GeothermalLoopTypeSchema,
calculatePricing,
calculatePricingFromType,
calculatePricingIfHardInstallation,
Expand Down Expand Up @@ -67,14 +67,14 @@ function parseData(
const region = data.get("region[value]")?.toString();
const isHilly = data.get("hills")?.toString() ?? "";
const renovations = data.get("renovations")?.toString() ?? "";
const geoType = geothermalLoopType.safeParse(
const geoType = Schema.decodeUnknownEither(GeothermalLoopTypeSchema)(
data.get("geo-type[value]")?.toString(),
);
const squareFootage = data.get("area")?.toString();
const requiresPermit = data.get("permit")?.toString() ?? "";

if (
geoType.success &&
Either.isRight(geoType) &&
region !== undefined &&
Object.hasOwn(stateData, region)
) {
Expand All @@ -87,7 +87,7 @@ function parseData(
geoCostData: {
isHilly: Boolean(isHilly),
needsRenovations: Boolean(renovations),
type: geoType.data,
type: geoType.right,
squareFootage: Number(squareFootage),
requiresPermit: Boolean(requiresPermit),
},
Expand Down
16 changes: 8 additions & 8 deletions src/utils/calc/geo.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { z } from "zod";
import { Schema } from "@effect/schema";

export type GeoType = z.infer<typeof geothermalLoopType>;
export type GeoType = typeof GeothermalLoopTypeSchema.Type;

export const geothermalLoopType = z.union([
z.literal("horizontal"),
z.literal("vertical"),
z.literal("open"),
z.literal("closed"),
]);
export const GeothermalLoopTypeSchema = Schema.Literal(
"horizontal",
"vertical",
"open",
"closed",
);

export interface GeoCostBreakdown {
/** +$2000 */
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/PHS-TSA/webmaster-23-24/pull/59/commits/e98097aa5e2a579a21dc086e4474dad2d42f7037

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy