mirror of
https://github.com/spliit-app/spliit.git
synced 2026-02-10 09:36:12 +01:00
Increase fuzzines of search results (#187)
* Introduce normalizeString fn * Prettier --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
This commit is contained in:
@@ -4,6 +4,7 @@ import { getGroupExpensesAction } from '@/app/groups/[groupId]/expenses/expense-
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { SearchBar } from '@/components/ui/search-bar'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { normalizeString } from '@/lib/utils'
|
||||
import { Participant } from '@prisma/client'
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import Link from 'next/link'
|
||||
@@ -134,13 +135,15 @@ export function ExpenseList({
|
||||
|
||||
return expenses.length > 0 ? (
|
||||
<>
|
||||
<SearchBar onValueChange={(value) => setSearchText(value)} />
|
||||
<SearchBar
|
||||
onValueChange={(value) => setSearchText(normalizeString(value))}
|
||||
/>
|
||||
{Object.values(EXPENSE_GROUPS).map((expenseGroup: string) => {
|
||||
let groupExpenses = groupedExpensesByDate[expenseGroup]
|
||||
if (!groupExpenses) return null
|
||||
|
||||
groupExpenses = groupExpenses.filter(({ title }) =>
|
||||
title.toLowerCase().includes(searchText.toLowerCase()),
|
||||
normalizeString(title).includes(searchText),
|
||||
)
|
||||
|
||||
if (groupExpenses.length === 0) return null
|
||||
|
||||
@@ -48,3 +48,13 @@ export function formatFileSize(size: number) {
|
||||
if (size > 1024) return `${formatNumber(size / 1024)} kB`
|
||||
return `${formatNumber(size)} B`
|
||||
}
|
||||
|
||||
export function normalizeString(input: string): string {
|
||||
// Replaces special characters
|
||||
// Input: áäåèéę
|
||||
// Output: aaaeee
|
||||
return input
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user