From 6a885df10f41959524a9418f1ebb06a9a7612e5e Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 4 Sep 2024 15:30:10 +0000 Subject: [PATCH 1/2] typescript changes to make ci run pass --- frontend/controllers/donation-controller.ts | 10 +++++----- frontend/controllers/product-controller.ts | 9 ++++----- frontend/main.ts | 10 ++++++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/frontend/controllers/donation-controller.ts b/frontend/controllers/donation-controller.ts index fd423d6..4a73c7d 100644 --- a/frontend/controllers/donation-controller.ts +++ b/frontend/controllers/donation-controller.ts @@ -2,20 +2,21 @@ import { Controller } from "@hotwired/stimulus"; class DonationController extends Controller { static targets = ["input"]; + inputTargets: any; setInputs(value: number) { // If the new value is one of the radios, select them // Else unselect all radios if (value) { - this.inputTargets.forEach((input) => { + this.inputTargets.forEach((input: { type: string; checked: boolean; value: string | number; }) => { if (input.type === "radio") { - input.checked = parseFloat(input.value) === value; + input.checked = parseFloat(input.value as string) === value; } else { - input.value = value; + input.value = String(value); } }); } else { - this.inputTargets.forEach((input) => { + this.inputTargets.forEach((input: { type: string; checked: boolean; value: string; }) => { if (input.type === "radio") { input.checked = false; } else { @@ -24,7 +25,6 @@ class DonationController extends Controller { }); } } - update(e: InputEvent) { let value = parseFloat((e.target as HTMLInputElement)?.value || "0") || 0; this.setInputs(value); diff --git a/frontend/controllers/product-controller.ts b/frontend/controllers/product-controller.ts index 87a1fac..9e87765 100644 --- a/frontend/controllers/product-controller.ts +++ b/frontend/controllers/product-controller.ts @@ -58,10 +58,9 @@ export default class ShopifyBuyControllerBase extends Controller { } private LOCALSTORAGE_CHECKOUT_ID = "checkoutId"; - get checkoutId() { - return window.localStorage - .getItem(this.LOCALSTORAGE_CHECKOUT_ID) - ?.toString(); + get checkoutId(): string | number { + const id = window.localStorage.getItem(this.LOCALSTORAGE_CHECKOUT_ID); + return id ? id.toString() : ""; } set checkoutId(id: string | number) { @@ -81,7 +80,7 @@ export default class ShopifyBuyControllerBase extends Controller { }); if (this.checkoutId) { - this.checkoutValue = await this.client.checkout.fetch(this.checkoutId); + this.checkoutValue = await this.client.checkout.fetch(this.checkoutId.toString()); } let checkoutIsExpired = false; diff --git a/frontend/main.ts b/frontend/main.ts index e457de5..ece07d1 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -6,7 +6,13 @@ import "bootstrap"; import initialiseSentry from "./sentry"; import initialisePosthog from "./posthog"; import { startApp } from "groundwork-django"; -const controllers = import.meta.glob("./controllers/*-controller.ts"); +import { ControllerConstructor } from "@hotwired/stimulus"; + +const controllers = import.meta.glob("./controllers/*-controller.ts") as Record< + string, + () => Promise<{ default: ControllerConstructor }> +>; + Turbo.session.drive = false; initialisePosthog(); @@ -17,4 +23,4 @@ import { Application } from "@hotwired/stimulus"; import ReadMore from "stimulus-read-more"; const application = Application.start(); application.register("read-more", ReadMore); -application.debug = true; +application.debug = true; \ No newline at end of file From b5a7004884b289a14e792e1c1bc6bedb492ee904 Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 4 Sep 2024 15:39:18 +0000 Subject: [PATCH 2/2] run prettier --- frontend/controllers/donation-controller.ts | 28 +++++++++-------- frontend/controllers/product-controller.ts | 34 ++++++++++++++------- frontend/main.ts | 2 +- package.json | 1 - 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/frontend/controllers/donation-controller.ts b/frontend/controllers/donation-controller.ts index 4a73c7d..56648bd 100644 --- a/frontend/controllers/donation-controller.ts +++ b/frontend/controllers/donation-controller.ts @@ -8,21 +8,25 @@ class DonationController extends Controller { // If the new value is one of the radios, select them // Else unselect all radios if (value) { - this.inputTargets.forEach((input: { type: string; checked: boolean; value: string | number; }) => { - if (input.type === "radio") { - input.checked = parseFloat(input.value as string) === value; - } else { - input.value = String(value); + this.inputTargets.forEach( + (input: { type: string; checked: boolean; value: string | number }) => { + if (input.type === "radio") { + input.checked = parseFloat(input.value as string) === value; + } else { + input.value = String(value); + } } - }); + ); } else { - this.inputTargets.forEach((input: { type: string; checked: boolean; value: string; }) => { - if (input.type === "radio") { - input.checked = false; - } else { - input.value = "0"; + this.inputTargets.forEach( + (input: { type: string; checked: boolean; value: string }) => { + if (input.type === "radio") { + input.checked = false; + } else { + input.value = "0"; + } } - }); + ); } } update(e: InputEvent) { diff --git a/frontend/controllers/product-controller.ts b/frontend/controllers/product-controller.ts index 9e87765..c4d13a3 100644 --- a/frontend/controllers/product-controller.ts +++ b/frontend/controllers/product-controller.ts @@ -44,23 +44,33 @@ export default class ShopifyBuyControllerBase extends Controller { } updateAddToCartButton() { - const selectedOption = this.variantSelectorTarget.options[this.variantSelectorTarget.selectedIndex]; + const selectedOption = + this.variantSelectorTarget.options[ + this.variantSelectorTarget.selectedIndex + ]; const selectedVariantId = selectedOption.value; - const inventoryQuantity = selectedOption.getAttribute('data-inventory-quantity'); - const inventoryPolicy = selectedOption.getAttribute('data-inventory-policy'); - this.addToCartButtonTarget.setAttribute('data-product-variant-id-param', selectedVariantId); + const inventoryQuantity = selectedOption.getAttribute( + "data-inventory-quantity" + ); + const inventoryPolicy = selectedOption.getAttribute( + "data-inventory-policy" + ); + this.addToCartButtonTarget.setAttribute( + "data-product-variant-id-param", + selectedVariantId + ); - if (Number(inventoryQuantity) == 0 && inventoryPolicy == 'deny') { - this.addToCartButtonTarget.setAttribute('disabled', 'true'); + if (Number(inventoryQuantity) == 0 && inventoryPolicy == "deny") { + this.addToCartButtonTarget.setAttribute("disabled", "true"); } else { - this.addToCartButtonTarget.removeAttribute('disabled'); + this.addToCartButtonTarget.removeAttribute("disabled"); } -} + } private LOCALSTORAGE_CHECKOUT_ID = "checkoutId"; get checkoutId(): string | number { const id = window.localStorage.getItem(this.LOCALSTORAGE_CHECKOUT_ID); - return id ? id.toString() : ""; + return id ? id.toString() : ""; } set checkoutId(id: string | number) { @@ -80,7 +90,9 @@ export default class ShopifyBuyControllerBase extends Controller { }); if (this.checkoutId) { - this.checkoutValue = await this.client.checkout.fetch(this.checkoutId.toString()); + this.checkoutValue = await this.client.checkout.fetch( + this.checkoutId.toString() + ); } let checkoutIsExpired = false; @@ -335,4 +347,4 @@ function currency( function length(arr: any[]) { if (!arr) return 0; return arr.length || 0; -} \ No newline at end of file +} diff --git a/frontend/main.ts b/frontend/main.ts index ece07d1..3f681a0 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -23,4 +23,4 @@ import { Application } from "@hotwired/stimulus"; import ReadMore from "stimulus-read-more"; const application = Application.start(); application.register("read-more", ReadMore); -application.debug = true; \ No newline at end of file +application.debug = true; diff --git a/package.json b/package.json index 8a5a743..32c172c 100644 --- a/package.json +++ b/package.json @@ -48,5 +48,4 @@ "vite": "^5.0.2" }, "packageManager": "yarn@1.22.22" - }