Fix budget selection for expenses

Also open the new expense modal by default on load for mobile viewport sizes.
This commit is contained in:
Bruno Bernardino
2025-03-10 15:13:16 +00:00
parent df332802c0
commit 0b5dd1ada7
2 changed files with 18 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { useSignal } from '@preact/signals';
import { useEffect } from 'preact/hooks';
import { useCallback, useEffect } from 'preact/hooks';
import { Budget, Expense, SupportedCurrencySymbol } from '/lib/types.ts';
import {
@@ -615,6 +615,13 @@ export default function MainExpenses({ initialBudgets, initialExpenses, initialM
}, 500);
}
// Open the expense modal if the window is small
const handleWindowResize = useCallback(() => {
if (globalThis.innerWidth < 600 && !isExpenseModalOpen.value && !editingExpense.value) {
isExpenseModalOpen.value = true;
}
}, []);
useEffect(() => {
return () => {
if (searchTimeout.value) {
@@ -623,6 +630,15 @@ export default function MainExpenses({ initialBudgets, initialExpenses, initialM
};
}, []);
useEffect(() => {
handleWindowResize();
globalThis.addEventListener('resize', handleWindowResize);
return () => {
globalThis.removeEventListener('resize', handleWindowResize);
};
}, [handleWindowResize]);
return (
<>
<section class='block md:flex flex-row items-center justify-between mb-4'>