diff --git a/web/src/components/Autocomplete.vue b/web/src/components/Autocomplete.vue index e305b67..22a9965 100644 --- a/web/src/components/Autocomplete.vue +++ b/web/src/components/Autocomplete.vue @@ -8,21 +8,15 @@ export interface Suggestion { Name: string } -interface Data { - Selected: Suggestion | undefined - SearchQuery: String - Suggestions: Suggestion[] -} - const props = defineProps<{ - modelValue: Suggestion | undefined, + text: String, + id: String | undefined, type: String }>(); -const Selected = ref(props.modelValue || undefined); -const SearchQuery = ref(props.modelValue?.Name || ""); +const SearchQuery = ref(props.text || ""); const Suggestions = ref>([]); -const emit = defineEmits(["update:modelValue"]); +const emit = defineEmits(["update:id", "update:text"]); watch(SearchQuery, () => { load(SearchQuery.value); }); @@ -30,7 +24,8 @@ function saveTransaction(e: MouseEvent) { e.preventDefault(); }; function load(text: String) { - emit('update:modelValue', { ID: null, Name: text }); + emit('update:id', null); + emit('update:text', text); if (text == "") { Suggestions.value = []; return; @@ -56,13 +51,12 @@ function keypress(e: KeyboardEvent) { const currentIndex = inputElements.indexOf(el); const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0]; (nextElement).focus(); - } }; function selectElement(element: Suggestion) { - Selected.value = element; + emit('update:id', element.ID); + emit('update:text', element.Name); Suggestions.value = []; - emit('update:modelValue', element); }; function select(e: MouseEvent) { const target = (e.target); @@ -74,8 +68,8 @@ function select(e: MouseEvent) { selectElement(selected); }; function clear() { - Selected.value = undefined; - emit('update:modelValue', { ID: null, Name: SearchQuery.value }); + emit('update:id', null); + emit('update:text', SearchQuery.value); }; @@ -84,10 +78,10 @@ function clear() { - {{ Selected.Name }} + {{ text }}
-import { computed, ref } from "vue"; -import Autocomplete, { Suggestion } from './Autocomplete.vue' -import { Transaction, useAccountStore } from '../stores/budget-account' +import { computed } from "vue"; +import Autocomplete from './Autocomplete.vue' +import { useAccountStore } from '../stores/budget-account' const props = defineProps<{ - transaction: Transaction + transactionid: string }>() -const TransactionDate = ref(props.transaction.Date.substring(0, 10)); -const Payee = ref({ID: "", Name: props.transaction.Payee}); -const Category = ref({ID: "", Name: props.transaction.Category}); -const Memo = ref(props.transaction.Memo); -const Amount = ref(props.transaction.Amount); +const accountStore = useAccountStore(); +const Transaction = accountStore.Transactions.get(props.transactionid)!; const payload = computed(() => JSON.stringify({ - date: TransactionDate.value, - payee: Payee.value, - category: Category.value, - memo: Memo.value, - amount: Amount.value, + date: Transaction.Date, + payee: Transaction.Payee, + category: Transaction.Category, + memo: Transaction.Memo, + amount: Transaction.Amount, state: "Uncleared" })); -const accountStore = useAccountStore(); function saveTransaction(e: MouseEvent) { e.preventDefault(); - console.log(props.transaction); - //accountStore.saveTransaction(payload.value); + accountStore.saveTransaction(payload.value); }