From e3c03563e3eba23f7ad67ed3ad51700be363774a Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Mon, 6 May 2024 16:08:33 -0700 Subject: [PATCH 1/2] chronological order - looks messy but it's ok because it's a temp fix. - when we move to the new data storage format, we can simply use the date field --- app/components/SearchDropdown.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/components/SearchDropdown.js b/app/components/SearchDropdown.js index 0d4868c..9cfb1dd 100644 --- a/app/components/SearchDropdown.js +++ b/app/components/SearchDropdown.js @@ -22,11 +22,33 @@ 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 }); + console.log(matches) setDropdownData(matches); // Find the selected match based on the URL and set it as selected From 7bb5eea020fbc6bde8131411813d29f5794b80ac Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Mon, 6 May 2024 16:09:34 -0700 Subject: [PATCH 2/2] remove console.log --- app/components/SearchDropdown.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/SearchDropdown.js b/app/components/SearchDropdown.js index 9cfb1dd..c3dc20f 100644 --- a/app/components/SearchDropdown.js +++ b/app/components/SearchDropdown.js @@ -48,7 +48,6 @@ const SearchDropdown = () => { if (!a.date || !b.date) return 1; // no date is last return b.date - a.date; // Sort by date }); - console.log(matches) setDropdownData(matches); // Find the selected match based on the URL and set it as selected