Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for description containing text #88

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/filters/AddFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRef, useState } from 'react'
import DateFilter from './DateFilter'
import DescFilter from './DescFilter'
import LatLongFilter from './LatLongFilter'
import { filterDispatchType, filterProps } from '@/pages/StatsDashboard'
import { LucideCalendar, LucideGlobe, LucideMapPin, LucidePlus, LucideTags, LucideText } from 'lucide-react'
Expand Down Expand Up @@ -54,7 +55,7 @@ const possibleFilters: FilterInfo[] = [
{
name: 'Descripción',
icon: LucideText,
component: DateFilter, // TODO: Change this to the actual component
component: DescFilter,
description: 'Filtrar por palabras clave en la descripción',
},
]
Expand Down
34 changes: 34 additions & 0 deletions src/components/filters/DescFilter.tsx
TetraTsunami marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { filterProps } from '@/pages/StatsDashboard'
import BaseFilter from './BaseFilter'
import { LucideCalendar, LucideTrash2 } from 'lucide-react'
import { useState, useEffect } from 'react'

const FilterDesc = ({ id, dispatch }: filterProps) => {
const [search, setSearch] = useState('')

useEffect(() => {
const lowercaseSearch = search.toLowerCase()
dispatch({
type: 'UPDATE_FILTER',
payload: {
id: id,
operation: (incident) => incident.description.toLowerCase().includes(lowercaseSearch),
},
})
}, [search])

const removeThisFilter = () => {
dispatch({ type: 'REMOVE_FILTER', payload: { id: id } })
}

return (
<BaseFilter icon={<LucideCalendar />} text={`La descripción contiene «${search}»`}>
<button onClick={removeThisFilter} className="absolute right-2 top-1 h-4 w-4 text-red-600" title="Eliminar Filtro">
<LucideTrash2 size={20} />
</button>
<input type="text" onChange={(e) => setSearch(e.target.value)} value={search} className="mr-6 rounded-md border border-gray-300 p-1" />
</BaseFilter>
)
}

export default FilterDesc
Loading