forked from jsnbuchanan/crowd-funder-for-time-pwa
refactor: convert AmountInput to function props
- Convert AmountInput from @Emit("update:value") to onUpdateValue function prop
- Update GiftDetailsStep to use new function prop interface for amount handling
AmountInput now provides better parent control over validation and updates
This commit is contained in:
@@ -36,7 +36,7 @@ with increment/decrement buttons and validation. * * @author Matthew Raymer */
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Prop, Vue, Watch, Emit } from "vue-facing-decorator";
|
import { Component, Prop, Vue, Watch } from "vue-facing-decorator";
|
||||||
import { logger } from "@/utils/logger";
|
import { logger } from "@/utils/logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +47,8 @@ import { logger } from "@/utils/logger";
|
|||||||
* - Configurable min/max values and step size
|
* - Configurable min/max values and step size
|
||||||
* - Input validation and formatting
|
* - Input validation and formatting
|
||||||
* - Disabled state handling for boundary values
|
* - Disabled state handling for boundary values
|
||||||
* - Emits update events for v-model compatibility
|
* - Function props for parent control over validation and updates
|
||||||
|
* - Maintains v-model compatibility through onUpdateValue function prop
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
export default class AmountInput extends Vue {
|
export default class AmountInput extends Vue {
|
||||||
@@ -71,6 +72,13 @@ export default class AmountInput extends Vue {
|
|||||||
@Prop({ default: "amount-input" })
|
@Prop({ default: "amount-input" })
|
||||||
inputId!: string;
|
inputId!: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function prop for handling value updates
|
||||||
|
* Called when the value changes, allowing parent to control validation and update behavior
|
||||||
|
*/
|
||||||
|
@Prop({ type: Function, default: () => {} })
|
||||||
|
onUpdateValue!: (value: number) => void | Promise<void>;
|
||||||
|
|
||||||
/** Internal display value for input field */
|
/** Internal display value for input field */
|
||||||
private displayValue: string = "0";
|
private displayValue: string = "0";
|
||||||
|
|
||||||
@@ -173,7 +181,8 @@ export default class AmountInput extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the value and emit change event
|
* Update the value and call parent function prop
|
||||||
|
* Allows parent to control validation and update behavior
|
||||||
*/
|
*/
|
||||||
private updateValue(newValue: number): void {
|
private updateValue(newValue: number): void {
|
||||||
logger.debug("[AmountInput] updateValue() called", {
|
logger.debug("[AmountInput] updateValue() called", {
|
||||||
@@ -182,27 +191,16 @@ export default class AmountInput extends Vue {
|
|||||||
});
|
});
|
||||||
if (newValue !== this.value) {
|
if (newValue !== this.value) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"[AmountInput] updateValue() - values different, updating and emitting",
|
"[AmountInput] updateValue() - values different, updating and calling parent handler",
|
||||||
);
|
);
|
||||||
this.displayValue = newValue.toString();
|
this.displayValue = newValue.toString();
|
||||||
this.emitUpdateValue(newValue);
|
this.onUpdateValue(newValue);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"[AmountInput] updateValue() - values same, skipping update",
|
"[AmountInput] updateValue() - values same, skipping update",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Emit update:value event
|
|
||||||
*/
|
|
||||||
@Emit("update:value")
|
|
||||||
emitUpdateValue(value: number): number {
|
|
||||||
logger.debug("[AmountInput] emitUpdateValue() - emitting value", {
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -111,8 +111,6 @@ export default class ContactInputForm extends Vue {
|
|||||||
@Prop({ type: Function, default: () => {} })
|
@Prop({ type: Function, default: () => {} })
|
||||||
onNavigateOnboardMeeting!: () => void | Promise<void>;
|
onNavigateOnboardMeeting!: () => void | Promise<void>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function prop for handling model value updates
|
* Function prop for handling model value updates
|
||||||
* Called when the input value changes for v-model binding
|
* Called when the input value changes for v-model binding
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ Template streamlined with computed CSS properties * * @author Matthew Raymer */
|
|||||||
:value="localAmount"
|
:value="localAmount"
|
||||||
:min="0"
|
:min="0"
|
||||||
input-id="inputGivenAmount"
|
input-id="inputGivenAmount"
|
||||||
@update:value="handleAmountChange"
|
:on-update-value="handleAmountChange"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<select
|
<select
|
||||||
|
|||||||
@@ -36,8 +36,8 @@
|
|||||||
:on-navigate-onboard-meeting="
|
:on-navigate-onboard-meeting="
|
||||||
() => $router.push({ name: 'onboard-meeting-list' })
|
() => $router.push({ name: 'onboard-meeting-list' })
|
||||||
"
|
"
|
||||||
@qr-scan="handleQRCodeClick"
|
|
||||||
:on-update-model-value="(value: string) => (contactInput = value)"
|
:on-update-model-value="(value: string) => (contactInput = value)"
|
||||||
|
@qr-scan="handleQRCodeClick"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ContactListHeader
|
<ContactListHeader
|
||||||
@@ -1243,10 +1243,12 @@ export default class ContactsView extends Vue {
|
|||||||
* Uses native scanner on mobile platforms, web scanner otherwise
|
* Uses native scanner on mobile platforms, web scanner otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public handleQRCodeClick() {
|
public handleQRCodeClick() {
|
||||||
console.log("[ContactsView] handleQRCodeClick method called");
|
console.log("[ContactsView] handleQRCodeClick method called");
|
||||||
this.$logAndConsole("[ContactsView] handleQRCodeClick method called", false);
|
this.$logAndConsole(
|
||||||
|
"[ContactsView] handleQRCodeClick method called",
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
if (Capacitor.isNativePlatform()) {
|
if (Capacitor.isNativePlatform()) {
|
||||||
console.log("[ContactsView] Navigating to contact-qr-scan-full");
|
console.log("[ContactsView] Navigating to contact-qr-scan-full");
|
||||||
|
|||||||
Reference in New Issue
Block a user