Improve UX of expenses

Enter on expense description will submit, and auto-complete suggestions will start from closer to longer matches.
This commit is contained in:
Bruno Bernardino
2025-03-26 15:55:04 +00:00
parent 5467fb3533
commit 1e1d3657a2
2 changed files with 12 additions and 1 deletions

View File

@@ -124,7 +124,7 @@ export async function getExpenseByName(userId: string, name: string) {
export async function getExpenseSuggestions(userId: string, name: string) {
const expenses = await db.query<Pick<Expense, 'description'>>(
sql`SELECT DISTINCT "description" FROM "bewcloud_expenses" WHERE "user_id" = $1 AND LOWER("description") ILIKE LOWER($2) ORDER BY "description" ASC`,
sql`SELECT "description" FROM "bewcloud_expenses" WHERE "user_id" = $1 AND LOWER("description") ILIKE LOWER($2) GROUP BY "description" ORDER BY LENGTH("description") ASC, "description" ASC`,
[
userId,
`%${name}%`,