Skip to content

Commit

Permalink
Fix (almost) all typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed May 10, 2024
1 parent fa73178 commit b61df6f
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 176 deletions.
4 changes: 4 additions & 0 deletions examples/counter-component/src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export async function Main(this: SeqflowFunctionContext) {
this.domEvent("click", { el: this._el as HTMLElement }),
);
for await (const ev of events) {
if (!(ev.target instanceof HTMLElement)) {
continue;
}

if (incrementButton.contains(ev.target)) {
counter++;
} else if (decrementButton.contains(ev.target)) {
Expand Down
10 changes: 3 additions & 7 deletions examples/counter/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { type SeqflowFunctionContext } from "seqflow-js";

export async function Main(this: SeqflowFunctionContext) {
const incrementButton: HTMLButtonElement = (
<button type="button">Increment</button>
);
const decrementButton: HTMLButtonElement = (
<button type="button">Decrement</button>
);
const counterDiv: HTMLDivElement = <div>0</div>;
const incrementButton = <button type="button">Increment</button>;
const decrementButton = <button type="button">Decrement</button>;
const counterDiv = <div>0</div>;

let counter = 0;
this.renderSync(
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-element/src/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function ChangeCounterButton(
export async function Counter(this: SeqflowFunctionContext) {
const counterDiv = <div>{this.app.domains.counter.get()}</div>;
this.renderSync(
<div class={classes.counter}>
<div className={classes.counter}>
<ChangeCounterButton delta={-1} text="Decrement" />
{counterDiv}
<ChangeCounterButton delta={1} text="Increment" />
Expand Down
4 changes: 2 additions & 2 deletions examples/e-commerce/src/components/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export async function CardList<T extends { id: string | number }>(
},
) {
this.renderSync(
<ol class={classes.wrapper}>
<ol className={classes.wrapper}>
{data.items.map((item) => (
<li class={classes.element} id={`${data.prefix}-${item.id}`}>
<li className={classes.element} id={`${data.prefix}-${item.id}`}>
<data.Component {...item} />
</li>
))}
Expand Down
8 changes: 4 additions & 4 deletions examples/e-commerce/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export async function Header(
data: { user?: UserType },
) {
const loginButton = <button type="button">Sign in</button>;
const storeLogo = <img src={icon} alt="icon" class={classes.icon} />;
const storeLogo = <img src={icon} alt="icon" className={classes.icon} />;

this.renderSync(
<header class={classes.header}>
<header className={classes.header}>
<a href="/">{storeLogo}</a>
<div class={classes.emptySpace} />
<div className={classes.emptySpace} />
<UserProfileBadge wrapperClass={classes.displayOnLogged} />
<div id="login" class={classes.displayOnUnlogged}>
<div id="login" className={classes.displayOnUnlogged}>
{loginButton}
</div>
<CartBadge />
Expand Down
10 changes: 5 additions & 5 deletions examples/e-commerce/src/domains/cart/components/AddToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export async function AddToCart(
const initCount = this.app.domains.cart.getProductCount(data.product.id);

const firstAddToCart = (
<button type="button" class={classes.firstAddToCart}>
<button type="button" className={classes.firstAddToCart}>
Add to cart
</button>
);
const removeFromCart = (
<button type="button" class={classes.removeFromCart}>
<button type="button" className={classes.removeFromCart}>
-
</button>
);
const secondAddFromCart = (
<button type="button" class={classes.secondAddFromCart}>
<button type="button" className={classes.secondAddFromCart}>
+
</button>
);
const count = <span class="count">{initCount}</span>;
const count = <span className="count">{initCount}</span>;
const otherAddToCartWrapper = (
<div class={`${classes.otherAddToCartWrapper} ${classes.show}`}>
<div className={`${classes.otherAddToCartWrapper} ${classes.show}`}>
{removeFromCart}
{count}
{secondAddFromCart}
Expand Down
10 changes: 7 additions & 3 deletions examples/e-commerce/src/domains/cart/components/CartBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ export async function CartBadge(this: SeqflowFunctionContext) {
const count = this.app.domains.cart.getProductCount();

const counter = (
<span arial-hidden={true} class={classes.cartProductCounter}>
<span arial-hidden={true} className={classes.cartProductCounter}>
{count}
</span>
);
this.renderSync(
<a href="/cart" title="go to cart" class={classes.numberOfProductsInCart}>
<i class={`fa-solid fa-cart-shopping ${classes.icon}`} />
<a
href="/cart"
title="go to cart"
className={classes.numberOfProductsInCart}
>
<i className={`fa-solid fa-cart-shopping ${classes.icon}`} />
{counter}
</a>,
);
Expand Down
22 changes: 11 additions & 11 deletions examples/e-commerce/src/domains/cart/components/CartProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export async function CartProduct(
data: { product: Product; count: number; subTotal: number },
) {
const removeButton = (
<button type="button" class="remove-from-cart">
<i class="fa-solid fa-trash" />
<button type="button" className="remove-from-cart">
<i className="fa-solid fa-trash" />
</button>
);
this.renderSync(
<div class={classes.product} id={`cart-product-${data.product.id}`}>
<div class={classes.left}>
<div className={classes.product} id={`cart-product-${data.product.id}`}>
<div className={classes.left}>
<img
class={classes.productImage}
className={classes.productImage}
src={data.product.image}
alt={data.product.title}
/>
<div>{data.product.price}</div>
</div>
<div class={classes.productTitle}>
<div className={classes.productTitle}>
<p>{data.product.title}</p>
</div>
<div>x {data.count}</div>
Expand Down Expand Up @@ -58,16 +58,16 @@ export async function CartProductList(
const checkoutButton = <button type="button">Checkout</button>;
const cartLogin = <a href="/login">Go to login</a>;
const cartTotal = (
<div class={classes.cartTotal} id="cart-total">
<div className={classes.cartTotal} id="cart-total">
total: {data.cart.total}
</div>
);
this.renderSync(
<div>
<ul class={classes.cartProducts}>
<ul className={classes.cartProducts}>
{data.cart.products.map(({ product, count, subTotal }) => {
return (
<li key={`cart-item-${product.id}`}>
<li id={`cart-item-${product.id}`}>
<CartProduct
product={product}
count={count}
Expand All @@ -79,7 +79,7 @@ export async function CartProductList(
</ul>
<hr />
{cartTotal}
<div class={classes.cartCheckout}>{checkoutButton}</div>
<div className={classes.cartCheckout}>{checkoutButton}</div>
<div>{cartLogin}</div>
</div>,
);
Expand Down Expand Up @@ -115,7 +115,7 @@ export async function CartProductList(
switch (ev.detail.action) {
case "remove-all-elements-of-a-product":
this._el
.querySelector(`li[key=cart-item-${ev.detail.product.id}]`)
.querySelector(`li#cart-item-${ev.detail.product.id}`)
?.remove();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function CartTooltip(this: SeqflowFunctionContext) {
}

const cartTooltipLink = (
<a class={classes.cartTooltipLink} id="cart-tooltip-link" href="/cart">
<a className={classes.cartTooltipLink} id="cart-tooltip-link" href="/cart">
Go to checkout
</a>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SeqflowAppContext, SeqflowFunctionContext } from "seqflow-js";
import { SeqflowFunctionContext } from "seqflow-js";
import { CardList } from "../../../components/CardList";
import { ProductCategory } from "../ProductDomain";
import classes from "./ProductCategoryList.module.css";
Expand All @@ -8,8 +8,12 @@ async function CategoryItem(
data: ProductCategory,
) {
const anchor = (
<a class={classes.categoryAnchor} href={`/category/${data.name}`}>
<img class={classes.categoryImage} src={data.image.url} alt={data.name} />
<a className={classes.categoryAnchor} href={`/category/${data.name}`}>
<img
className={classes.categoryImage}
src={data.image.url}
alt={data.name}
/>
<span>{data.name}</span>
</a>
);
Expand All @@ -31,7 +35,7 @@ export async function ProductCategoryList(
data: { categories: ProductCategory[] },
) {
this.renderSync(
<div class={classes.productList}>
<div className={classes.productList}>
<CardList
prefix="category"
items={data.categories}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import classes from "./ProductItem.module.css";

export async function ProductItem(this: SeqflowFunctionContext, data: Product) {
const productImage = (
<img src={data.image} class={classes.productImage} alt={data.title} />
<img src={data.image} className={classes.productImage} alt={data.title} />
);
const tooltip = <div class={classes.tooltipWrapper}>{data.title}</div>;
const tooltip = <div className={classes.tooltipWrapper}>{data.title}</div>;
this.renderSync(
<div class={classes.wrapper}>
<div className={classes.wrapper}>
{productImage}
<p class={classes.price}>{data.price}</p>
<p className={classes.price}>{data.price}</p>
{tooltip}
<div id={`product-card-cart-${data.id}`}>
<AddToCart product={data} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function UserProfileBadge(this: SeqflowFunctionContext) {
<img
width={size}
height={size}
class={classes.logo}
className={classes.logo}
src={getProfileUrl(user, size)}
alt="Profile Avatar"
/>
Expand All @@ -37,9 +37,9 @@ export async function UserProfileBadge(this: SeqflowFunctionContext) {
);

this.renderSync(
<button type="button" class={classes.logoWrapper} href="/profile">
<button type="button" className={classes.logoWrapper}>
{profilePicture}
<div class={classes["profile-header-menu-wrapper"]}>
<div className={classes["profile-header-menu-wrapper"]}>
{profileHeaderMenu}
</div>
</button>,
Expand Down
4 changes: 2 additions & 2 deletions examples/e-commerce/src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export async function Login(this: SeqflowFunctionContext) {
const el = (
<input id="username" type="text" name="username" value="johnd" />
) as HTMLInputElement;
const error = <p class="error" />;
const error = <p className="error" />;
const submit = (<button type="submit">Login</button>) as HTMLButtonElement;

this.renderSync(
<div>
<form>
<label for="username">Username</label>
<label htmlFor="username">Username</label>
{el}
{error}
{submit}
Expand Down
3 changes: 0 additions & 3 deletions examples/e-commerce/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
screen,
waitFor,
waitForElementToBeRemoved,
} from "@testing-library/dom";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";

import { InMemoryRouter, start } from "seqflow-js";
import { afterAll, afterEach, beforeAll, expect, test } from "vitest";
import { s } from "vitest/dist/reporters-MmQN-57K";
import { Main } from "../src/Main";
import { CartDomain } from "../src/domains/cart";
import { ProductDomain } from "../src/domains/product";
Expand Down
Loading

0 comments on commit b61df6f

Please sign in to comment.