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

@@ -175,7 +175,7 @@ export default function ExpenseModal(
name='expense_budget' name='expense_budget'
id='expense_budget' id='expense_budget'
value={newExpenseBudget.value} value={newExpenseBudget.value}
onSelect={(event) => { onChange={(event) => {
newExpenseBudget.value = event.currentTarget.value; newExpenseBudget.value = event.currentTarget.value;
}} }}
placeholder='Misc' placeholder='Misc'

View File

@@ -1,5 +1,5 @@
import { useSignal } from '@preact/signals'; 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 { Budget, Expense, SupportedCurrencySymbol } from '/lib/types.ts';
import { import {
@@ -615,6 +615,13 @@ export default function MainExpenses({ initialBudgets, initialExpenses, initialM
}, 500); }, 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(() => { useEffect(() => {
return () => { return () => {
if (searchTimeout.value) { 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 ( return (
<> <>
<section class='block md:flex flex-row items-center justify-between mb-4'> <section class='block md:flex flex-row items-center justify-between mb-4'>