Skip to content

Commit

Permalink
Fix sorting of incidents
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Nov 24, 2023
1 parent 2d0c038 commit a7dc53a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions pages/findings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,26 @@ const Index = () => {
}, [data])

const sortedAndFilteredData = useMemo(() => {
const sortedData = displayData.sort((a, b) => {
if (sortValue === 'start_asc') {
return a.start_time - b.start_time
} else if (sortValue === 'start_desc') {
return b.start_time - a.start_time
} else if (sortValue === 'end_asc') {
return a.sort_end_time - b.sort_end_time
} else {
// default to 'end_desc' sort
return b.sort_end_time - a.sort_end_time
}
})
const sortedData = displayData
.sort((a, b) => (b.start_time - a.start_time)) // make sure ongoing events are always chronologically sorted
.sort((a, b) => {
if (sortValue === 'start_asc') {
return a.start_time - b.start_time
} else if (sortValue === 'start_desc') {
return b.start_time - a.start_time
} else if (sortValue === 'end_asc') {
return a.sort_end_time - b.sort_end_time
} else {
// default to 'end_desc' sort
return b.sort_end_time - a.sort_end_time
}})

const filteredData = !!searchValue.length ?
sortedData.filter((incident) => {
const fitsSearchValue = !!searchValue ? incident.title.toLowerCase().includes(searchValue.toLowerCase()) : true
return fitsSearchValue
}) :
sortedData.filter((incident) => (
!!searchValue ?
incident.title.toLowerCase().includes(searchValue.toLowerCase()) || incident.short_description.toLowerCase().includes(searchValue.toLowerCase()) :
true
)) :
sortedData

return filteredData
Expand Down

1 comment on commit a7dc53a

@vercel
Copy link

@vercel vercel bot commented on a7dc53a Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer – ./

explorer-ooni1.vercel.app
explorer-git-master-ooni1.vercel.app
explorer-one.vercel.app

Please sign in to comment.