Skip to content

Commit

Permalink
hotfix: daily budget settings
Browse files Browse the repository at this point in the history
  • Loading branch information
begprod committed Nov 1, 2024
1 parent 42552ac commit c8247c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "budget.it",
"version": "0.10.1",
"version": "0.10.2",
"description": "Another budget app, but this one is handy",
"repository": "https://github.com/begprod/budget.it",
"homepage": "https://begprod.github.io/budget.it/",
Expand Down
4 changes: 4 additions & 0 deletions src/stores/settings/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { createPinia, setActivePinia, storeToRefs } from 'pinia';
import { describe, it, expect } from 'vitest';
import { useCalendarStore } from '@/stores/calendar/calendar';
import { useSettingsStore } from '@/stores/settings/settings';

describe('Settings store', () => {
const pinia = createPinia();

setActivePinia(pinia);

const calendarStore = useCalendarStore();
const settingsStore = useSettingsStore();
const { currencies, dailyBudget, getMonthlyDailyBudget, getActiveCurrency } =
storeToRefs(settingsStore);
const { initCalendar } = calendarStore;
const {
initMonthlyDailyBudgetObject,
setActiveCurrency,
Expand All @@ -19,6 +22,7 @@ describe('Settings store', () => {
} = settingsStore;

it('should initialize monthly daily budget object', () => {
initCalendar();
initMonthlyDailyBudgetObject();

expect(Object.keys(getMonthlyDailyBudget.value).length).toEqual(7);
Expand Down
23 changes: 10 additions & 13 deletions src/stores/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IMonth } from '@/types';
import type { ISettingsStore, ICurrency } from '@/types';
import { defineStore } from 'pinia';
import { defineStore, storeToRefs } from 'pinia';
import { useLocalStorage } from '@vueuse/core';
import { generateMonths } from '@/helpers';
import { useCalendarStore } from '@/stores';

export const useSettingsStore = defineStore('settings', {
state: (): ISettingsStore => ({
Expand Down Expand Up @@ -48,18 +48,15 @@ export const useSettingsStore = defineStore('settings', {

actions: {
initMonthlyDailyBudgetObject() {
if (Object.keys(this.monthlyDailyBudget).length !== 0) {
return;
}

const monthsList = generateMonths(5);
const nextMonth = generateMonths(0, 1);
const allMonths = [...nextMonth, ...monthsList];
const calendarStore = useCalendarStore();
const { months } = storeToRefs(calendarStore);

allMonths.forEach((month: IMonth) => {
this.monthlyDailyBudget[month.id] = {
dailyBudget: this.dailyBudget,
};
months.value.forEach((item: IMonth) => {
if (!this.monthlyDailyBudget[item.id]) {
this.monthlyDailyBudget[item.id] = {
dailyBudget: this.dailyBudget,
};
}
});
},
setActiveCurrency(name: ICurrency['name']) {
Expand Down

0 comments on commit c8247c2

Please sign in to comment.