Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/preorder-app/embed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/preorder-app/embed.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/PreorderApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { PreorderAppConfig } from "./Config.types";
import LocationInput from "./location-input/LocationInput.svelte";
import ZipCodeInput from "./location-input/ZipCodeInput.svelte";

// Track initialization state
let isZipCodeInitialized = false;

export const PreorderApp = {
initialize: (props: PreorderAppConfig) => {
const {
Expand Down Expand Up @@ -56,6 +59,12 @@ export const PreorderApp = {
},

initializeZipCode: (props: PreorderAppConfig) => {
// Prevent multiple initializations
if (isZipCodeInitialized) {
console.warn('ZipCodeInput already initialized, skipping...');
return;
}

const {
targetElAddressInput = document.getElementById("zip-code-entry"),
onAddressSubmitSuccess,
Expand Down Expand Up @@ -94,6 +103,9 @@ export const PreorderApp = {
});
}

// Mark as initialized
isZipCodeInitialized = true;

return zipCodeInput;
},
};
1 change: 1 addition & 0 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PreorderApp } from "./PreorderApp";

// Initialize ZIP code input when DOM is ready
document.addEventListener("DOMContentLoaded", () => {
// Initialize ZIP code input if it exists
if (document.getElementById("zip-code-entry")) {
PreorderApp.initializeZipCode({
targetElAddressInput: document.getElementById("zip-code-entry"),
Expand Down
4 changes: 2 additions & 2 deletions src/location-input/LocationInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
jQuery(".input-address-container").addClass("focused");
jQuery("input.location-search-input").attr(
"placeholder",
"Enter your home address",
"Enter home address",
);
jQuery("button.submitAddressButton").hide();
});
Expand All @@ -116,7 +116,7 @@
<GooglePlaceAutocomplete
class="location-search-input"
apiKey={googlePublicApiKey}
placeholder="Enter your home address"
placeholder="Enter home address"
onSelect={(value) => {
console.log("Place selected:", value);
const parsed = parsePlaceResult(value);
Expand Down
47 changes: 29 additions & 18 deletions src/location-input/ZipCodeInput.svelte
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<script lang="ts">
import { onMount } from "svelte";
import { onMount, onDestroy } from "svelte";
import type { OnAddressSubmitSuccess } from "../types";
import { displayBlock, displayNone, fadeIn } from "../visibilityUtils";
import { addressState } from "../windowVars";

export let addressCtaText: string = "See if I qualify";
export let onAddressSubmitSuccess: OnAddressSubmitSuccess = () => {};

let inputContainer: HTMLElement;
let focusOverlay: HTMLElement;
let input: HTMLInputElement;

const handleContainerClick = () => {
if (zipCode.length !== 5) { // Only show overlay if not complete
focusOverlay.style.display = "block";
inputContainer.classList.add("focused");
}
input?.focus();
};

const handleOverlayClick = () => {
focusOverlay.style.display = "none";
inputContainer.classList.remove("focused");
};

onMount(() => {
const inputContainer = document.querySelector(".input-zip-container") as HTMLElement;
const focusOverlay = document.querySelector(".focus_overlay") as HTMLElement;
const input = document.querySelector(".zip-search-input") as HTMLInputElement;
if (inputContainer && focusOverlay) {
inputContainer.addEventListener("click", handleContainerClick);
focusOverlay.addEventListener("click", handleOverlayClick);
}
});

onDestroy(() => {
if (inputContainer && focusOverlay) {
inputContainer.addEventListener("click", () => {
if (zipCode.length !== 5) { // Only show overlay if not complete
focusOverlay.style.display = "block";
inputContainer.classList.add("focused");
}
input?.focus();
});

focusOverlay.addEventListener("click", () => {
focusOverlay.style.display = "none";
inputContainer.classList.remove("focused");
});
inputContainer.removeEventListener("click", handleContainerClick);
focusOverlay.removeEventListener("click", handleOverlayClick);
}
});

Expand Down Expand Up @@ -84,14 +94,15 @@
</script>

<div class="input-zip-wrap">
<div class="input-zip-container">
<div class="input-zip-container" bind:this={inputContainer}>
<div class="zip-input-layout">
<input
type="text"
inputmode="numeric"
pattern="[0-9]*"
class="zip-search-input"
maxlength="5"
bind:this={input}
on:input={handleInput}
on:keydown={(e) => e.key === 'Enter' && isComplete && handleSubmit()}
/>
Expand All @@ -112,7 +123,7 @@
</button>
</div>
</div>
<div class="focus_overlay"></div>
<div class="focus_overlay" bind:this={focusOverlay}></div>

<style lang="scss" global>
.input-zip-wrap {
Expand Down