Convert other pages to composition API
This commit is contained in:
@ -1,68 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { mapState } from "pinia";
|
||||
import { defineComponent, PropType } from "vue";
|
||||
<script lang="ts" setup>
|
||||
import { computed, defineProps, onMounted, PropType, watch, watchEffect } from "vue";
|
||||
import Currency from "../components/Currency.vue";
|
||||
import { useBudgetsStore } from "../stores/budget";
|
||||
import { Category, useAccountStore } from "../stores/budget-account";
|
||||
import { useAccountStore } from "../stores/budget-account";
|
||||
|
||||
interface Date {
|
||||
Year: number,
|
||||
Month: number,
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
budgetid: {} as PropType<string>,
|
||||
year: {} as PropType<number>,
|
||||
month: {} as PropType<number>,
|
||||
},
|
||||
computed: {
|
||||
...mapState(useBudgetsStore, ["CurrentBudgetID"]),
|
||||
Categories() : Category[] {
|
||||
const accountStore = useAccountStore();
|
||||
return [...accountStore.CategoriesForMonth(this.selected.Year, this.selected.Month)];
|
||||
},
|
||||
previous() : Date {
|
||||
return {
|
||||
Year: new Date(this.selected.Year, this.selected.Month - 1, 1).getFullYear(),
|
||||
Month: new Date(this.selected.Year, this.selected.Month - 1, 1).getMonth(),
|
||||
};
|
||||
},
|
||||
current() : Date {
|
||||
return {
|
||||
Year: new Date().getFullYear(),
|
||||
Month: new Date().getMonth(),
|
||||
};
|
||||
},
|
||||
selected() : Date {
|
||||
return {
|
||||
Year: this.year ?? this.current.Year,
|
||||
Month: Number(this.month ?? this.current.Month) + 1
|
||||
}
|
||||
},
|
||||
next() : Date {
|
||||
return {
|
||||
Year: new Date(this.selected.Year, Number(this.month) + 1, 1).getFullYear(),
|
||||
Month: new Date(this.selected.Year, Number(this.month) + 1, 1).getMonth(),
|
||||
};
|
||||
}
|
||||
},
|
||||
mounted() : Promise<void> {
|
||||
document.title = "Budgeteer - Budget for " + this.selected.Month + "/" + this.selected.Year;
|
||||
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.selected.Year, this.selected.Month);
|
||||
},
|
||||
watch: {
|
||||
year() {
|
||||
if (this.year != undefined && this.month != undefined)
|
||||
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.year, this.month);
|
||||
},
|
||||
month() {
|
||||
if (this.year != undefined && this.month != undefined)
|
||||
return useAccountStore().FetchMonthBudget(this.budgetid ?? "", this.year, this.month);
|
||||
},
|
||||
},
|
||||
components: { Currency }
|
||||
})
|
||||
const props = defineProps<{
|
||||
budgetid: string,
|
||||
year: string,
|
||||
month: string,
|
||||
}>()
|
||||
|
||||
const budgetsStore = useBudgetsStore();
|
||||
const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID);
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
//const categoriesForMonth = accountStore.CategoriesForMonth;
|
||||
const Categories = computed(() => {
|
||||
const yearMap = accountStore.Months.get(selected.value.Year);
|
||||
const monthMap = yearMap?.get(selected.value.Month);
|
||||
console.log("MTH", monthMap)
|
||||
const CategoriesForMonth = [ ...monthMap?.values() || [] ];
|
||||
console.log("YAY?")
|
||||
return CategoriesForMonth;
|
||||
//return [...categoriesForMonth(selected.value.Year, selected.value.Month)];
|
||||
});
|
||||
const previous = computed(() => ({
|
||||
Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(),
|
||||
Month: new Date(selected.value.Year, selected.value.Month - 1, 1).getMonth(),
|
||||
}));
|
||||
const current = computed(() => ({
|
||||
Year: new Date().getFullYear(),
|
||||
Month: new Date().getMonth(),
|
||||
}));
|
||||
const selected = computed(() => ({
|
||||
Year: Number(props.year) ?? current.value.Year,
|
||||
Month: Number(props.month ?? current.value.Month) + 1
|
||||
}));
|
||||
const next = computed(() => ({
|
||||
Year: new Date(selected.value.Year, Number(props.month) + 1, 1).getFullYear(),
|
||||
Month: new Date(selected.value.Year, Number(props.month) + 1, 1).getMonth(),
|
||||
}));
|
||||
|
||||
watchEffect(() => {
|
||||
if (props.year != undefined && props.month != undefined)
|
||||
return useAccountStore().FetchMonthBudget(props.budgetid ?? "", Number(props.year), Number(props.month));
|
||||
});
|
||||
|
||||
/*{{define "title"}}
|
||||
{{printf "Budget for %s %d" .Date.Month .Date.Year}}
|
||||
|
Reference in New Issue
Block a user