diff --git a/src/AppRouter.js b/src/AppRouter.js
index 660a1e8..6778ff6 100644
--- a/src/AppRouter.js
+++ b/src/AppRouter.js
@@ -3,6 +3,7 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom';
import AddItem from './pages/AddItem';
import List from './pages/List';
import HomePage from './pages/HomePage';
+import ListSort from './pages/ListSorted';
export default function AppRouter() {
return (
@@ -11,6 +12,7 @@ export default function AppRouter() {
+ >
);
diff --git a/src/listContext.js b/src/listContext.js
index d01edc8..a4b5d7b 100644
--- a/src/listContext.js
+++ b/src/listContext.js
@@ -22,7 +22,9 @@ const ListContextProvider = props => {
// fetch the latest shopping list from the database and save to state
const fetchList = token => {
let query = itemsRef
- .orderBy('name')
+ // .orderBy('name')
+ // .where('nextExpectedPurchase', "===", )
+ .orderBy('nextExpectedPurchase')
.where('token', '==', token || 'token not set');
const tempArray = [];
query
diff --git a/src/pages/ListSorted.js b/src/pages/ListSorted.js
new file mode 100644
index 0000000..4624068
--- /dev/null
+++ b/src/pages/ListSorted.js
@@ -0,0 +1,113 @@
+import dayjs from 'dayjs';
+import React, { useContext, useState } from 'react';
+import { FirestoreCollection } from 'react-firestore';
+
+import { ListContext } from '../listContext';
+import useListToken, { getCurrentToken } from '../useListToken';
+import NavTabs from '../components/NavTabs';
+import Loading from '../components/Loading';
+import normalizeName from '../lib/normalizeName';
+
+function isLessThan24hrs(datePurchased) {
+ return dayjs().diff(dayjs(datePurchased), 'hours') <= 24;
+}
+
+//we are checking if the last date it was purchased is less than 24hrs using isLessThan24hrs function
+function isChecked(lastDatePurchased) {
+ return !!lastDatePurchased && isLessThan24hrs(lastDatePurchased);
+}
+
+const ListSort = props => {
+ const now = new Date();
+ // const today = dayjs(now);
+
+ const [filteredInput, setFilteredInput] = useState('');
+ const { shoppingList, setShoppingList, purchaseItem } = useContext(
+ ListContext,
+ );
+ const { token } = useListToken();
+
+ function handlePurchasedChange(item) {
+ // We don't want to uncheck ourselves. We should have a separate ticket for handling a mis-check
+ // What would we set datePurchased to on an uncheck? Can't be null if we've purchased or our suggestions
+ // are goofed. Maybe we live with that, or we could keep the most recent lastDatePurchased in case
+ // of a mistake. For this ticket, let's keep it simple.
+ if (!isChecked(item.lastDatePurchased)) {
+ purchaseItem(item, Date.now());
+ }
+ }
+
+ function handleFilterChange(event) {
+ setFilteredInput(event.target.value);
+ }
+
+ //5. way to clear out the filter
+
+ function filterListInput(name) {
+ return normalizeName(name).includes(normalizeName(filteredInput));
+ }
+
+ return (
+ <>
+ {
+ if (!isLoading) {
+ setShoppingList(data);
+ }
+ return isLoading ? (
+
+ ) : (
+ <>
+