Skip to content

Commit

Permalink
Merge pull request #77 from PHS-TSA/todos
Browse files Browse the repository at this point in the history
Misc
  • Loading branch information
lishaduck authored Oct 20, 2024
2 parents 0093279 + 6715ad4 commit cabf089
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 37 deletions.
10 changes: 6 additions & 4 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function createCarouselStyles(number: number): string {
}
`;

const delays = Array.from({ length: number })
const delayList = Array.from({ length: number })
.map((_, i) => {
return css`
&:nth-child(${i + 1}) {
Expand All @@ -73,6 +73,10 @@ function createCarouselStyles(number: number): string {
`;
})
.join("\n");
const delays = css`
.carousel > img {
${delayList}
}`;

return css`
.carousel > img {
Expand All @@ -88,9 +92,7 @@ function createCarouselStyles(number: number): string {
}
}
.carousel > img {
${delays}
}
${delays}
${keyframes}
`;
Expand Down
1 change: 0 additions & 1 deletion src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ function RenderCategory(props: Menu): JSX.Element {
* @param props.title - The title of the link.
* @returns The rendered category header.
*/
// TODO(lishaduck): Add a <Link> component to centralize anchor styling.
function RenderCategoryHeader({ url, title }: BasicMenu): JSX.Element {
return (
<a
Expand Down
2 changes: 0 additions & 2 deletions src/islands/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ function ChatbotBox(props: JSX.HTMLAttributes<HTMLDivElement>): JSX.Element {
<form
class="py-2 place-items-center"
onSubmit={async (e) => {
// TODO(lishaduck): Enable moderation.

e.preventDefault();

if (threadId.value === undefined) {
Expand Down
6 changes: 1 addition & 5 deletions src/islands/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export interface SelectorProps<T extends string, U extends T> {
readonly required?: boolean;
/** A hacky way to get Fresh to serialize the `info` prop. */
readonly children?: ComponentChildren;
/** A hacky way to get Fresh *not* to serialize the `info` prop. */
// TODO(lishaduck): Is this really needed?
readonly hasInfo?: boolean;
}

export interface SelectorListObject<T extends string> {
Expand Down Expand Up @@ -56,7 +53,6 @@ export function Selector<T extends string, U extends T>({
current: currentValue,
required,
children: info,
hasInfo,
}: SelectorProps<T, U>): JSX.Element {
const current = useSignal(
list.find((val) => val.name === currentValue) ?? { name: "", value: "" },
Expand Down Expand Up @@ -109,7 +105,7 @@ export function Selector<T extends string, U extends T>({
>
<Label className={labelStyles}>
{question}
{hasInfo && (
{info !== undefined && (
<>
{" "}
<Info>{info}</Info>
Expand Down
3 changes: 2 additions & 1 deletion src/routes/calculator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const handler: Handlers<CalculatorSearchProps> = {
_req: Request,
ctx: FreshContextHelper<CalculatorSearchProps>,
): Promise<Response> {
// Debug is true when developing to avoid rate limiting.
// If you need to test this code, replace `DEBUG` with `false`.
const visitor = DEBUG
? undefined
: await getIpLocation(ctx.remoteAddr.hostname);
Expand Down Expand Up @@ -92,7 +94,6 @@ export default function Calculator({
]}
current="horizontal"
required
hasInfo={true}
>
See{" "}
<a href="/solutions/geothermal/what/">
Expand Down
11 changes: 7 additions & 4 deletions src/routes/calculator/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { type StateData, stateData } from "../../utils/calc/solar.ts";
import { useCsp } from "../../utils/csp.ts";
import type { FreshContextHelper } from "../../utils/handlers.ts";
import { usdFormat, yearFormat } from "../../utils/intl.ts";
import { isKey } from "../../utils/type-helpers.ts";

export const config = {
csp: true,
Expand Down Expand Up @@ -76,11 +75,15 @@ function parseData(

if (
geoType.success &&
typeof region === "string" &&
isKey(stateData, region)
region !== undefined &&
Object.hasOwn(stateData, region)
) {
return {
solarRegionData: stateData[region],
solarRegionData:
stateData[
// See microsoft/TypeScript#44253
region as keyof typeof stateData
],
geoCostData: {
isHilly: Boolean(isHilly),
needsRenovations: Boolean(renovations),
Expand Down
14 changes: 10 additions & 4 deletions src/routes/solutions/[category]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Meta } from "../../../components/Meta.tsx";
import { solutions } from "../../../utils/categories.gen.ts";
import { useCsp } from "../../../utils/csp.ts";
import type { FreshContextHelper } from "../../../utils/handlers.ts";
import { hasSlug, isKey } from "../../../utils/type-helpers.ts";
import { hasSlug } from "../../../utils/type-helpers.ts";

export const config = {
csp: true,
Expand Down Expand Up @@ -51,7 +51,7 @@ export const handler: Handlers<CategoryProps> = {
if (
category === undefined ||
category === "" ||
!isKey(categoryMetadata, category)
!Object.hasOwn(categoryMetadata, category)
) {
return await ctx.renderNotFound();
}
Expand All @@ -76,10 +76,16 @@ export const handler: Handlers<CategoryProps> = {
}
}

const metadata =
categoryMetadata[
// See microsoft/TypeScript#44253
category as keyof typeof categoryMetadata
];

return await ctx.render({
pages: categoryPropsPages.parse(data),
title: categoryMetadata[category].title,
description: categoryMetadata[category].description,
title: metadata.title,
description: metadata.description,
heros: data.map((page) => page.picture),
});
} catch (e) {
Expand Down
17 changes: 1 addition & 16 deletions src/utils/type-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,5 @@ import type { SolutionPage } from "./solutions.ts";
export function hasSlug(
data: SolutionPage,
): data is SolutionPage & { slug: string | undefined } {
return isKey(data, "slug");
}

/**
* Check if an object has a key.
*
* @typeParam T - The type of the object.
* @param obj - The object to check.
* @param key - The key to check for.
* @returns Whether the object has the key.
*/
export function isKey<const T extends object>(
obj: T,
key: PropertyKey,
): key is keyof T {
return Object.hasOwn(obj, key);
return Object.hasOwn(data, "slug");
}

0 comments on commit cabf089

Please sign in to comment.