Skip to content

Commit

Permalink
Merge pull request #142 from awest25/chronological
Browse files Browse the repository at this point in the history
Chronological
  • Loading branch information
Fredenck authored May 6, 2024
2 parents de73e30 + 7bb5eea commit aa4130d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/components/SearchDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,31 @@ const SearchDropdown = () => {
.filter((doc) => doc.data().published)
.map((doc) => {
const data = doc.data();
const name = data.name;
const dateRegex = /(\d{1,2})\/(\d{1,2})\/(\d{2})/;
const match = name.match(dateRegex);

let extractedDate = null;
if (match) {
const month = parseInt(match[1], 10);
const day = parseInt(match[2], 10);
const year = parseInt(match[3], 10);

// Assuming year 2000 is the base, adjust if needed
const fullYear = year < 50 ? 2000 + year : 1900 + year;

extractedDate = new Date(fullYear, month - 1, day);
}

return {
value: doc.id, // Use 'value' to adhere to react-select convention
label: data.name
value: doc.id,
label: name,
date: extractedDate
};
})
.sort((a, b) => {
if (!a.date || !b.date) return 1; // no date is last
return b.date - a.date; // Sort by date
});
setDropdownData(matches);

Expand Down

0 comments on commit aa4130d

Please sign in to comment.